From nobody Mon Feb 19 16:45:14 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TdpLM2Ltdz5C9Hn; Mon, 19 Feb 2024 16:45:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TdpLL6fn3z4bpB; Mon, 19 Feb 2024 16:45:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708361114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=R2Ud5+5uK1JDA8CBwRZSDyEeML9tckeBaaMg308yZec=; b=Bek+safOkdAiZwUWFOddVxuRltu5gd2KiZ/IyemmnIQFaNmzElrPHPjudf2iIXNlPBznvC DVwOUkm+Bjp63dI9gZ2nMYLK3Mj4Gvr+sMVYEo2b4LCB9rfDJQzUSHAn+3SYD0bvXxw4UE UtEYXpDfSdGm80Q6zrsGPJaTdu4i5b8xXo2FSLu7h5vvzi5ed/kLFNdVWrIIak6EppBaEU a2OKZh9D9xiJgctVts5VNx69/E4Lrd+d62vFqVgqJic/28q2bdhYJqf6SyL0cCK2TqujPc 7Sbh342rBtzb5a1DFvKcuRBNsBeFW/TZNSYLiK8QiihPNlEgMJ0410oc904U0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708361114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=R2Ud5+5uK1JDA8CBwRZSDyEeML9tckeBaaMg308yZec=; b=LI5OrQn3XjsIQJVB/yx7ftzeFByYEPlPgBH8N14dqTSy76eLByzFLvrTC7WOE9lZmW9Ymq dgP6OrRdlpKM3tviCGN6u7IDvrSiQS4xNnQAgtBj8XQwgaFa6CD76pdXWuKLLQdqvx+64z 8kub0bb9kaWdBciabZ385WK5muy6n7ztjFVsxboNIayDPHQGjFYJAEeKznSm2h4gZGcKXx 3nP6hXIT9QFoB2GIeJiI790DSf97gwQIFT2DuhHAohKmzfY+VwD7FF5XuIOBrJWQI7muD2 paLjog9xEH5/WfV9iuI7bAg5W69npClqqmb/n/pf71BqGG66R1TyByvUvPTWmA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708361114; a=rsa-sha256; cv=none; b=sB5ieaVU2ghlXavzsb9hZ97mrgrIz96BrpDFREsNrhMOzdYR1uav1/vcqD1DUvj+EezM3h eNguy10glLSPZt9htnHc5pcGTRHx24JBxPeBCtmFHuMYJCnIcE2nW9TBfiBwazchwQPTyM /9Nnt9lGEnG3a87cZ7gNdljKrELuAqrBXaIkDiRMTui2uwVWrFRfcHfby1M34rLiToucBg f5c1hEEtoXaePfS6RGRFUq7+zDR5y4P/m0AE1ClMWcH6NaIv5MPrjAij4r69QdRVUgZ46a CrA1xKtlF5BkUkp6gsy6GXgpjcO0F/UVjEls7zOSAajDGeyOv5lh0sEl3QXD8w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TdpLL5n7DzjGt; Mon, 19 Feb 2024 16:45:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41JGjEnk095858; Mon, 19 Feb 2024 16:45:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41JGjEXP095855; Mon, 19 Feb 2024 16:45:14 GMT (envelope-from git) Date: Mon, 19 Feb 2024 16:45:14 GMT Message-Id: <202402191645.41JGjEXP095855@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Andrew Turner Subject: git: eb1dae1c40f2 - stable/14 - csu: Teach csu about PAC and BTI List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: eb1dae1c40f261f39f96db83d86b995985b5af7c Auto-Submitted: auto-generated The branch stable/14 has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=eb1dae1c40f261f39f96db83d86b995985b5af7c commit eb1dae1c40f261f39f96db83d86b995985b5af7c Author: Andrew Turner AuthorDate: 2023-10-12 10:03:37 +0000 Commit: Andrew Turner CommitDate: 2024-02-19 13:12:08 +0000 csu: Teach csu about PAC and BTI Add the Branch Target Identification (BTI) note to libc assembly sources and Pointer Authentication Code (PAC) instructions to _init and _fini. _init and _fini may be called indirectly so need a BTI landing pad. As they are non-leaf functions use the appropriate PAC instruction that also guards against changing the link register. As all object files need the note for any binary using these object files we need to insert it in all asm files. Reviewed by: markj Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D42227 (cherry picked from commit 522126fea72419fae344fbcb897b41588909308a) --- lib/csu/aarch64/crt1_s.S | 4 ++++ lib/csu/aarch64/crti.S | 5 +++++ lib/csu/aarch64/crtn.S | 6 ++++++ lib/csu/common/crtbrand.S | 5 +++++ lib/csu/common/feature_note.S | 5 +++++ lib/csu/common/ignore_init_note.S | 5 +++++ 6 files changed, 30 insertions(+) diff --git a/lib/csu/aarch64/crt1_s.S b/lib/csu/aarch64/crt1_s.S index 97b4bff35a0b..981cf4653efd 100644 --- a/lib/csu/aarch64/crt1_s.S +++ b/lib/csu/aarch64/crt1_s.S @@ -30,6 +30,8 @@ */ #include +#include + /* * The program entry point * void _start(char **ap, void (*cleanup)(void)) __dead2 @@ -62,3 +64,5 @@ eprol: END(_start) .section .note.GNU-stack,"",@progbits + +GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL) diff --git a/lib/csu/aarch64/crti.S b/lib/csu/aarch64/crti.S index 0a20f4c5e314..8bd2dfac1494 100644 --- a/lib/csu/aarch64/crti.S +++ b/lib/csu/aarch64/crti.S @@ -28,11 +28,14 @@ */ #include +#include + .section .init,"ax",@progbits .align 4 .globl _init .type _init,@function _init: + PAC_LR_SIGN stp x29, x30, [sp, #-16]! mov x29, sp @@ -41,6 +44,8 @@ _init: .globl _fini .type _fini,@function _fini: + PAC_LR_SIGN stp x29, x30, [sp, #-16]! mov x29, sp +GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL) diff --git a/lib/csu/aarch64/crtn.S b/lib/csu/aarch64/crtn.S index 924aa36aa045..441411f0ab83 100644 --- a/lib/csu/aarch64/crtn.S +++ b/lib/csu/aarch64/crtn.S @@ -28,13 +28,19 @@ */ #include +#include + .section .init,"ax",@progbits ldp x29, x30, [sp], #16 + PAC_LR_AUTH ret .section .fini,"ax",@progbits ldp x29, x30, [sp], #16 + PAC_LR_AUTH ret .section .note.GNU-stack,"",%progbits + +GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL) diff --git a/lib/csu/common/crtbrand.S b/lib/csu/common/crtbrand.S index 0ed86bfba2b2..b59e2fd8056b 100644 --- a/lib/csu/common/crtbrand.S +++ b/lib/csu/common/crtbrand.S @@ -47,3 +47,8 @@ 4: .section .note.GNU-stack,"",%progbits + +#ifdef __aarch64__ +/* This is needed in all objects for BTI to be used in the linked elf file */ +GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL) +#endif diff --git a/lib/csu/common/feature_note.S b/lib/csu/common/feature_note.S index 343d2a9262e2..5c1d56d4cde1 100644 --- a/lib/csu/common/feature_note.S +++ b/lib/csu/common/feature_note.S @@ -40,3 +40,8 @@ 4: .section .note.GNU-stack,"",%progbits + +#ifdef __aarch64__ +/* This is needed in all objects for BTI to be used in the linked elf file */ +GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL) +#endif diff --git a/lib/csu/common/ignore_init_note.S b/lib/csu/common/ignore_init_note.S index fa37a8990538..57fb4e8f4d51 100644 --- a/lib/csu/common/ignore_init_note.S +++ b/lib/csu/common/ignore_init_note.S @@ -41,3 +41,8 @@ 4: .section .note.GNU-stack,"",%progbits + +#ifdef __aarch64__ +/* This is needed in all objects for BTI to be used in the linked elf file */ +GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL) +#endif