From: Michal Hocko <mhocko@kernel.org>
To: James Hogan <james.hogan@mips.com>
Cc: Kees Cook <keescook@chromium.org>,
LKML <linux-kernel@vger.kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Jiri Kosina <jkosina@suse.cz>, Al Viro <viro@zeniv.linux.org.uk>,
Oleg Nesterov <oleg@redhat.com>, Ingo Molnar <mingo@redhat.com>,
Baoquan He <bhe@redhat.com>,
linux-metag@vger.kernel.org
Subject: Re: [PATCH 1/2] fs, elf: drop MAP_FIXED usage from elf_map
Date: Tue, 17 Oct 2017 10:56:43 +0200 [thread overview]
Message-ID: <20171017085643.wag7fsrqmhhnlr2f@dhcp22.suse.cz> (raw)
In-Reply-To: <20171017083556.GM15235@jhogan-linux>
On Tue 17-10-17 09:35:57, James Hogan wrote:
> On Tue, Oct 17, 2017 at 09:37:48AM +0200, Michal Hocko wrote:
[...]
> > This would be something like. I wanted to share elf_vm_mmap but didn't
> > find a proper place to not cause include dependency hell so I balied out
> > to c&p.
> > ---
> > diff --git a/arch/metag/kernel/process.c b/arch/metag/kernel/process.c
> > index c4606ce743d2..b20596b4c4c2 100644
> > --- a/arch/metag/kernel/process.c
> > +++ b/arch/metag/kernel/process.c
> > @@ -378,6 +378,29 @@ int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
> >
> > #define BAD_ADDR(x) ((unsigned long)(x) >= TASK_SIZE)
> >
> > +static unsigned long elf_vm_mmap(struct file *filep, unsigned long addr,
> > + unsigned long size, int prot, int type, unsigned long off)
> > +{
> > + unsigned long map_addr;
> > +
> > + /*
> > + * If caller requests the mapping at a specific place, make sure we fail
> > + * rather than potentially clobber an existing mapping which can have
> > + * security consequences (e.g. smash over the stack area).
> > + */
> > + map_addr = vm_mmap(filep, addr, size, prot, type & ~MAP_FIXED, off);
> > + if (BAD_ADDR(map_addr))
> > + return map_addr;
> > +
> > + if ((type & MAP_FIXED) && map_addr != addr) {
> > + pr_info("Uhuuh, elf segement at %p requested but the memory is mapped already\n",
> > + (void*)addr);
> > + return -EAGAIN;
> > + }
> > +
> > + return map_addr;
> > +}
> > +
> > unsigned long __metag_elf_map(struct file *filep, unsigned long addr,
> > struct elf_phdr *eppnt, int prot, int type,
> > unsigned long total_size)
> > @@ -410,11 +433,11 @@ unsigned long __metag_elf_map(struct file *filep, unsigned long addr,
> > */
> > if (total_size) {
> > total_size = ELF_PAGEALIGN(total_size);
> > - map_addr = vm_mmap(filep, addr, total_size, prot, type, off);
> > + map_addr = elf_vm_mmap(filep, addr, total_size, prot, type, off);
> > if (!BAD_ADDR(map_addr))
> > vm_munmap(map_addr+size, total_size-size);
> > } else
> > - map_addr = vm_mmap(filep, addr, size, prot, type, off);
> > + map_addr = elf_vm_mmap(filep, addr, size, prot, type, off);
> >
> > if (!BAD_ADDR(map_addr) && tcm_tag != TCM_INVALID_TAG) {
> > struct tcm_allocation *tcm;
>
> Yeh that looks reasonable to me.
Thanks for double checking. I will make sure to CC you when reposting
the patch after other concerns sort out.
--
Michal Hocko
SUSE Labs
prev parent reply other threads:[~2017-10-17 8:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20171004075059.bbx7madwgwflb7ky@dhcp22.suse.cz>
[not found] ` <20171016134446.19910-1-mhocko@kernel.org>
[not found] ` <20171016134446.19910-2-mhocko@kernel.org>
[not found] ` <CAGXu5jK8n4SCHniH85Wwtzw8QdoO1_1CMoiWqGnG-OBSwH2FRw@mail.gmail.com>
[not found] ` <CAGXu5jK8n4SCHniH85Wwtzw8QdoO1_1CMoiWqGnG-OBSwH2FRw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-10-16 19:00 ` [PATCH 1/2] fs, elf: drop MAP_FIXED usage from elf_map Michal Hocko
2017-10-16 20:02 ` James Hogan
2017-10-17 7:37 ` Michal Hocko
2017-10-17 8:35 ` James Hogan
2017-10-17 8:56 ` Michal Hocko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171017085643.wag7fsrqmhhnlr2f@dhcp22.suse.cz \
--to=mhocko@kernel.org \
--cc=bhe@redhat.com \
--cc=james.hogan@mips.com \
--cc=jkosina@suse.cz \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-metag@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).