linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Dave Martin <Dave.Martin@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>,
	libc-alpha@sourceware.org, Kees Cook <keescook@chromium.org>,
	Szabolcs Nagy <szabolcs.nagy@arm.com>,
	Jeremy Linton <jeremy.linton@arm.com>,
	Mark Brown <broonie@kernel.org>, Will Deacon <will@kernel.org>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] arm64: bti: Set PROT_BTI on all BTI executables mapped by the kernel
Date: Mon, 8 Feb 2021 18:49:03 +0000	[thread overview]
Message-ID: <20210208184902.GC12694@gaia> (raw)
In-Reply-To: <20210208174028.GG21837@arm.com>

On Mon, Feb 08, 2021 at 05:40:29PM +0000, Dave P Martin wrote:
> On Mon, Feb 08, 2021 at 04:47:45PM +0000, Szabolcs Nagy via Libc-alpha wrote:
> > The 02/08/2021 14:13, Szabolcs Nagy via Libc-alpha wrote:
> > > The 02/08/2021 12:44, Will Deacon wrote:
> > > > I'd like an Ack from Szabolcs before we queue this.
> > > 
> > > i'm ok with this in principle, but i will rerun
> > > the glibc tests over night to be sure.
> > 
> > 
> > the patch applied cleanly on top of arm64 for-next/core
> > 
> > but it does not work as i expected:
> > 
> > executables that do not have the bti property note
> > set seems to get bti guarded by the kernel.
> > 
> > at least i see crash in _start when the dynamic
> > linker (which has bti marking) transfers control
> > to it and the start code has no bti c.
> > 
> > (according to strace the dynamic linker did not
> > remap/mprotect the main exe with bti so i assume
> > this is the kernel's doing)
> > 
> > can somebody verify that the notes are checked
> > on the executable too and not just on ld.so?

Thanks Szabolcs for testing.

> Reviewed-by bites the dust...
> 
> Aha, looking at the ELF code in the kernel, it looks like some extra
> refactoring is needed.
> 
> We do the heavy lifting only for the image containing the userspace
> entry point -- i.e., ld.so in the dynamically linked case.  This
> includes the ELF property handling.  When ld.so is present, the main
> executable is just data so we map it in but don't do a whole lot else
> with it:
> 
> static int load_elf_binary(struct linux_binprm *bprm)
> {
> 	/* ... */
> 
> 	retval = parse_elf_properties(interpreter ?: bprm->file,
> 				      elf_property_phdata, &arch_state);
> 
> The way I originally integrated this therefore just tracks the BTI-ness
> (and/or equivalently how to mutate PROT_EXEC) once.  Looks like we need
> to do that independently for ld.so and for the executable instead.
> 
> We could simplify things by treating it as an error if the executable
> and ld.so have different BTI properties, but that seems a bit of an own
> goal, since it breaks foreseeable backwards compatibility / hybrid use
> cases.

Ah, I haven't thought of these cases either.

In theory, if the dynamic loader hasn't been compiled with
-mbranch-protection=bti, it does not mean it won't be able to use
PROT_BTI on the mapped executable/libraries. The same goes for
BTI-compiled loader with a non-BTI executable, it should be allowed.

So I think decoupling the two makes sense but the patch is no longer as
simple as the ELF loader now needs to parse the main executable. If
that's doable and the code looks sane, I'd go with it. Otherwise, we
scrap the idea of the kernel setting PROT_BTI on the main executable.

-- 
Catalin

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-02-08 18:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05 17:38 [PATCH] arm64: bti: Set PROT_BTI on all BTI executables mapped by the kernel Mark Brown
2021-02-05 17:51 ` Catalin Marinas
2021-02-05 19:01   ` Mark Brown
2021-02-08 12:44   ` Will Deacon
2021-02-08 14:13     ` Szabolcs Nagy
2021-02-08 16:47       ` Szabolcs Nagy
2021-02-08 17:40         ` Dave Martin
2021-02-08 18:49           ` Catalin Marinas [this message]
2021-02-08 14:53 ` Dave Martin
2021-02-08 15:06   ` Mark Brown
2021-02-08 16:50     ` Szabolcs Nagy

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=20210208184902.GC12694@gaia \
    --to=catalin.marinas@arm.com \
    --cc=Dave.Martin@arm.com \
    --cc=broonie@kernel.org \
    --cc=jeremy.linton@arm.com \
    --cc=keescook@chromium.org \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=szabolcs.nagy@arm.com \
    --cc=will@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).