From patchwork Fri Jan 3 15:41:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 103960 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 43BF03858C60 for ; Fri, 3 Jan 2025 15:49:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 43BF03858C60 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 8C3E43858C60 for ; Fri, 3 Jan 2025 15:43:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8C3E43858C60 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8C3E43858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1735919023; cv=none; b=Gn8Nfq5CaE8cQeSw3bpFrtQEJUf5/A2dwGKrV/Uv/vLK5bRmVl8UhGfRvdw7UQtd+TayK0CARmYHLkgIZA8sxVQtseGqKCoCcwe1RKbdmTcBdIFX4S8R3ARdaTWJtbwHxpU/1cAC2/Z1aGrhsWzUVnU+q4as8B3MhXzoFwd852o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1735919023; c=relaxed/simple; bh=bCusDRHVOXx17EGRKGy8xlyZ5Wf65I/hD/bMtoGpN58=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=ZkjAo6s4gNnAwBNYerx6HfsWLm4BzZzIHYGlphui7yj0zpjKTR4aOk4GApbIxuFelVWUHvlyv03pY+BH2mWTuHVSBgV2AEi/tKxeu7cGREWpaHS/Edb2ZUOdl4ZVE/U013RFBf+lkQ9oVkeJWiX9GZWwcxC9U9HCC0JHOiJDoVA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C3E43858C60 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8D9CF150C; Fri, 3 Jan 2025 07:44:11 -0800 (PST) Received: from udebian.localdomain (unknown [10.57.3.206]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 72D6F3F6A8; Fri, 3 Jan 2025 07:43:42 -0800 (PST) From: Yury Khrustalev To: libc-alpha@sourceware.org Cc: fweimer@redhat.com, adhemerval.zanella@linaro.org, codonell@redhat.com, nsz@gcc.gnu.org, schwab@suse.de, wilco.dijkstra@arm.com Subject: [PATCH v7 20/23] aarch64: Process gnu properties in static exe Date: Fri, 3 Jan 2025 15:41:38 +0000 Message-Id: <20250103154141.47731-21-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250103154141.47731-1-yury.khrustalev@arm.com> References: <20250103154141.47731-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Szabolcs Nagy Unlike for BTI, the kernel does not process GCS properties so update GL(dl_aarch64_gcs) before the GCS status is set. Co-authored-by: Yury Khrustalev --- csu/libc-start.c | 12 ++++++++++++ sysdeps/generic/libc-start.h | 1 + sysdeps/unix/sysv/linux/aarch64/libc-start.h | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/csu/libc-start.c b/csu/libc-start.c index 6f3d52e223..325ef010d4 100644 --- a/csu/libc-start.c +++ b/csu/libc-start.c @@ -206,6 +206,10 @@ call_fini (void *unused) #include +#ifndef ARCH_PROCESS_NOTES +# define ARCH_PROCESS_NOTES() +#endif + STATIC int LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), int argc, @@ -219,6 +223,11 @@ STATIC int LIBC_START_MAIN (int (*main) (int, char **, char ** void *stack_end) __attribute__ ((noreturn)); +void +__libc_process_notes (void) +{ + +} /* Note: The init and fini parameters are no longer used. fini is completely unused, init is still called if not NULL, but the @@ -276,6 +285,9 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), /* Perform IREL{,A} relocations. */ ARCH_SETUP_IREL (); + /* Process notes: PT_NOTE / PT_GNU_PROPERTY. */ + ARCH_PROCESS_NOTES (); + /* The stack guard goes into the TCB, so initialize it early. */ ARCH_SETUP_TLS (); diff --git a/sysdeps/generic/libc-start.h b/sysdeps/generic/libc-start.h index 0b107cf2a1..1a421626b5 100644 --- a/sysdeps/generic/libc-start.h +++ b/sysdeps/generic/libc-start.h @@ -24,6 +24,7 @@ initialization, and this means you cannot, without machine knowledge, access TLS from an IFUNC resolver. */ #define ARCH_SETUP_IREL() apply_irel () +#define ARCH_PROCESS_NOTES() __libc_process_notes () #define ARCH_SETUP_TLS() __libc_setup_tls () #define ARCH_APPLY_IREL() #endif /* ! SHARED */ diff --git a/sysdeps/unix/sysv/linux/aarch64/libc-start.h b/sysdeps/unix/sysv/linux/aarch64/libc-start.h index 735076c086..0f80a8abe9 100644 --- a/sysdeps/unix/sysv/linux/aarch64/libc-start.h +++ b/sysdeps/unix/sysv/linux/aarch64/libc-start.h @@ -21,6 +21,24 @@ #ifndef SHARED +# include + +/* Must be on a top-level stack frame that does not return. */ +static inline void __attribute__((always_inline)) +aarch64_libc_process_notes (void) +{ + struct link_map *main_map = _dl_get_dl_main_map (); + const ElfW(Phdr) *phdr = GL(dl_phdr); + const ElfW(Phdr) *ph; + for (ph = phdr; ph < phdr + GL(dl_phnum); ph++) + if (ph->p_type == PT_GNU_PROPERTY) + { + _dl_process_pt_gnu_property (main_map, -1, ph); + _rtld_main_check (main_map, _dl_argv[0]); + break; + } +} + # ifndef PR_SET_SHADOW_STACK_STATUS # define PR_SET_SHADOW_STACK_STATUS 75 # define PR_SHADOW_STACK_ENABLE (1UL << 0) @@ -39,6 +57,7 @@ aarch64_libc_setup_tls (void) } # define ARCH_SETUP_IREL() apply_irel () +# define ARCH_PROCESS_NOTES() aarch64_libc_process_notes () # define ARCH_SETUP_TLS() aarch64_libc_setup_tls () # define ARCH_APPLY_IREL() #endif /* ! SHARED */