From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.19484.1680161339682354098 for ; Thu, 30 Mar 2023 00:28:59 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=b8MSLyhS; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 24651609FF for ; Thu, 30 Mar 2023 07:28:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88CC7C4339B for ; Thu, 30 Mar 2023 07:28:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680161338; bh=ruVFLdQXtouXGoWKGZHYju5B7HfBAAwyknA0go4L4I4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=b8MSLyhSTfNEJGo1aThRjHcVGOeyZg92I3eIbLoOBrdJk8PW1DVFW7q7nVP1tsh9s IVWynvJGNSFDeTphSRZO+BsC09joNUU1LSgZhqC+cLd0XGX7p365nSzTz8mId1TNbP hqwm9o4x0NaBBfEoXJIry5rBnq6lJYYLqwDFWBqgyYy+1663VOFnw5JBsWk1A81xx0 OGUMcC/ywJ6KwHL1WszDg1fsWoBQJVJe+rEs2Avu33F1ICEIvHBtnenAbhegJ0q5B7 RdKOkUZ7qzO0kAbax2cQSuBy9TOMN7wJic9lC0OIzKoZH6T4pL0/Zyu9+bHV26J8TL Uv+9hHUZGc3KQ== Received: by mail-lj1-f180.google.com with SMTP id z42so18619099ljq.13 for ; Thu, 30 Mar 2023 00:28:58 -0700 (PDT) X-Gm-Message-State: AAQBX9cW8fNp53IDiscx49h9FHHMVbFuE/VP9ib2/v2MPi49I0+GzicG pZLjSLorn2yfY9faxpf+EbISmtfMfLe+D17IdvM= X-Google-Smtp-Source: AKy350aG1O85RTvjzUK6pPeLGHYMp9hVsi+PH3PXQMjxflqrpB8Wax5C9G+/aMFYAqpKMZP50Zgkd/rWSTC3O321pOM= X-Received: by 2002:a2e:9c11:0:b0:298:bddc:dbbf with SMTP id s17-20020a2e9c11000000b00298bddcdbbfmr6648382lji.2.1680161336506; Thu, 30 Mar 2023 00:28:56 -0700 (PDT) MIME-Version: 1.0 References: <20230327110112.262503-1-ardb@kernel.org> <20230327110112.262503-2-ardb@kernel.org> In-Reply-To: From: "Ard Biesheuvel" Date: Thu, 30 Mar 2023 09:28:45 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] [PATCH v2 01/17] MdePkg/ProcessorBind AARCH64: Add asm macro to emit GNU BTI note To: devel@edk2.groups.io, quic_llindhol@quicinc.com Cc: pedro.falcato@gmail.com, Michael Kinney , Liming Gao , Jiewen Yao , Michael Kubacki , Sean Brogan , Rebecca Cran , Sami Mujawar , Taylor Beebe , =?UTF-8?Q?Marvin_H=C3=A4user?= , Bob Feng Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 27 Mar 2023 at 16:24, Leif Lindholm wro= te: > > On Mon, Mar 27, 2023 at 15:12:29 +0100, Pedro Falcato wrote: > > On Mon, Mar 27, 2023 at 12:01=E2=80=AFPM Ard Biesheuvel wrote: > > > > > > Implement a CPP macro that can be called from .S files to emit the .n= ote > > > section carrying the annotation that informs the linker that the obje= ct > > > file is compatible with BTI control flow integrity checks. > > > > > > Signed-off-by: Ard Biesheuvel > > > --- > > > MdePkg/Include/AArch64/ProcessorBind.h | 31 ++++++++++++++++++++ > > > 1 file changed, 31 insertions(+) > > > > > > diff --git a/MdePkg/Include/AArch64/ProcessorBind.h b/MdePkg/Include/= AArch64/ProcessorBind.h > > > index abe2571245c665f3..11814f1ffaef698a 100644 > > > --- a/MdePkg/Include/AArch64/ProcessorBind.h > > > +++ b/MdePkg/Include/AArch64/ProcessorBind.h > > > @@ -186,6 +186,37 @@ typedef INT64 INTN; > > > #define GCC_ASM_IMPORT(func__) \ > > > .extern _CONCATENATE (__USER_LABEL_PREFIX__, func__) > > > > > > +#if defined(__ARM_FEATURE_BTI_DEFAULT) && __ARM_FEATURE_BTI_DEFAULT = =3D=3D 1 > > > +#define AARCH64_BTI(__type) \ > > > + .ifnc __type, ;\ > > > + bti __type ;\ > > > + .endif ;\ > > > + .ifndef .Lgnu_bti_notesize ;\ > > > + .pushsection .note.gnu.property, "a" ;\ > > > + .set NT_GNU_PROPERTY_TYPE_0, 0x5 ;\ > > > + .set GNU_PROPERTY_AARCH64_FEATURE_1_AND, 0xc0000000 ;\ > > > + .set GNU_PROPERTY_AARCH64_FEATURE_1_BTI, 0x1 ;\ > > > + .align 3 ;\ > > > + .long .Lnamesize ;\ > > > + .long .Lgnu_bti_notesize ;\ > > > + .long NT_GNU_PROPERTY_TYPE_0 ;\ > > > +0: .asciz "GNU" ;\ > > > + .set .Lnamesize, . - 0b ;\ > > > + .align 3 ;\ > > > +1: .long GNU_PROPERTY_AARCH64_FEATURE_1_AND ;\ > > > + .long .Lvalsize ;\ > > > +2: .long GNU_PROPERTY_AARCH64_FEATURE_1_BTI ;\ > > > + .set .Lvalsize, . - 2b ;\ > > > + .align 3 ;\ > > > + .set .Lgnu_bti_notesize, . - 1b ;\ > > > + .popsection ;\ > > > + .endif > > > +#endif > > > + > > > +#endif > > > + > > > +#ifndef AARCH64_BTI > > > +#define AARCH64_BTI(__type) > > > #endif > > > > > > /** > > > -- > > > 2.39.2 > > > > Patch-set wide comment: is there any chance we could take this > > opportunity to introduce a global ASM_FUNC (or a more Linux-named > > ENTRY(FuncName))? > > It seems to be that the current way is a bit error prone and you end > > up repeating yourself quite a bit with: > > > > ASM_PFX(Foo): > > AARCH64_BTI(c) > > > > > > having a: > > ASM_FUNC(Foo) > > > > > > that does proper PFX and BTI expansion internally seems better to me. > > I was thinking while looking at this patch that ASM_FUNC could > probably do with moving over to this file from AsmMacroIoLibV8.h. > I didn't take the thought far enough to consider including the BTI > bits in that, but I guess that could make sense. > Yeah, but I'd prefer it if we could do that globally, and not just for AArch64 as part of this series.