From patchwork Tue Jan 9 20:06:16 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: 1884629 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=Mn0rHzxB; 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 4T8hlt12lsz1yPm for ; Wed, 10 Jan 2024 07:06:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2AC6E3857BB2 for ; Tue, 9 Jan 2024 20:06:48 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by sourceware.org (Postfix) with ESMTPS id 3F0983858C39 for ; Tue, 9 Jan 2024 20:06:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3F0983858C39 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 3F0983858C39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1030 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704830783; cv=none; b=HfZyc7GtPu0vqnnCGRpuF/8NwMZsn0VW+aGvm5E8aNMubA4GcNbFsltYpqjXJ/MtomnfYNOA6aMrE6J7/j3Ddcc/YlPnvH6lTD6xkTaDvGl0xLpoyFoprUUQCUQr5GG7YFwyyb76QA5qDOiNIt2AqASmeIG7f0ZJRF9EjdSodCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704830783; c=relaxed/simple; bh=eY9o3A/Ua6+L9R5xE4zQrNxqilQpakr/XNZkB5NJjco=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Lv/tbxrjLj/Go5Z9Q83GLITLOZPRelQWyie6bRbbsH2W5LwVIudpd0k/auMWPAPcjMG6I9i70A+OUyK2KaZSbR0bMcOTw5c4MbI4JkpsMzYHiXPwQq22A5Q9G4R3quts+cwdDB/ZeGls+e6JDJCVIDzE1nidCs5wS121y0x5J1o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-28c2b8d6f2aso2230814a91.2 for ; Tue, 09 Jan 2024 12:06:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704830780; x=1705435580; 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=Mn0rHzxBYmOq35XK5svSI9i6CEfkAe5DNvnSheGMJv3JC3g7Vb+4vfntHGnq085/D0 drnX0yPqha5iElC0/Ew0tZ0uRSO8BKfsz06RwWSIZXNHYMLfweW/a8NbxxChyFAA6qor v40g1kLbljpyOKsaJ4nKEUaP3vwdsjlyWe+kWWD5W/YpaFor8En8h4chMqPU3cnxodb7 MvuSRnKfvGLu8pwpCGFLwPeZBWmEIXJ9eNECIN0wwYqVI29g3TxPfvoj2La/Ej/Y18q+ KRkN0JOGVfD4R2vdLENtEOiioUZH4jze1Ua1v2z06zioOF1kng+1RUoZxN+dCUKkdnWJ KzWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704830780; x=1705435580; 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=hRQ7A7TsHyVxSwY3IN5KEVi0sV/XR3qjXJej8ojHk5s7u30U5YwLwOq2WNzot9ar5f Q/kT/zTKOWIAJhvZ5KV2W1qSQQDBU9PiKqf7tBSr3AITu2OGMMq/+COM3k3Qau/2jxZC iAVNHoHTSSrO2SEMoUdXZHkrA320oCTQGrYHmLBG9RyANk/u7tG7Q+rVjZMTRz+7cWa+ Tmf2G3Q8sq90V5gsYAeWwpddVU9hSNkYjmYqNZjAqNq+8n9Y3Ae4jEffukmN/IW8qm1E Ibcjn43gMYAfUm0SsGzm0hXh39d5HKPYgnhA7l65AnpYD/J5edt3NbzLH/8lRjjppqO+ L5zg== X-Gm-Message-State: AOJu0YxhUeLMHJe6+coG8ozugu8GH7gDIude4wscTBMXgxrWkGGx7rpp BVXG4QnuhaTgYPROl7zmI1o= X-Google-Smtp-Source: AGHT+IHlD/qO8tGbkcrrequphqbE+bWk5fe3X8IqFL8JJvOf3xU5m1BnyJwgEqkPib4E+GSUlrX4ng== X-Received: by 2002:a17:90a:ee81:b0:28a:c749:23cf with SMTP id i1-20020a17090aee8100b0028ac74923cfmr2522123pjz.75.1704830780119; Tue, 09 Jan 2024 12:06:20 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.56.169.119]) by smtp.gmail.com with ESMTPSA id ph3-20020a17090b3bc300b0028d0c8c9d37sm8834945pjb.22.2024.01.09.12.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 12:06:19 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id CA799740677; Tue, 9 Jan 2024 12:06:18 -0800 (PST) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: adhemerval.zanella@linaro.org, goldstein.w.n@gmail.com Subject: [PATCH v2 2/4] x86-64/cet: Move dl-cet.[ch] to x86_64 directories Date: Tue, 9 Jan 2024 12:06:16 -0800 Message-ID: <20240109200618.1508659-3-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240109200618.1508659-1-hjl.tools@gmail.com> References: <20240109200618.1508659-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+incoming=patchwork.ozlabs.org@sourceware.org Since CET is only enabled for x86-64, move dl-cet.[ch] to x86_64 directories. --- 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