From patchwork Tue Jan 9 19:30:39 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: 83679 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 8CB56385DC27 for ; Tue, 9 Jan 2024 19:31:26 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id AFD74385842F for ; Tue, 9 Jan 2024 19:30:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AFD74385842F 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 AFD74385842F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704828648; cv=none; b=QoYdSKLT0QAFMXnRcA4jkiP9Rt3N+pYwAuNf4RJ25kL2ZorrUexzKtw7UGtzX3USk5Wk5xo+HnyACJlX4ABqPczt4JjJxpltU5iKWZT/uq12sseSq0xCWnZH+PBxWywMRcNwGY2iwzoqWqI1fJ32GjgzzGU9DGlf8IUG1Fp5YI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704828648; c=relaxed/simple; bh=VzQSm+uImmRP3litAItMF9qjw1tn9X/4NNtBFiZGnSc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=p4IKCY4SivPNaEMB7NAFpFM2s1T6lzr9e+mnx4jeD4+Z/7kldqMpDygVQK9FEhSChJIDFRboBkNwQkz/wVaRQNkYfjHd2DN2Mr+e6BTngQQwPMeSOXjcR91ZMQf3nKFj9sxa2TF/NYxJbmJuEQ8V21Qk0bvbpeUaOEzV8BAabZ8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1d3e8a51e6bso26884795ad.3 for ; Tue, 09 Jan 2024 11:30:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704828644; x=1705433444; 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=U2yt2VhxmMHBPCFxLMh/zvO20Iaoo8z8hJXUKxV2NWo=; b=SWK59VGPXcv1mwHbmVVVG0XMjP5KFhZ2jmIFDLgwnyFWPwDwlFzZGSo+Fn+Ovtga8b MMH1S8lTxwR6wh0v6Mz1bkQoROK389h9P6K/RI5O3QLSKhKx9xMTh5ZiFXTT3xsckrnL yw8oHSnQVp0zcazH+ArNO7EQbsItvpwCkL8KuMLc56/uprNFCPX1VbbmcLe/snCQ6TXM /fBf2ZAbH6ANfmNndnEWvR7z92tVomQNrt1fVRleaAJumeWFahOonfC4CDg7y26OV9ZY Cfj+fpDOJEQq7hxkF0lq6157Tnii5JVRc7VU+t+s5BQs3VGkO2Ll4o7pCjHP4jHbTWhB fXog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704828644; x=1705433444; 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=U2yt2VhxmMHBPCFxLMh/zvO20Iaoo8z8hJXUKxV2NWo=; b=MplTVpd5Xn+PLh1GOau8/mkqzIlAle1zpa8yU712gU+ASiiHHpA2yYWHcsParqAJMx LI/kq0AuOBjKSISofo0MPeLQNhZ7IVZixXWjlEUigp7aiVSrKUPmROQTbGw3OGBBD3k9 b5zzsj+9hJuPJ4/E97vc2qs/YMpLh925DkN3dxxbzO3gn+mIP9YbSp5faDpAspuvjURM qKG7w4H/XFPkpOOyhp/zNVvgxXPWw2+zo3OpHA6yOICpGluJDrkZGk1yu8M9dBfGs4Ef Gzv6Rgjwl2hAA7zN28nWGdoRN05QEMUyKNevVhE4cehLJqTZMleUJrgoy/AjosexeUuU h5iw== X-Gm-Message-State: AOJu0YwBFad1pPUcXMw+BmgchI9Dfgywwz7RV7TVjtopLe72T/9OK1ly HJVGfOEj1dMTLFS2IoiT3Do= X-Google-Smtp-Source: AGHT+IHhF0frR6GYpiitsx7Lw+XNiuM0IhMmpHI9RKZyuEfCkS1+4C93KpPzZLmnRJ0EtHNoSt2ZlQ== X-Received: by 2002:a17:902:7c92:b0:1d3:e135:7891 with SMTP id y18-20020a1709027c9200b001d3e1357891mr5885726pll.102.1704828643550; Tue, 09 Jan 2024 11:30:43 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.169.119]) by smtp.gmail.com with ESMTPSA id w10-20020a170902904a00b001d05bb77b43sm2154913plz.19.2024.01.09.11.30.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 11:30:43 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 1330E740677; Tue, 9 Jan 2024 11:30:42 -0800 (PST) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: adhemerval.zanella@linaro.org, goldstein.w.n@gmail.com Subject: [PATCH 2/4] x86-64/cet: Move dl-cet.[ch] to x86_64 directories Date: Tue, 9 Jan 2024 11:30:39 -0800 Message-ID: <20240109193041.3987157-3-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240109193041.3987157-1-hjl.tools@gmail.com> References: <20240109193041.3987157-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, 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 | 0 3 files changed, 46 insertions(+), 64 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/x86/dl-cet.h rename sysdeps/{x86 => x86_64}/dl-cet.c (100%) 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 100% rename from sysdeps/x86/dl-cet.c rename to sysdeps/x86_64/dl-cet.c