From: Yu-cheng Yu <yu-cheng.yu@intel.com>
To: Dave Martin <Dave.Martin@arm.com>
Cc: x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
linux-mm@kvack.org, linux-arch@vger.kernel.org,
linux-api@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
Andy Lutomirski <luto@amacapital.net>,
Balbir Singh <bsingharora@gmail.com>,
Cyrill Gorcunov <gorcunov@gmail.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
Eugene Syromiatnikov <esyr@redhat.com>,
Florian Weimer <fweimer@redhat.com>,
"H.J. Lu" <hjl.tools@gmail.com>, Jann Horn <jannh@google.com>,
Jonathan Corbet <corbet@lwn.net>,
Kees Cook <keescook@chromium.org>,
Mike Kravetz <mike.kravetz@oracle.com>,
Nadav Amit <nadav.amit@gmail.com>,
Oleg Nesterov <oleg@redhat.com>,
Pa
Subject: Re: [PATCH] binfmt_elf: Extract .note.gnu.property from an ELF file
Date: Thu, 02 May 2019 08:48:42 -0700 [thread overview]
Message-ID: <ed56d7930e630213d74a7df8b9144d01415dac7c.camel@intel.com> (raw)
In-Reply-To: <20190502142951.GP3567@e103592.cambridge.arm.com>
On Thu, 2019-05-02 at 15:29 +0100, Dave Martin wrote:
> On Thu, May 02, 2019 at 12:10:04PM +0100, Dave Martin wrote:
> > On Wed, May 01, 2019 at 02:12:17PM -0700, Yu-cheng Yu wrote:
>
> [...]
>
> > > diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c > > index
> > > 7d09d125f148..40aa4a4fd64d 100644
> > > --- a/fs/binfmt_elf.c
> > > +++ b/fs/binfmt_elf.c
> > > @@ -1076,6 +1076,19 @@ static int load_elf_binary(struct linux_binprm
> > > *bprm)
> > > goto out_free_dentry;
> > > }
> > >
> > > + if (interpreter) {
> > > + retval = arch_setup_property(&loc->interp_elf_ex,
> > > + interp_elf_phdata,
> > > + interpreter, true);
> > > + } else {
> > > + retval = arch_setup_property(&loc->elf_ex,
> > > + elf_phdata,
> > > + bprm->file, false);
> > > + }
>
> This will be too late for arm64, since we need to twiddle the mmap prot
> flags for the executable's pages based on the detected properties.
>
> Can we instead move this much earlier, letting the arch code stash
> something in arch_state that can be consumed later on?
>
> This also has the advantage that we can report errors to the execve()
> caller before passing the point of no return (i.e., flush_old_exec()).
I will look into that.
>
> [...]
>
> > > diff --git a/fs/gnu_property.c b/fs/gnu_property.c
>
> [...]
>
> > > +int get_gnu_property(void *ehdr_p, void *phdr_p, struct file *f,
> > > + u32 pr_type, u32 *property)
> > > +{
> > > + struct elf64_hdr *ehdr64 = ehdr_p;
> > > + int err = 0;
> > > +
> > > + *property = 0;
> > > +
> > > + if (ehdr64->e_ident[EI_CLASS] == ELFCLASS64) {
> > > + struct elf64_phdr *phdr64 = phdr_p;
> > > +
> > > + err = scan_segments_64(f, phdr64, ehdr64->e_phnum,
> > > + pr_type, property);
> > > + if (err < 0)
> > > + goto out;
> > > + } else {
> > > +#ifdef CONFIG_COMPAT
> > > + struct elf32_hdr *ehdr32 = ehdr_p;
> > > +
> > > + if (ehdr32->e_ident[EI_CLASS] == ELFCLASS32) {
> > > + struct elf32_phdr *phdr32 = phdr_p;
> > > +
> > > + err = scan_segments_32(f, phdr32, ehdr32-
> > > >e_phnum,
> > > + pr_type, property);
> > > + if (err < 0)
> > > + goto out;
> > > + }
> > > +#else
> > > + WARN_ONCE(1, "Exec of 32-bit app, but CONFIG_COMPAT is not
> > > enabled.\n");
> > > + return -ENOTSUPP;
> > > +#endif
> > > + }
>
> We have already made a ton of assumptions about the ELF class by this
> point, and we don't seem to check it explicitly elsewhere, so it is a
> bit weird to police it specifically here.
>
> Can we simply pass the assumed ELF class as a parameter instead?
Yes.
Yu-cheng
next prev parent reply other threads:[~2019-05-02 15:48 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-01 21:12 [PATCH] binfmt_elf: Extract .note.gnu.property from an ELF file Yu-cheng Yu
2019-05-01 21:37 ` Matthew Wilcox
2019-05-01 21:54 ` Yu-cheng Yu
2019-05-02 11:10 ` Dave Martin
2019-05-02 14:29 ` Dave Martin
2019-05-02 15:48 ` Yu-cheng Yu [this message]
2019-05-02 15:47 ` Yu-cheng Yu
2019-05-02 16:14 ` Dave Martin
2019-05-02 16:25 ` Yu-cheng Yu
2019-06-26 17:14 ` Andy Lutomirski
2019-06-26 17:30 ` Yu-cheng Yu
2019-06-27 9:27 ` Dave Martin
2019-06-27 9:38 ` Florian Weimer
2019-06-29 23:51 ` Andy Lutomirski
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=ed56d7930e630213d74a7df8b9144d01415dac7c.camel@intel.com \
--to=yu-cheng.yu@intel.com \
--cc=Dave.Martin@arm.com \
--cc=arnd@arndb.de \
--cc=bsingharora@gmail.com \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=esyr@redhat.com \
--cc=fweimer@redhat.com \
--cc=gorcunov@gmail.com \
--cc=hjl.tools@gmail.com \
--cc=hpa@zytor.com \
--cc=jannh@google.com \
--cc=keescook@chromium.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@amacapital.net \
--cc=mike.kravetz@oracle.com \
--cc=mingo@redhat.com \
--cc=nadav.amit@gmail.com \
--cc=oleg@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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 NNTP newsgroup(s).