From nobody Mon Feb 19 16:45:09 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 4TdpLF4wh2z5C9N4; Mon, 19 Feb 2024 16:45:09 +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 4TdpLF1xCSz4bYm; Mon, 19 Feb 2024 16:45:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708361109; 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=XyMF+vc1fz1Sx13vBr2CJlHO56PoRnkcfUBYO0T4dWE=; b=EPww4lSu/XKs7phSH3RrSd9ah3+//I6WbMoVyqvprivHve50iGWB2kQktsi3tcHvqXD9oS EWOYt94tX4dOrK0t+XCGfsgSOGFkXmZi/SMrBcECr+LcNkC+BsbJlod6qZbmRxvtK/DLIc IbvY3bmmGRM0p//MauKYaZ8HtdneZPDXp25yhRrwPDWE35tOkcjP0GFGu3E2XxZJvhlzUX sk0/rUHhKUjRYM1tjKHfIwQt6HWqkpR39PVp1R5wDxCaJ0PY9rOz893zhWY7iv/+FTRqFq QYRP+GcnP/ugFBp3VWXO4kv5m343w9AJSBYLnuHt/AlKlWWLRakdjLVOSa2Z9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708361109; 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=XyMF+vc1fz1Sx13vBr2CJlHO56PoRnkcfUBYO0T4dWE=; b=RUKWREGPWLWI5DvYTRJSlVHlNMp/0X5FOQF9KZcRtRE2rWUFLl1ULslETYj9iYJbO27Qnp rJXHB9obbZfEt9sBAFzAX/Nkz2s4eX0XeVT7IpbqOgBOBKzW53Dj6/LOX7/1BaKjF5l7FN Eze2RUlmkOEggflqWuJTs8M3pJxDTNXoj8yE63CF51YjW3UmWz6z+Eb7mEDG+rPYatYCQl R/3SDdTljzaz4XSzLkGTbY+DyO7nHVmJHh9eQZN4fMJqPQ2b5vK91uJFVmLeaS/Vhauqre 4vHmw4BKm6r25FIQlmHkWJJItvAn/KMndk6GcygjaDDjO/cO1M5zm7nRG9p8WA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708361109; a=rsa-sha256; cv=none; b=C+KCrOZ2mCCDPOtBlAMeFJVC6AB/0RD2m1NEWbHwSZtHKTUfdT9Lk1r/g029vE5DgA51Qm P9erdKyH0zNCYPPLG/HSn6zYLfmjAIqPMu1dcba6pLqC/AdYZYyiz0kVt17utYcstcJMt0 JRgjcIRlMX7W9VTDijAndwJg1fR2Iu2T63YE2bhiREv2mcC3Xi8uRLqVoRwLjnM7q1IOYR OZ6wdkic1GNWsyOvfphpdzm/s239FMZVeLPeGZ7dRzQIT7VByQm0Y45Je0n7jqidLQaWft 1yrTvgLQ4q6AMNMA93l1yc3MN48Oeykyq1w73hHuJH80GzAkl4F/2MQEXuvblg== 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 4TdpLF0yRvzjSQ; Mon, 19 Feb 2024 16:45:09 +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 41JGj9A3095626; Mon, 19 Feb 2024 16:45:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41JGj9HW095623; Mon, 19 Feb 2024 16:45:09 GMT (envelope-from git) Date: Mon, 19 Feb 2024 16:45:09 GMT Message-Id: <202402191645.41JGj9HW095623@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: 0d44915e06e5 - stable/14 - arm64: Support creating a BTI & PAC note 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: 0d44915e06e5ff94a3338249aaf23301fe542de5 Auto-Submitted: auto-generated The branch stable/14 has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=0d44915e06e5ff94a3338249aaf23301fe542de5 commit 0d44915e06e5ff94a3338249aaf23301fe542de5 Author: Andrew Turner AuthorDate: 2023-10-10 13:00:59 +0000 Commit: Andrew Turner CommitDate: 2024-02-19 13:11:11 +0000 arm64: Support creating a BTI & PAC note To detect when an object file is build with the Branch Target Identification (BTI) and Pointer Authentication Code (PAC) extensions there is an elf note the compiler will insert. It will only do so from a high level language, e.g. C or C++. To get the not in assembly add the GNU_PROPERTY_AARCH64_FEATURE_1_NOTE macro that can be used to create it, and the GNU_PROPERTY_AARCH64_FEATURE_1_VAL macro to insert the correct value based on which combination of BTI and PAC are enabled. Reviewed by: markj (earlier version), emaste Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D42225 (cherry picked from commit 82597d2102a02c4e9e9355717c32867d34b77ef0) --- sys/arm64/include/asm.h | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/sys/arm64/include/asm.h b/sys/arm64/include/asm.h index 6ebfca6eaf0c..da3c3df5f647 100644 --- a/sys/arm64/include/asm.h +++ b/sys/arm64/include/asm.h @@ -142,6 +142,58 @@ #define BTI_J #endif +/* + * GNU_PROPERTY_AARCH64_FEATURE_1_NOTE can be used to insert a note that + * the current assembly file is built with Pointer Authentication (PAC) or + * Branch Target Identification support (BTI). As the linker requires all + * object files in an executable or library to have the GNU property + * note to emit it in the created elf file we need to add a note to all + * assembly files that support BTI so the kernel and dynamic linker can + * mark memory used by the file as guarded. + * + * The GNU_PROPERTY_AARCH64_FEATURE_1_VAL macro encodes the combination + * of PAC and BTI that have been enabled. It can be used as follows: + * GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL); + * + * To use this you need to include for + * GNU_PROPERTY_AARCH64_FEATURE_1_* + */ +#if defined(__ARM_FEATURE_BTI_DEFAULT) +#if defined(__ARM_FEATURE_PAC_DEFAULT) +/* BTI, PAC */ +#define GNU_PROPERTY_AARCH64_FEATURE_1_VAL \ + (GNU_PROPERTY_AARCH64_FEATURE_1_BTI | GNU_PROPERTY_AARCH64_FEATURE_1_PAC) +#else +/* BTI, no PAC */ +#define GNU_PROPERTY_AARCH64_FEATURE_1_VAL \ + (GNU_PROPERTY_AARCH64_FEATURE_1_BTI) +#endif +#elif defined(__ARM_FEATURE_PAC_DEFAULT) +/* No BTI, PAC */ +#define GNU_PROPERTY_AARCH64_FEATURE_1_VAL \ + (GNU_PROPERTY_AARCH64_FEATURE_1_PAC) +#else +/* No BTI, no PAC */ +#define GNU_PROPERTY_AARCH64_FEATURE_1_VAL 0 +#endif + +#if defined(__ARM_FEATURE_BTI_DEFAULT) || defined(__ARM_FEATURE_PAC_DEFAULT) +#define GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(x) \ + .section .note.gnu.property, "a"; \ + .balign 8; \ + .4byte 0x4; /* sizeof(vendor) */ \ + .4byte 0x10; /* sizeof(note data) */ \ + .4byte (NT_GNU_PROPERTY_TYPE_0); \ + .asciz "GNU"; /* vendor */ \ + /* note data: */ \ + .4byte (GNU_PROPERTY_AARCH64_FEATURE_1_AND); \ + .4byte 0x4; /* sizeof(property) */ \ + .4byte (x); /* property */ \ + .4byte 0 +#else +#define GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(x) +#endif + #endif /* _MACHINE_ASM_H_ */ #endif /* !__arm__ */