From patchwork Tue Jan 9 20:23:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1884633 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=FIfYbs9I; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T8j7d3M3Hz1yPm for ; Wed, 10 Jan 2024 07:23:57 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71909385AC12 for ; Tue, 9 Jan 2024 20:23:55 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by sourceware.org (Postfix) with ESMTPS id 5EC333858426 for ; Tue, 9 Jan 2024 20:23:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5EC333858426 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5EC333858426 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1035 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704831812; cv=none; b=rRnKeiUkg7ggIWQQ4fkG4McfdEn97+wsjhVCYFGwe0TcpZAAfQDyQpWQkvU0xSiKHE9+SraJOOGnQijodY6MleCrw+0JDd4paozCoUt6JoZJgIQoYnqSBUPC7+8BuFNr6iJAoGji7I2UQyXpR4T0lVezw5I1BPpQ8gqaI4YX+8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704831812; c=relaxed/simple; bh=M9AvoD8Aqs6257um81l3Wnm99dyi3J6XhZkaIH/yAc0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TW+z+Y37Eq76DTVNoanl8KTQfRJrHmfumeSiLAWcTo+T6KMYds5bOkyZsW9Tywcoic7r8bUDG3d/dfC+GoxfYtXVGt70nNydYGNWSdRgoACKfm12B1xeFxjFYrxnIeOW9lnTxuyb/aP0m2ExS0bYej50JgUrPdR+bB5LjjaW3s8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-28cec7ae594so2944302a91.3 for ; Tue, 09 Jan 2024 12:23:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704831809; x=1705436609; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8gg70xkDf+aW3HAwhgnAilQuj6AoF9ss0zHBQECPtw0=; b=FIfYbs9IxyfxTRrpApMeACRIwK1vg+Yz7XhsCGeXbsSE67i7DlKcqkkZldZZECwGZ5 TtIn8Vp3XM+bzOjXN5ETHTM2Qn1KzxIH5qTIVdXdqQk9Bm2OhfY6p5H9ZnpgZTKF2JFj VtQUIwnxkmJvERSVUXnwqykoxHWShJvPDQY1lED5yZBpbCHUxkoBDFqkJdjJkJhh+FK9 BJ91v2PABm6BopDJybn3jzqFtWCERoNQAkCnQw+dl033jl+kbTKGb9Qy0uIBIYrmAgr/ T/pTX+6FGA7anYm82vU8HA2js68hgIUyzvga8dgJytFy2yxT7ZKTXpPiHbdjpPlJ1Dxh +g6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704831809; x=1705436609; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8gg70xkDf+aW3HAwhgnAilQuj6AoF9ss0zHBQECPtw0=; b=Ybakafy+Dl3WKu0ewpSHCt34TVHnSEHlRlYT6P3hgi3UlgtO0LHaLKyRVwH/PcpjWb ToNTsraTHb3haK664QrJFSBTURGzv1yNkE7koBA3Cm1MTamQsyw+xDJbZl7qyCAF4p7o 88H4psK8LfcugadVCkZFqYUqYCt2+su3e5XlEkqdc013BXnckVJtJy+3PFaIaGYm/cz4 ZHQcTnk0i42aVh+lUWHtfuwVwkfMutY6eXxgTOwwO+x16c1/d6mttQ5OGZy9MjjFwdaw i4o5uqEuzQweHgA17PWauaAxQV4wx3Xj4tpB6PyY7aC9hvkBHWua42yzFiUeM25/UoNy zlJw== X-Gm-Message-State: AOJu0YypMJMkfSX2YsfyhC/K4z5iB7Lx2B4crjdhadEAn0BU+dC0gRVv Wkj/UTLgi302TFsxz68KYclbw3LYluc= X-Google-Smtp-Source: AGHT+IE9cHAWS+1+jxmWh4mOD19fpmkZ+NxjBeFRdaBISZ2v1CYHH6y6MCrnFQU+Ge0qM2fvFoUawQ== X-Received: by 2002:a17:90a:c291:b0:28d:2ad0:41fc with SMTP id f17-20020a17090ac29100b0028d2ad041fcmr3159214pjt.24.1704831809428; Tue, 09 Jan 2024 12:23:29 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.169.119]) by smtp.gmail.com with ESMTPSA id s4-20020a17090a6e4400b0028ceeca04a1sm2448739pjm.19.2024.01.09.12.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 12:23:29 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id BDB1F740676; Tue, 9 Jan 2024 12:23:27 -0800 (PST) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: adhemerval.zanella@linaro.org, goldstein.w.n@gmail.com Subject: [PATCH v3 1/4] x86: Move x86-64 shadow stack startup codes Date: Tue, 9 Jan 2024 12:23:24 -0800 Message-ID: <20240109202327.1565961-2-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240109202327.1565961-1-hjl.tools@gmail.com> References: <20240109202327.1565961-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3024.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org Move sysdeps/x86/libc-start.h to sysdeps/x86_64/libc-start.h and use sysdeps/generic/libc-start.h for i386. Reviewed-by: Adhemerval Zanella --- sysdeps/{x86 => x86_64}/libc-start.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename sysdeps/{x86 => x86_64}/libc-start.h (98%) diff --git a/sysdeps/x86/libc-start.h b/sysdeps/x86_64/libc-start.h similarity index 98% rename from sysdeps/x86/libc-start.h rename to sysdeps/x86_64/libc-start.h index c3cc05888d..63fef17029 100644 --- a/sysdeps/x86/libc-start.h +++ b/sysdeps/x86_64/libc-start.h @@ -1,4 +1,4 @@ -/* X86 definitions for libc main startup. +/* x86-64 definitions for libc main startup. Copyright (C) 2018-2024 Free Software Foundation, Inc. This file is part of the GNU C Library. From patchwork Tue Jan 9 20:23:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1884637 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=kYApMN4q; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T8j8Y1RN7z1yPm for ; Wed, 10 Jan 2024 07:24:45 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3A3E23857C43 for ; Tue, 9 Jan 2024 20:24:43 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 4CA5B385840F for ; Tue, 9 Jan 2024 20:23:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4CA5B385840F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4CA5B385840F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704831812; cv=none; b=cE2Hb/4KmReMkQZw0bjREdgGOHxm3x4pHc7Iz9qN+PmuKiMzDfhbPwocbVaXOQd2OxxgUkoU5Gx5QAjDS9iMjdRzZGCsf0asAwVeS+4vIlfQPWiZr9B+oIyscIm/U+QX0Vqp9OroCoGmDGC8QdEON7FIj0yggzsL4Or1mbYoNLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704831812; c=relaxed/simple; bh=eY9o3A/Ua6+L9R5xE4zQrNxqilQpakr/XNZkB5NJjco=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=admakvneI2kolmwBYM8AS581fd8wLeCR5ZyFutsCG0NSl3c+8VSMc1Oldb7TmtJJLDCzooezgE9RiEPQK7QqIJtW9F6eN+u0XcjJ4EJdJ7LzPasIvYtSFa8KZ2OXgjvhOMgLHN18vwI3ODW8HLZOFReJ0c+uo7ucYVFzuAkwUHg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6d9ac5bd128so2067602b3a.0 for ; Tue, 09 Jan 2024 12:23:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704831809; x=1705436609; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iisgiVoaUxCXz3Gl3SwC/cdsk1FlRAFZmjHqOeOFRpE=; b=kYApMN4qjpkueakJJdE1yU50O1e7Q//ObM+JO4yPihMrV19B/Nr5xLYm1kluQ4FbuY r4Rime0fhUtnidNUkJ1Jo0b4Q3/B/IxImEONLlteerFxStq7VvDUnHXfxduxJBLr/jdW sJLR4xJPTjfI1PIpnzHhWwFb5RBvTjSObIMwYijbxN8rUdK9Ti6G1RyrYM0v1E3zBCnx WxVqe5K9fSoSl8M9E2V1kA7wQp4ffaibGZSp1uXa8KnwWMkHNMJhubGolyy3ZBd40sQp k2zwwmsR13kzvRyPon8c1sgIlYfDjYqdOoX4rt0+/OxCmx8vHkbrAK1o11LHL0m/uj8x 5jDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704831809; x=1705436609; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iisgiVoaUxCXz3Gl3SwC/cdsk1FlRAFZmjHqOeOFRpE=; b=Qha4YLnumOcPGpAyKEoc0LlS80ObJfSptO1eTKvdLu9fM4C6UOiUnPL4A1uCeLLCTl d6I9Eg9k2lI0TesqObPqx7gsA0pECHURjrPFaZ5kV8+WPiizzgL9vMfsR5HXwxb6VeUq +7pN8TkgXBKQBWPq+uS7lITXENQd9u1k5WjoAYI6fFlrF2lFq4sK7F7T6svR+awDYIyn pxXoZOaayZJc8FqiMHo6u3FAkvCFDTlnU9YYNSey1oSFrIIVrhTWNKBYIELiexRTO8kF bTF2dx6kio3+vc3iX7DoidDO9cqWv5t9RR+ITnyTRCrnimds0hC4KRC2tb/wEzt5jSQq YS+Q== X-Gm-Message-State: AOJu0YxAl2MMRe3WlgRjGny+20nSZjtF0jdDpiIS+vNDFD9FqyfTCFyY mRuU2qqB6B9KB7GKOaxAt6dtC4Eh7nw= X-Google-Smtp-Source: AGHT+IEtJuuKHhdHD1K8cxg26PDbbywMAyMW09p3RniHEdFSZfH0nuAwOxbtfmAUH71TgXF7O5/KqA== X-Received: by 2002:a05:6a00:9295:b0:6d9:b4e6:12c5 with SMTP id jw21-20020a056a00929500b006d9b4e612c5mr55611pfb.0.1704831809162; Tue, 09 Jan 2024 12:23:29 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.169.119]) by smtp.gmail.com with ESMTPSA id i22-20020aa78d96000000b006dacbe57efbsm2130927pfr.90.2024.01.09.12.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 12:23:28 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id C9BC6740677; Tue, 9 Jan 2024 12:23:27 -0800 (PST) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: adhemerval.zanella@linaro.org, goldstein.w.n@gmail.com Subject: [PATCH v3 2/4] x86-64/cet: Move dl-cet.[ch] to x86_64 directories Date: Tue, 9 Jan 2024 12:23:25 -0800 Message-ID: <20240109202327.1565961-3-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240109202327.1565961-1-hjl.tools@gmail.com> References: <20240109202327.1565961-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3024.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org Since CET is only enabled for x86-64, move dl-cet.[ch] to x86_64 directories. Reviewed-by: Adhemerval Zanella --- sysdeps/unix/sysv/linux/x86/dl-cet.h | 63 ------------------------- sysdeps/unix/sysv/linux/x86_64/dl-cet.h | 47 +++++++++++++++++- sysdeps/{x86 => x86_64}/dl-cet.c | 2 +- 3 files changed, 47 insertions(+), 65 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/x86/dl-cet.h rename sysdeps/{x86 => x86_64}/dl-cet.c (99%) diff --git a/sysdeps/unix/sysv/linux/x86/dl-cet.h b/sysdeps/unix/sysv/linux/x86/dl-cet.h deleted file mode 100644 index c10773ab0e..0000000000 --- a/sysdeps/unix/sysv/linux/x86/dl-cet.h +++ /dev/null @@ -1,63 +0,0 @@ -/* Linux/x86 CET initializers function. - Copyright (C) 2018-2024 Free Software Foundation, Inc. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -static __always_inline int -dl_cet_disable_cet (unsigned int cet_feature) -{ - if (cet_feature != GNU_PROPERTY_X86_FEATURE_1_SHSTK) - return -1; - long long int kernel_feature = ARCH_SHSTK_SHSTK; - return (int) INTERNAL_SYSCALL_CALL (arch_prctl, ARCH_SHSTK_DISABLE, - kernel_feature); -} - -static __always_inline int -dl_cet_lock_cet (unsigned int cet_feature) -{ - if (cet_feature != GNU_PROPERTY_X86_FEATURE_1_SHSTK) - return -1; - /* Lock all SHSTK features. */ - long long int kernel_feature = -1; - return (int) INTERNAL_SYSCALL_CALL (arch_prctl, ARCH_SHSTK_LOCK, - kernel_feature); -} - -static __always_inline unsigned int -dl_cet_get_cet_status (void) -{ - unsigned long long kernel_feature; - unsigned int status = 0; - if (INTERNAL_SYSCALL_CALL (arch_prctl, ARCH_SHSTK_STATUS, - &kernel_feature) == 0) - { - if ((kernel_feature & ARCH_SHSTK_SHSTK) != 0) - status = GNU_PROPERTY_X86_FEATURE_1_SHSTK; - } - return status; -} - -/* Enable shadow stack with a macro to avoid shadow stack underflow. */ -#define ENABLE_X86_CET(cet_feature) \ - if ((cet_feature & GNU_PROPERTY_X86_FEATURE_1_SHSTK)) \ - { \ - long long int kernel_feature = ARCH_SHSTK_SHSTK; \ - INTERNAL_SYSCALL_CALL (arch_prctl, ARCH_SHSTK_ENABLE, \ - kernel_feature); \ - } diff --git a/sysdeps/unix/sysv/linux/x86_64/dl-cet.h b/sysdeps/unix/sysv/linux/x86_64/dl-cet.h index c89dd6bd42..94e9b9aa86 100644 --- a/sysdeps/unix/sysv/linux/x86_64/dl-cet.h +++ b/sysdeps/unix/sysv/linux/x86_64/dl-cet.h @@ -15,8 +15,53 @@ License along with the GNU C Library; if not, see . */ +#include +#include #include -#include_next + +static __always_inline int +dl_cet_disable_cet (unsigned int cet_feature) +{ + if (cet_feature != GNU_PROPERTY_X86_FEATURE_1_SHSTK) + return -1; + long long int kernel_feature = ARCH_SHSTK_SHSTK; + return (int) INTERNAL_SYSCALL_CALL (arch_prctl, ARCH_SHSTK_DISABLE, + kernel_feature); +} + +static __always_inline int +dl_cet_lock_cet (unsigned int cet_feature) +{ + if (cet_feature != GNU_PROPERTY_X86_FEATURE_1_SHSTK) + return -1; + /* Lock all SHSTK features. */ + long long int kernel_feature = -1; + return (int) INTERNAL_SYSCALL_CALL (arch_prctl, ARCH_SHSTK_LOCK, + kernel_feature); +} + +static __always_inline unsigned int +dl_cet_get_cet_status (void) +{ + unsigned long long kernel_feature; + unsigned int status = 0; + if (INTERNAL_SYSCALL_CALL (arch_prctl, ARCH_SHSTK_STATUS, + &kernel_feature) == 0) + { + if ((kernel_feature & ARCH_SHSTK_SHSTK) != 0) + status = GNU_PROPERTY_X86_FEATURE_1_SHSTK; + } + return status; +} + +/* Enable shadow stack with a macro to avoid shadow stack underflow. */ +#define ENABLE_X86_CET(cet_feature) \ + if ((cet_feature & GNU_PROPERTY_X86_FEATURE_1_SHSTK)) \ + { \ + long long int kernel_feature = ARCH_SHSTK_SHSTK; \ + INTERNAL_SYSCALL_CALL (arch_prctl, ARCH_SHSTK_ENABLE, \ + kernel_feature); \ + } #define X86_STRINGIFY_1(x) #x #define X86_STRINGIFY(x) X86_STRINGIFY_1 (x) diff --git a/sysdeps/x86/dl-cet.c b/sysdeps/x86_64/dl-cet.c similarity index 99% rename from sysdeps/x86/dl-cet.c rename to sysdeps/x86_64/dl-cet.c index d1d42ab002..1297c09f84 100644 --- a/sysdeps/x86/dl-cet.c +++ b/sysdeps/x86_64/dl-cet.c @@ -1,4 +1,4 @@ -/* x86 CET initializers function. +/* x86-64 CET initializers function. Copyright (C) 2018-2024 Free Software Foundation, Inc. The GNU C Library is free software; you can redistribute it and/or From patchwork Tue Jan 9 20:23:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1884635 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=W6OjiHZn; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T8j7j2Zssz1yPm for ; Wed, 10 Jan 2024 07:24:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 55BB3385843E for ; Tue, 9 Jan 2024 20:23:59 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by sourceware.org (Postfix) with ESMTPS id 98E6E385843E for ; Tue, 9 Jan 2024 20:23:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 98E6E385843E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 98E6E385843E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704831814; cv=none; b=PR1t5m0GqgoVKTIJ39JlXHKqqM4UTvneDgbnD1CBN6DjtCdLsrbUt6XtSpGgzpVrDMfw4VnPGJFTHZwYNMlRlmfgomPT9T/ZSzQimFvzKgV0DA4Cnh4NWasvsGGTuHU11oYc+m270X4R+uFTcNI2Z2PtYVIs1wtdsHxRTp4bsKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704831814; c=relaxed/simple; bh=LBIDihAL7Eqy6UFRI6uhTOpYU9BQmISEY2cIEW13VD0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=UCtu6MPqBbNPcTDbYth7HOEUdz43qHviF9Z/MZdDhu5GJd6SrZeUvvbfL23cy0mihXmuWEuNXf9LKUSfdsztvQiAVz4NmF3MgcreSfW8ECiebf1L0uSA72GQfEsoCn4CH9L7HlTADTGovpN5IzNM3gc9CKbl2P2f2+EEjJ8E53w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-5ce10b5ee01so2266336a12.1 for ; Tue, 09 Jan 2024 12:23:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704831809; x=1705436609; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=weLEfC+/PBKM4TzqtlUl0l6E+v/HQaymuPA3aMU5GYA=; b=W6OjiHZnYXy07NKzl4eEAP1VSg3f1kUa39oSqfyuJDHWAtMOWR0PhrZCe9HPijDkki m0lp1/OvDF/A5ccd5cVyDo1O4XttH+bO2X4VP0b3pSp1j3rINc5OUsuOzF3bNged2VY6 W7YWHa/cbZy1rn+do2BshCicTsN1gGCWsv1J81lIb/k9r9zOBdlhHKUPYT+4G4Eo2q/b Qfq/oX1no+tuxFoXHrYvG1l7jDIRDeMw8Fj8vlQWB6v0Pt16AxvbDT7EotOl2Ny3JcGY VZlb45WHqzShHiJoj3QY4l2Uu/Tr30OV5nm4hTL+jb3wZUCR08LwjjUzQWwkcr3V8P2P 1a1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704831809; x=1705436609; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=weLEfC+/PBKM4TzqtlUl0l6E+v/HQaymuPA3aMU5GYA=; b=xQdijjVzwCtVxJzHuOwHuJdLmKLPRXYJIevwadhGcUD5dAWSXrWOJdfTVdK5t3Vopb nnG0WYfmp/nI83t7cLFcH83SKSFzNFxNazAtZ8//siSJ06ei4bt62dUGMlFu/oH8wguq 7pVjKOnVDcib9APvb2BWeXRbSo//KHXdQx8Sr9Ch2ygpUZ7HSQ5kHmS2/npUS02KAR4s 59ahvK966hvIY2U1T2vMT+YxaYZAkFGVf1fe7yjAymiItzmK5ik0HyUi7gd1ceFEwtxu yPyHvaRW+qU8k3UWrCNhQu0ZZ2ItMc0vbMFsZvDqqPErU1cjRcDjwtVaa2Kr93OaABev oTVQ== X-Gm-Message-State: AOJu0YyidMLp05q4jEeGclL0MaLSRCnu05+AQoXUOXp7E0vwFpD14c0N q0k7W+OBdiwZzX0iThC8IuByDmnqLGs= X-Google-Smtp-Source: AGHT+IFQfpb7TveFzmkq8Z0OMayqWyn8CdEkj9zJIvsmB026wzTjY8vGaZE+Gmxp8NwbG/ZBPuoOsA== X-Received: by 2002:a05:6a21:999f:b0:199:29c4:b4b2 with SMTP id ve31-20020a056a21999f00b0019929c4b4b2mr1738354pzb.29.1704831809674; Tue, 09 Jan 2024 12:23:29 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.169.119]) by smtp.gmail.com with ESMTPSA id f22-20020a631016000000b005cd821a01d4sm2051945pgl.28.2024.01.09.12.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 12:23:29 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id D5C96740678; Tue, 9 Jan 2024 12:23:27 -0800 (PST) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: adhemerval.zanella@linaro.org, goldstein.w.n@gmail.com Subject: [PATCH v3 3/4] x86-64/cet: Move check-cet.awk to x86_64 Date: Tue, 9 Jan 2024 12:23:26 -0800 Message-ID: <20240109202327.1565961-4-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240109202327.1565961-1-hjl.tools@gmail.com> References: <20240109202327.1565961-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3024.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org --- sysdeps/x86_64/Makefile | 2 +- sysdeps/{x86 => x86_64}/check-cet.awk | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename sysdeps/{x86 => x86_64}/check-cet.awk (100%) Reviewed-by: Adhemerval Zanella diff --git a/sysdeps/x86_64/Makefile b/sysdeps/x86_64/Makefile index 98f0e04f90..e8babc9a4e 100644 --- a/sysdeps/x86_64/Makefile +++ b/sysdeps/x86_64/Makefile @@ -468,7 +468,7 @@ $(cet-built-dso:=.note): %.note: % mv -f $@T $@ common-generated += $(cet-built-dso:$(common-objpfx)%=%.note) -$(objpfx)check-cet.out: $(..)sysdeps/x86/check-cet.awk \ +$(objpfx)check-cet.out: $(..)sysdeps/x86_64/check-cet.awk \ $(cet-built-dso:=.note) LC_ALL=C $(AWK) -f $^ > $@; \ $(evaluate-test) diff --git a/sysdeps/x86/check-cet.awk b/sysdeps/x86_64/check-cet.awk similarity index 100% rename from sysdeps/x86/check-cet.awk rename to sysdeps/x86_64/check-cet.awk From patchwork Tue Jan 9 20:23:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1884636 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=dC12qMRh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T8j8W3zD2z1yPm for ; Wed, 10 Jan 2024 07:24:43 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D720385802E for ; Tue, 9 Jan 2024 20:24:41 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oo1-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) by sourceware.org (Postfix) with ESMTPS id 4E0FA3858422 for ; Tue, 9 Jan 2024 20:23:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E0FA3858422 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4E0FA3858422 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c31 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704831813; cv=none; b=gQ2moa+OoQnS69DonVXNBfrdhqaowa/ZhAG1C844O6fSFoRJ5BUkPrs9K5Og5Gj8vySC2ypX/Mz/T9TAk9Qtd7l3fyfqIAJ/LOhN5hTMLKWcPWQjy8apsC3shM+cK+SKkiXw3nmlr0sSEJnV4y/GTnBMN0feR+WzVunKjdV9FqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704831813; c=relaxed/simple; bh=lOaoQrA9GvSt6cGA1NAI9cmFPAtweFpeyK2mlBsvwVM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=r94XIpanal/wMWgX8mlq3fRZJqgKfJ4SCDd75/sl2JHI0CcLCsynEtDCbI+jICslfvDI/gKlwhLxQxRiwbiLT//W0zWMY1kFXa0IUm37AVQ4Y92SbO0zq5FxiZaogZvOpj3u6a4klqRUJyZwi5Ywf3gKg8d6UaIlc8qwXGJvmME= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-595ac2b6c59so1853814eaf.2 for ; Tue, 09 Jan 2024 12:23:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704831809; x=1705436609; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q0aTtavtYR0aDoT3CAiDljGHrwRnToMDtGmcSD1Zpsw=; b=dC12qMRhiWaYh2GlS8SDcKAGIgFlVtcpzPbYalaLaiKq0OYNt+UErAsNEGSL35YqBm wo/jzzuhhGyo9I3pb/dEYOcdxAX/Bam3tPHVethdb9cB409BsiG19rERDWW883fBUcoW 7ENzw9/1YyPpJNDkgn5xljoR3K+/Cw3/Bpf/mX5d8Vm+tp9jUr4Ggew0mPkRKezH2CrY kbBGfedHpAlshb9+PkL20euhmZ6vxy5zuJSMzMIiK6FsIZONmkoojAwLRXf9CZEzsHA4 QM1xIQtNqxGQSbPU98x3wbc5PrcoakwfpJYD6HFtRbzsxKdToqm0mu3Gl629bv/c9vMr oNCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704831809; x=1705436609; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q0aTtavtYR0aDoT3CAiDljGHrwRnToMDtGmcSD1Zpsw=; b=m38jGQN1ARJLmS7k2HOhTUv4BGTh1pCNIPxnDr+dzfrR8Crhq3hqpePCw0WX++2Qka OSyM7Jdol5Zk883x9U6sr2bnmgchfxsiEOB1HK1juELPhs87u37vz9DTnS1b1EWoX3Tr VnkPZMWjSz0uM7i4hqtD9kXAoJGHNDfSbl2eu8cY8Y0Hag8M35KBSldDT281oM15B8Rq mivBqnZo9JgS1Wof2wwOgpXI5G9l9TyT3ogGGve17yWgbW3cKTZjR/08jJoSpPA368v0 nQekEjq5kEkF3Yj+jLVpte21yiu4bLtkMwl438RNjFHv2XqFAdFXOYUXaISXzkRv0R/u GLDQ== X-Gm-Message-State: AOJu0Yz/ovb/6leqBV4NajCJa15XOvE1dpJfjLiRXezJX78NzEf/cC6H t9r5duHWXV404bHhVCpbnds= X-Google-Smtp-Source: AGHT+IHKPPGUJWVNU+BTmQmkAw39LdWy3okZzlK3wBI3yyXaK9YLc4MC+IJ2hCc9/a/K3iC+RQrkeA== X-Received: by 2002:a05:6358:715:b0:175:ac73:cbb3 with SMTP id e21-20020a056358071500b00175ac73cbb3mr40991rwj.5.1704831809322; Tue, 09 Jan 2024 12:23:29 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.169.119]) by smtp.gmail.com with ESMTPSA id c5-20020a63ef45000000b005ceeeea1816sm2080537pgk.77.2024.01.09.12.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 12:23:29 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id E1183740679; Tue, 9 Jan 2024 12:23:27 -0800 (PST) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: adhemerval.zanella@linaro.org, goldstein.w.n@gmail.com Subject: [PATCH v3 4/4] i386: Remove CET support bits Date: Tue, 9 Jan 2024 12:23:27 -0800 Message-ID: <20240109202327.1565961-5-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240109202327.1565961-1-hjl.tools@gmail.com> References: <20240109202327.1565961-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3024.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org 1. Remove _dl_runtime_resolve_shstk and _dl_runtime_profile_shstk. 2. Move CET offsets from x86 cpu-features-offsets.sym to x86-64 features-offsets.sym. 3. Rename x86 cet-control.h to x86-64 feature-control.h since it is only for x86-64 and also used for PLT rewrite. 4. Add x86-64 ldsodefs.h to include feature-control.h. 5. Change TUNABLE_CALLBACK (set_plt_rewrite) to x86-64 only. 6. Move x86 dl-procruntime.c to x86-64. Reviewed-by: Adhemerval Zanella --- sysdeps/i386/dl-machine.h | 11 +-- sysdeps/i386/dl-trampoline.S | 69 ------------------- sysdeps/unix/sysv/linux/x86_64/dl-cet.h | 2 +- sysdeps/x86/cpu-features-offsets.sym | 2 - sysdeps/x86/cpu-features.c | 4 +- sysdeps/x86/ldsodefs.h | 1 - sysdeps/x86_64/Makefile | 2 +- sysdeps/{x86 => x86_64}/dl-procruntime.c | 2 +- sysdeps/x86_64/dl-trampoline.S | 1 + .../feature-control.h} | 8 +-- sysdeps/x86_64/features-offsets.sym | 6 ++ sysdeps/x86_64/ldsodefs.h | 26 +++++++ 12 files changed, 45 insertions(+), 89 deletions(-) rename sysdeps/{x86 => x86_64}/dl-procruntime.c (97%) rename sysdeps/{x86/cet-control.h => x86_64/feature-control.h} (92%) create mode 100644 sysdeps/x86_64/features-offsets.sym create mode 100644 sysdeps/x86_64/ldsodefs.h diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h index c69ae165ac..fc1ef96587 100644 --- a/sysdeps/i386/dl-machine.h +++ b/sysdeps/i386/dl-machine.h @@ -65,9 +65,6 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[], extern void _dl_runtime_profile (Elf32_Word) attribute_hidden; extern void _dl_runtime_resolve_shstk (Elf32_Word) attribute_hidden; extern void _dl_runtime_profile_shstk (Elf32_Word) attribute_hidden; - /* Check if SHSTK is enabled by kernel. */ - bool shstk_enabled - = (GL(dl_x86_feature_1) & GNU_PROPERTY_X86_FEATURE_1_SHSTK) != 0; if (l->l_info[DT_JMPREL] && lazy) { @@ -95,9 +92,7 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[], #ifdef SHARED if (__glibc_unlikely (profile)) { - got[2] = (shstk_enabled - ? (Elf32_Addr) &_dl_runtime_profile_shstk - : (Elf32_Addr) &_dl_runtime_profile); + got[2] = (Elf32_Addr) &_dl_runtime_profile; if (GLRO(dl_profile) != NULL && _dl_name_match_p (GLRO(dl_profile), l)) @@ -109,9 +104,7 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[], #endif /* This function will get called to fix up the GOT entry indicated by the offset on the stack, and then jump to the resolved address. */ - got[2] = (shstk_enabled - ? (Elf32_Addr) &_dl_runtime_resolve_shstk - : (Elf32_Addr) &_dl_runtime_resolve); + got[2] = (Elf32_Addr) &_dl_runtime_resolve; } return lazy; diff --git a/sysdeps/i386/dl-trampoline.S b/sysdeps/i386/dl-trampoline.S index 2632020145..6c14d463b6 100644 --- a/sysdeps/i386/dl-trampoline.S +++ b/sysdeps/i386/dl-trampoline.S @@ -44,76 +44,7 @@ _dl_runtime_resolve: cfi_endproc .size _dl_runtime_resolve, .-_dl_runtime_resolve -# The SHSTK compatible version. - .text - .globl _dl_runtime_resolve_shstk - .type _dl_runtime_resolve_shstk, @function - cfi_startproc - .align 16 -_dl_runtime_resolve_shstk: - cfi_adjust_cfa_offset (8) - pushl %eax # Preserve registers otherwise clobbered. - cfi_adjust_cfa_offset (4) - pushl %edx - cfi_adjust_cfa_offset (4) - movl 12(%esp), %edx # Copy args pushed by PLT in register. Note - movl 8(%esp), %eax # that `fixup' takes its parameters in regs. - call _dl_fixup # Call resolver. - movl (%esp), %edx # Get register content back. - movl %eax, %ecx # Store the function address. - movl 4(%esp), %eax # Get register content back. - addl $16, %esp # Adjust stack: PLT1 + PLT2 + %eax + %edx - cfi_adjust_cfa_offset (-16) - jmp *%ecx # Jump to function address. - cfi_endproc - .size _dl_runtime_resolve_shstk, .-_dl_runtime_resolve_shstk - #if !defined PROF && defined SHARED -# The SHSTK compatible version. - .globl _dl_runtime_profile_shstk - .type _dl_runtime_profile_shstk, @function - cfi_startproc - .align 16 -_dl_runtime_profile_shstk: - cfi_adjust_cfa_offset (8) - pushl %esp - cfi_adjust_cfa_offset (4) - addl $8, (%esp) # Account for the pushed PLT data - pushl %ebp - cfi_adjust_cfa_offset (4) - pushl %eax # Preserve registers otherwise clobbered. - cfi_adjust_cfa_offset (4) - pushl %ecx - cfi_adjust_cfa_offset (4) - pushl %edx - cfi_adjust_cfa_offset (4) - movl %esp, %ecx - subl $8, %esp - cfi_adjust_cfa_offset (8) - movl $-1, 4(%esp) - leal 4(%esp), %edx - movl %edx, (%esp) - pushl %ecx # Address of the register structure - cfi_adjust_cfa_offset (4) - movl 40(%esp), %ecx # Load return address - movl 36(%esp), %edx # Copy args pushed by PLT in register. Note - movl 32(%esp), %eax # that `fixup' takes its parameters in regs. - call _dl_profile_fixup # Call resolver. - cfi_adjust_cfa_offset (-8) - movl (%esp), %edx - testl %edx, %edx - jns 1f - movl 4(%esp), %edx # Get register content back. - movl %eax, %ecx # Store the function address. - movl 12(%esp), %eax # Get register content back. - # Adjust stack: PLT1 + PLT2 + %esp + %ebp + %eax + %ecx + %edx - # + free. - addl $32, %esp - cfi_adjust_cfa_offset (-32) - jmp *%ecx # Jump to function address. - cfi_endproc - .size _dl_runtime_profile_shstk, .-_dl_runtime_profile_shstk - .globl _dl_runtime_profile .type _dl_runtime_profile, @function cfi_startproc diff --git a/sysdeps/unix/sysv/linux/x86_64/dl-cet.h b/sysdeps/unix/sysv/linux/x86_64/dl-cet.h index 94e9b9aa86..a00c7ee662 100644 --- a/sysdeps/unix/sysv/linux/x86_64/dl-cet.h +++ b/sysdeps/unix/sysv/linux/x86_64/dl-cet.h @@ -17,7 +17,7 @@ #include #include -#include +#include static __always_inline int dl_cet_disable_cet (unsigned int cet_feature) diff --git a/sysdeps/x86/cpu-features-offsets.sym b/sysdeps/x86/cpu-features-offsets.sym index 5429f60632..6a8fd29813 100644 --- a/sysdeps/x86/cpu-features-offsets.sym +++ b/sysdeps/x86/cpu-features-offsets.sym @@ -2,6 +2,4 @@ #include -RTLD_GLOBAL_RO_DL_X86_CPU_FEATURES_OFFSET offsetof (struct rtld_global_ro, _dl_x86_cpu_features) XSAVE_STATE_SIZE_OFFSET offsetof (struct cpu_features, xsave_state_size) -RTLD_GLOBAL_DL_X86_FEATURE_1_OFFSET offsetof (struct rtld_global, _dl_x86_feature_1) diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c index 9ca307f521..46bdaffbc2 100644 --- a/sysdeps/x86/cpu-features.c +++ b/sysdeps/x86/cpu-features.c @@ -27,7 +27,7 @@ extern void TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *) attribute_hidden; -#ifdef SHARED +#if defined SHARED && defined __x86_64__ static void TUNABLE_CALLBACK (set_plt_rewrite) (tunable_val_t *valp) { @@ -1125,8 +1125,10 @@ no_cpuid: #endif #ifdef SHARED +# ifdef __x86_64__ TUNABLE_GET (plt_rewrite, tunable_val_t *, TUNABLE_CALLBACK (set_plt_rewrite)); +# endif #else /* NB: In libc.a, call init_cacheinfo. */ init_cacheinfo (); diff --git a/sysdeps/x86/ldsodefs.h b/sysdeps/x86/ldsodefs.h index b2a6d71513..50dc81c022 100644 --- a/sysdeps/x86/ldsodefs.h +++ b/sysdeps/x86/ldsodefs.h @@ -61,7 +61,6 @@ struct La_x32_retval; struct La_x86_64_retval *, \ const char *) -#include #include_next #endif diff --git a/sysdeps/x86_64/Makefile b/sysdeps/x86_64/Makefile index e8babc9a4e..90f4ecfd26 100644 --- a/sysdeps/x86_64/Makefile +++ b/sysdeps/x86_64/Makefile @@ -10,7 +10,7 @@ LDFLAGS-rtld += -Wl,-z,nomark-plt endif ifeq ($(subdir),csu) -gen-as-const-headers += link-defines.sym +gen-as-const-headers += features-offsets.sym link-defines.sym endif ifeq ($(subdir),gmon) diff --git a/sysdeps/x86/dl-procruntime.c b/sysdeps/x86_64/dl-procruntime.c similarity index 97% rename from sysdeps/x86/dl-procruntime.c rename to sysdeps/x86_64/dl-procruntime.c index 15b3d0d878..7078581778 100644 --- a/sysdeps/x86/dl-procruntime.c +++ b/sysdeps/x86_64/dl-procruntime.c @@ -1,4 +1,4 @@ -/* Data for processor runtime information. x86 version. +/* Data for processor runtime information. x86-64 version. Copyright (C) 2018-2024 Free Software Foundation, Inc. This file is part of the GNU C Library. diff --git a/sysdeps/x86_64/dl-trampoline.S b/sysdeps/x86_64/dl-trampoline.S index 4c1ba5c9af..b2e7e0f69b 100644 --- a/sysdeps/x86_64/dl-trampoline.S +++ b/sysdeps/x86_64/dl-trampoline.S @@ -19,6 +19,7 @@ #include #include #include +#include #include #include diff --git a/sysdeps/x86/cet-control.h b/sysdeps/x86_64/feature-control.h similarity index 92% rename from sysdeps/x86/cet-control.h rename to sysdeps/x86_64/feature-control.h index f09f193e9b..4c8727e844 100644 --- a/sysdeps/x86/cet-control.h +++ b/sysdeps/x86_64/feature-control.h @@ -1,4 +1,4 @@ -/* x86 CET tuning. +/* x86-64 feature tuning. This file is part of the GNU C Library. Copyright (C) 2018-2024 Free Software Foundation, Inc. @@ -16,8 +16,8 @@ License along with the GNU C Library; if not, see . */ -#ifndef _CET_CONTROL_H -#define _CET_CONTROL_H +#ifndef _X86_64_FEATURE_CONTROL_H +#define _X86_64_FEATURE_CONTROL_H /* For each CET feature, IBT and SHSTK, valid control values. */ enum dl_x86_cet_control @@ -50,4 +50,4 @@ struct dl_x86_feature_control enum dl_plt_rewrite_control plt_rewrite : 2; }; -#endif /* cet-control.h */ +#endif /* feature-control.h */ diff --git a/sysdeps/x86_64/features-offsets.sym b/sysdeps/x86_64/features-offsets.sym new file mode 100644 index 0000000000..9e4be3393a --- /dev/null +++ b/sysdeps/x86_64/features-offsets.sym @@ -0,0 +1,6 @@ +#define SHARED 1 + +#include + +RTLD_GLOBAL_RO_DL_X86_CPU_FEATURES_OFFSET offsetof (struct rtld_global_ro, _dl_x86_cpu_features) +RTLD_GLOBAL_DL_X86_FEATURE_1_OFFSET offsetof (struct rtld_global, _dl_x86_feature_1) diff --git a/sysdeps/x86_64/ldsodefs.h b/sysdeps/x86_64/ldsodefs.h new file mode 100644 index 0000000000..0f468ddf5b --- /dev/null +++ b/sysdeps/x86_64/ldsodefs.h @@ -0,0 +1,26 @@ +/* Run-time dynamic linker data structures for loaded ELF shared objects. + x86-64 version. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _X86_64_LDSODEFS_H +#define _X86_64_LDSODEFS_H 1 + +#include +#include_next + +#endif