From patchwork Sun Jul 21 23:04:20 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: 1962976 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=a9jVHaBB; 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 4WRzWp5Frcz1yYm for ; Mon, 22 Jul 2024 09:04:54 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6AECF385841D for ; Sun, 21 Jul 2024 23:04:44 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by sourceware.org (Postfix) with ESMTPS id BB5FB385DDE3 for ; Sun, 21 Jul 2024 23:04:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BB5FB385DDE3 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 BB5FB385DDE3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f2f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721603069; cv=none; b=EoR8j1EhY/h2PL/vSlMD/WJdd3+Wm0lAe9946KdI8VBptKBDHFfTYMVIuFDkIg3y1m1Lbp9YQwzD8PQJhGjPbJ0IVfy6vX1ju+SYTY2EjfbkUxU0CThvGoWTnFRy3AVz6NLJOioBEAaPWNMHEHYxZQ+RpObv16Q6Axmv5twtWDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721603069; c=relaxed/simple; bh=uY5hD1OXpD3LodCJoEp0mL6RskrtER1loMUYlhQenHM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TJGyTDzzu0deN86S2U0MZb7vy35HzGSZXtQhkjUIdlqek6sCV/XJ2+hSgoqAQS8/6jXMLCTEUQAPaVn6ygP/BqQYh4gWCHgGUpFOl8wON2q3ZD8A5u3oB4+PkI+s0wT+ragieUAAKW1dQGYHZt5LscsRiOvzREnztHYxLk8zdzg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf2f.google.com with SMTP id 6a1803df08f44-6b7a3e468a9so21157396d6.1 for ; Sun, 21 Jul 2024 16:04:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721603065; x=1722207865; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=SnftcRE4VWWac4an9EIIVxkUSlQ++ZGf5SreY6GSNJI=; b=a9jVHaBBTqPc7jzi7e1FSKgi+ur+q7V0fMe1P92pg0je8uJmvxvPd13kQ862FKNjGR +ZbrfixwtsmdgFWKJDC47c/q32/+tAvepaNN0tZ5owa95uccwKKlOu88yc1uK9HAukrF BarlLcIn5D+gU/gppobs0p3xjO4ykrq6cZ/583K+FRQL3DFGzi4MoSU3oMhaGvktYOob itVn72UenozpVIPM17YuIupZzmCEkukuszRNNzv4hxo/hseoUroXqbHKsyiPu1vVLMXb nIo1ZJlPe+FAZKGLx+HC9xyruN3Uc3a68k+O1jGvnrutOlXvpd7+Dhxeo0zfPr0f3cl2 Vqyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721603065; x=1722207865; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SnftcRE4VWWac4an9EIIVxkUSlQ++ZGf5SreY6GSNJI=; b=eycz0FdbVk5s73cMsOfnQFImc65UrmC3Cm0kQeOiqQpRCXAoEYC0nyL84FRFK5U6Fn PjBH5wjcD7itXoXBpdoKBjREmYgIW6VuSLqCoSJQKQzNscmTCgcu241vKJiXSg1f8+PL OPpogbn7fHN/vaqF03fCCFQ9Kbc5oJXqtTETloDCCV0Ojion/7yzHzyaSX6d9586jJM0 l5CJvtaZ/BiXRXZ5X4pi1lu4ncvzPtPrkpyiuhjXfWxNKkQyQBcABG6ZzgXLnh09bdXq mgmMZcea/JTU+/SPjKYGirU5V8C7TF2z0s8IcH1elVOrkxxsLXsPdUTnNGXXr5pP0yZr NkCw== X-Gm-Message-State: AOJu0YxxJ3l0Snfnn7J9jYb26Y/dluAIlbllusjcxSxI3WqqBHpQRnsT Llz2YEa00GhHAivB3BXsl6QiMplwDzYM8YvBQloV5Wzcgb052hmQy1iLmd8ndiE= X-Google-Smtp-Source: AGHT+IGxORN9NkZgJtxNfsym3cLCrgMk2By9sIig7em5L8+dr1cVSDwqPNipE/da0DW5KfpT2fRkhw== X-Received: by 2002:a05:6214:c63:b0:6b5:e74a:8ad3 with SMTP id 6a1803df08f44-6b96104bb6emr64954556d6.13.1721603064930; Sun, 21 Jul 2024 16:04:24 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.58.27.191]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b7ac7dc47esm29877716d6.43.2024.07.21.16.04.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jul 2024 16:04:24 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 5A2ACC00BC for ; Sun, 21 Jul 2024 16:04:20 -0700 (PDT) From: "H.J. Lu" To: libc-alpha@sourceware.org Subject: [PATCH v2] x32/cet: Enable shadow stack during startup for Linux 6.10 Date: Sun, 21 Jul 2024 16:04:20 -0700 Message-ID: <20240721230420.3684982-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Spam-Status: No, score=-3021.2 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 Enable 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. --- sysdeps/unix/sysv/linux/x86_64/x32/arch-syscall.h | 1 + sysdeps/unix/sysv/linux/x86_64/x32/fixup-asm-unistd.h | 4 ++++ sysdeps/x86_64/x32/dl-machine.h | 7 +++++-- 3 files changed, 10 insertions(+), 2 deletions(-) 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 diff --git a/sysdeps/x86_64/x32/dl-machine.h b/sysdeps/x86_64/x32/dl-machine.h index c35cee9261..3eb59bde7c 100644 --- a/sysdeps/x86_64/x32/dl-machine.h +++ b/sysdeps/x86_64/x32/dl-machine.h @@ -45,13 +45,16 @@ _start:\n\ _dl_start_user:\n\ # Save the user entry point address in %r12.\n\ movl %eax, %r12d\n\ + # Save %rsp value in %r13.\n\ + movl %esp, %r13d\n\ +"\ + RTLD_START_ENABLE_X86_FEATURES \ +"\ # Read the original argument count.\n\ movl (%rsp), %edx\n\ # Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env)\n\ # argc -> rsi\n\ movl %edx, %esi\n\ - # Save %rsp value in %r13.\n\ - movl %esp, %r13d\n\ # And align stack for the _dl_init call.\n\ and $-16, %esp\n\ # _dl_loaded -> rdi\n\