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: 83691 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 153BF3857C5E for ; Tue, 9 Jan 2024 20:24:50 +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+patchwork=sourceware.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