From patchwork Tue Jul 23 00:47:22 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: 1963500 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=Hs5OFoRG; 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 4WSdmk2MLmz1yYm for ; Tue, 23 Jul 2024 10:48:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 77ABE386103E for ; Tue, 23 Jul 2024 00:48:20 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by sourceware.org (Postfix) with ESMTPS id 604953860776 for ; Tue, 23 Jul 2024 00:47:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 604953860776 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 604953860776 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f29 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721695651; cv=none; b=U+q4fIRge4DtQXS3L4eZHqNAYOnW/TFQsPUiUuwifdMgfwi/1OgmQQIJt0fsicqNOr8gFsbfs+cmxRAMhjrKnjByp29N3IYSbIbrS+B4zxEBESRv/4o8YgQqdepwqzhQ06tVai+r2xVUcjhefkwXppDZU8hXL8Ea272BYVI/FtQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721695651; c=relaxed/simple; bh=Ce30f58KNSkjwxFxMrkUEwDCu6FmbE1WR9+ORAKsvo8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=NNNMPHb9GPaopkexUtrbf1HzihZI5zCeOwJeSubAqeOcw6SMlwHxjz4/Cm/DtV9aPvM0jzx0sVTMjAdnqxY1uvlebSTewXpobFIf6IwlExzqj1DiYyqfy7aba0SfpVw6myhcSyyAx7CHM02lYCE4eQY9kSPzAa6UiclK/eQlfRY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf29.google.com with SMTP id 6a1803df08f44-6b797fb1c4aso38501326d6.2 for ; Mon, 22 Jul 2024 17:47:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721695648; x=1722300448; 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=CM/I9rjzdvPVk8LARLU+XCnVXbpKkFfboyDfD+w8mB0=; b=Hs5OFoRGfIKwIF1DgUchoRrkNkATQz9DlyjjmDeNam7ZwldxYvbe61Qn8GcNe5a2Yh d9n0XQdiEdSKwaUCr4l4ZQBgAeQO/7LQATK9TPxgmNLWGuB4l1Gc3cOugSIpRXO9DCji CcDYIOPgoI7cLaUkhqWGHVA0yjEqCdLSXSH+ztsT+9fIdKnQ5CrG196VRzGUx8tAEW2N akx0zM8u9n25ONjtCWPYv84/2u1okkgABJCadBgvELTXtjYmnX2u0VsoTSwmqR9tnqs7 Itxc33y9W+r3yFEzo6jvd2hBMMpPajQKyAFdbgu9QLNIFmPnY1puU8xwNrQHKBNyhSgN KEYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721695648; x=1722300448; 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=CM/I9rjzdvPVk8LARLU+XCnVXbpKkFfboyDfD+w8mB0=; b=KqRWIe5RQ1HfDrTXc7MievdQFYAB0TRG8mmUpYCabWyfvYMvWE63YxyuqOVsCR5lJx 1CDGb0oQa0WdBzOwjFnG5BgxHI1At5lBG6fgx+CE1vZXVPw/PZZgM0QE8JTZfypjAQiu f3E8ymRJhZX0PhUIzN+w2ObB5S88XEj17WRt7OcePRVDsXt4kTUcY9fx8pA0mfsGialZ CSt9pj4qYoOEansnv0U+4xFCUpKwtIJepkv0NY4oJGywrjPkgiyo/l6CcG/QkMLAzihG J8OYTjWH2ejD4fszXw/ghwvIoYX6AwFx9E/FjPhvg6yITVgSSjkBywigpBbNLIeZE+xx BLdw== X-Gm-Message-State: AOJu0Yy/0NHB0/7xFDoWcLdm/dKBy9vl1bJH0Mh4/qXgtDSBd6KGpJk8 eYrg6gZjaI4FECgm6vMvDvnesIuDjQlhhBb+lemTZRw/lck+b5vg X-Google-Smtp-Source: AGHT+IG+k5Z1nSQk5ptf77tSNVNb6NMLyyBEghlTkxm6ptfnOSY3bUu0DdG+bOK13Ktl6O4qEd9HrQ== X-Received: by 2002:a05:6214:c46:b0:6b2:b4d2:984d with SMTP id 6a1803df08f44-6b94f0124a9mr118481756d6.15.1721695648398; Mon, 22 Jul 2024 17:47:28 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.58.142.192]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b7ac7bd5d6sm40736506d6.22.2024.07.22.17.47.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 17:47:27 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 1415AC01C2; Mon, 22 Jul 2024 17:47:23 -0700 (PDT) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: goldstein.w.n@gmail.com Subject: [PATCH v3 2/2] x32/cet: Support shadow stack during startup for Linux 6.10 Date: Mon, 22 Jul 2024 17:47:22 -0700 Message-ID: <20240723004722.2337170-3-hjl.tools@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240723004722.2337170-1-hjl.tools@gmail.com> References: <20240723004722.2337170-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3020.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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~incoming=patchwork.ozlabs.org@sourceware.org Use RXX_LP in RTLD_START_ENABLE_X86_FEATURES. Support shadow stack during startup for Linux 6.10: commit 2883f01ec37dd8668e7222dfdb5980c86fdfe277 Author: H.J. Lu Date: Fri Mar 15 07:04:33 2024 -0700 x86/shstk: Enable shadow stacks for x32 1. Add shadow stack support to x32 signal. 2. Use the 64-bit map_shadow_stack syscall for x32. 3. Set up shadow stack for x32. Add the map_shadow_stack system call to and regenerate arch-syscall.h. Tested on Intel Tiger Lake with CET enabled x32. There are no regressions with CET enabled x86-64. There are no changes in CET enabled x86-64 _dl_start_user. Signed-off-by: H.J. Lu Reviewed-by: Noah Goldstein --- sysdeps/unix/sysv/linux/x86_64/dl-cet.h | 6 +++--- sysdeps/unix/sysv/linux/x86_64/x32/arch-syscall.h | 1 + sysdeps/unix/sysv/linux/x86_64/x32/fixup-asm-unistd.h | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sysdeps/unix/sysv/linux/x86_64/dl-cet.h b/sysdeps/unix/sysv/linux/x86_64/dl-cet.h index 1fe3133406..b4f7e6c9cd 100644 --- a/sysdeps/unix/sysv/linux/x86_64/dl-cet.h +++ b/sysdeps/unix/sysv/linux/x86_64/dl-cet.h @@ -92,9 +92,9 @@ dl_cet_ibt_enabled (void) # Pass GL(dl_x86_feature_1) to _dl_cet_setup_features.\n\ movl %edx, %edi\n\ # Align stack for the _dl_cet_setup_features call.\n\ - andq $-16, %rsp\n\ + and $-16, %" RSP_LP "\n\ call _dl_cet_setup_features\n\ # Restore %rax and %rsp from %r12 and %r13.\n\ - movq %r12, %rax\n\ - movq %r13, %rsp\n\ + mov %" R12_LP ", %" RAX_LP "\n\ + mov %" R13_LP ", %" RSP_LP "\n\ " diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/arch-syscall.h b/sysdeps/unix/sysv/linux/x86_64/x32/arch-syscall.h index 3040a47d72..df3e22236d 100644 --- a/sysdeps/unix/sysv/linux/x86_64/x32/arch-syscall.h +++ b/sysdeps/unix/sysv/linux/x86_64/x32/arch-syscall.h @@ -155,6 +155,7 @@ #define __NR_lsm_set_self_attr 1073742284 #define __NR_lstat 1073741830 #define __NR_madvise 1073741852 +#define __NR_map_shadow_stack 1073742277 #define __NR_mbind 1073742061 #define __NR_membarrier 1073742148 #define __NR_memfd_create 1073742143 diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/fixup-asm-unistd.h b/sysdeps/unix/sysv/linux/x86_64/x32/fixup-asm-unistd.h index 98124169e6..47fa8af4ce 100644 --- a/sysdeps/unix/sysv/linux/x86_64/x32/fixup-asm-unistd.h +++ b/sysdeps/unix/sysv/linux/x86_64/x32/fixup-asm-unistd.h @@ -15,6 +15,10 @@ License along with the GNU C Library; if not, see . */ +#ifndef __NR_map_shadow_stack +# define __NR_map_shadow_stack 1073742277 +#endif + /* X32 uses the same 64-bit syscall interface for set_thread_area. */ #ifndef __NR_set_thread_area # define __NR_set_thread_area 1073742029