public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
From: Dave Martin <Dave.Martin@arm•com>
To: Will Deacon <will@kernel•org>
Cc: Catalin Marinas <catalin.marinas@arm•com>,
	Mark Brown <broonie@kernel•org>,
	Vincenzo Frascino <Vincenzo.Frascino@arm•com>,
	Kees Cook <keescook@chromium•org>,
	linux-arm-kernel@lists•infradead.org
Subject: Re: [PATCH v2 07/10] arm64: asm: Provide a mechanism for generating ELF note for BTI
Date: Tue, 5 May 2020 17:51:28 +0100	[thread overview]
Message-ID: <20200505165128.GR30377@arm.com> (raw)
In-Reply-To: <20200505145858.GB24239@willie-the-truck>

On Tue, May 05, 2020 at 03:58:59PM +0100, Will Deacon wrote:
> [+Dave]
> 
> On Wed, Apr 29, 2020 at 10:16:38PM +0100, Mark Brown wrote:
> > ELF files built for BTI should have a program property note section which
> > identifies them as such. The linker expects to find this note in all
> > object files it is linking into a BTI annotated output, the compiler will
> > ensure that this happens for C files but for assembler files we need to do
> > this in the source so provide a macro which can be used for this purpose.
> > 
> > This is mainly for use in the VDSO which should be a normal ELF shared
> > library and should therefore include BTI annotations when built for BTI.
> > 
> > Signed-off-by: Mark Brown <broonie@kernel•org>
> > ---
> >  arch/arm64/include/asm/assembler.h | 41 ++++++++++++++++++++++++++++++
> >  1 file changed, 41 insertions(+)
> > 
> > diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
> > index 0bff325117b4..85a88df2d0fe 100644
> > --- a/arch/arm64/include/asm/assembler.h
> > +++ b/arch/arm64/include/asm/assembler.h
> > @@ -736,4 +736,45 @@ USER(\label, ic	ivau, \tmp2)			// invalidate I line PoU
> >  .Lyield_out_\@ :
> >  	.endm
> >  
> > +/*
> > + * This macro emits a program property note section identifying
> > + * architecture features which require special handling, mainly for
> > + * use in assembly files included in the VDSO.
> > + */
> > +
> > +#ifdef CONFIG_ARM64_BTI_KERNEL
> > +
> > +#define NT_GNU_PROPERTY_TYPE_0  5
> > +#define GNU_PROPERTY_AARCH64_FEATURE_1_AND      0xc0000000
> > +
> > +#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI      (1U << 0)
> > +#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC      (1U << 1)
> > +
> > +.macro emit_aarch64_feature_1_and
> 
> Might be useful to take the features as a macro argument, so we can
> re-use this when extra features get added in the future.

Probably a good idea, though I hope this doesn't crop up too often...

> > +	.pushsection .note.gnu.property, "a"
> > +	.align  3
> > +	.long   2f - 1f
> > +	.long   6f - 3f
> > +	.long   NT_GNU_PROPERTY_TYPE_0
> > +1:      .string "GNU"
> > +2:
> > +	.align  3
> > +3:      .long   GNU_PROPERTY_AARCH64_FEATURE_1_AND
> > +	.long   5f - 4f
> > +4:
> > +	.long   GNU_PROPERTY_AARCH64_FEATURE_1_PAC | \
> > +		GNU_PROPERTY_AARCH64_FEATURE_1_BTI
> 
> Hmm. The Linux ABI doc [1] says this field is:
> 
> 	unsigned char pr_data[PR_DATASZ];
> 
> but the AArch64 PCS [2] says:
> 
> 	"It has a single 32-bit value for the pr_data field."
> 
> What does this mean for endianness?

I think this means it's poorly specified.

The spirit of this is that each property is a container for a random ELF
structure, whose elements are encoded with endianness matching that of 
the ELF file.

Because these structures are variably sized, they can't be described
properly using a C type.  The pseudo-C in [1] is illustrative but a bit
of a bodge IMHO.  Attempting to do things this way for real would also
get you into trouble with strict-aliasing IIUC.


This ship has already sailed: someone should check what comes out of
cc -mbig-endian -mbranch-protection=standard.  (Extra points scored if
you can persuade gcc and clang to do something different!)

Cheers
---Dave

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

  reply	other threads:[~2020-05-05 16:51 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-29 21:16 [PATCH v2 00/10] arm64: BTI kernel and vDSO support Mark Brown
2020-04-29 21:16 ` [PATCH v2 01/10] arm64: bti: Support building kernel C code using BTI Mark Brown
2020-05-05 16:50   ` Dave Martin
2020-05-05 17:31     ` Mark Brown
2020-05-06 12:24       ` Amit Kachhap
2020-04-29 21:16 ` [PATCH v2 02/10] arm64: asm: Override SYM_FUNC_START when building the kernel with BTI Mark Brown
2020-05-05 14:56   ` Will Deacon
2020-05-05 15:18     ` Mark Brown
2020-05-05 16:08       ` Will Deacon
2020-05-05 17:21         ` Mark Brown
2020-05-06  7:10           ` Will Deacon
2020-05-06 10:41             ` Mark Brown
2020-05-06 10:50               ` Will Deacon
2020-05-06 11:43                 ` Mark Brown
2020-05-06 12:27                   ` Will Deacon
2020-05-06 13:03                     ` Mark Brown
2020-05-06 13:40                 ` Dave Martin
2020-05-06 14:45                   ` Will Deacon
2020-05-06 15:25                     ` Mark Brown
2020-05-06 15:48                       ` Will Deacon
2020-05-06 15:33                     ` Dave Martin
2020-04-29 21:16 ` [PATCH v2 03/10] arm64: Set GP bit in kernel page tables to enable BTI for the kernel Mark Brown
2020-04-29 21:16 ` [PATCH v2 04/10] arm64: bpf: Annotate JITed code for BTI Mark Brown
2020-04-29 21:16 ` [PATCH v2 05/10] arm64: mm: Mark executable text as guarded pages Mark Brown
2020-04-29 21:16 ` [PATCH v2 06/10] arm64: bti: Provide Kconfig for kernel mode BTI Mark Brown
2020-04-29 21:16 ` [PATCH v2 07/10] arm64: asm: Provide a mechanism for generating ELF note for BTI Mark Brown
2020-05-05 14:58   ` Will Deacon
2020-05-05 16:51     ` Dave Martin [this message]
2020-05-05 17:06     ` Mark Brown
2020-05-06 11:26       ` Will Deacon
2020-05-06 12:38         ` Mark Brown
2020-05-06 13:44           ` Will Deacon
2020-05-06 15:39             ` Mark Brown
2020-04-29 21:16 ` [PATCH v2 08/10] arm64: vdso: Annotate " Mark Brown
2020-04-29 21:16 ` [PATCH v2 09/10] arm64: vdso: Force the vDSO to be linked as BTI when built " Mark Brown
2020-04-29 21:16 ` [PATCH v2 10/10] arm64: vdso: Map the vDSO text with guarded pages " Mark Brown
2020-04-30 17:18 ` [PATCH v2 00/10] arm64: BTI kernel and vDSO support Catalin Marinas
2020-04-30 17:23   ` Mark Brown

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=20200505165128.GR30377@arm.com \
    --to=dave.martin@arm$(echo .)com \
    --cc=Vincenzo.Frascino@arm$(echo .)com \
    --cc=broonie@kernel$(echo .)org \
    --cc=catalin.marinas@arm$(echo .)com \
    --cc=keescook@chromium$(echo .)org \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    --cc=will@kernel$(echo .)org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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