From patchwork Wed Jun 19 21:00:32 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: 1949806 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=nQ0wFwH/; 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 4W4GHX06BDz20XW for ; Thu, 20 Jun 2024 07:00:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 413383886C40 for ; Wed, 19 Jun 2024 21:00:54 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by sourceware.org (Postfix) with ESMTPS id CA0B53858C41 for ; Wed, 19 Jun 2024 21:00:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CA0B53858C41 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 CA0B53858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::731 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718830840; cv=none; b=nBol1U3FC3zcGm86SOmwd5YWSmtyuwCRct0QhEV94bh37IgvsM5iOpe2+c4AZ7Sqle8NUdKhTBBTjVjL5vYle9C3SZB+MDbo7xhBIjvdj49SAZ7IE9YJUCrK2uGkve8s6PWdSZSfNr6X+FwtVY0XqDHI1UnE8ib09V7IIUkBPD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718830840; c=relaxed/simple; bh=AlCmeihB0dXwu551X/AFPlFPLrGilCNbIXm+AxhtvtM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=J3u5hiD9r7pkAKAUnBeJ7IxQ1EB1FSFZnb6N0q1IChTovBM0Mf6SRX03D30xUUs1mhV0/bujhywhnV6Mrl9ZTIsc3Palo3riSV0ymZLgK34LBXzFWEscvFgs2PE2tMIxkOXr/U/715z9Z/zOTeVkk8YsaUXdT+Ln8lDxM2AZ79E= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-79767180a15so13237685a.1 for ; Wed, 19 Jun 2024 14:00:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718830838; x=1719435638; 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=RL/dWFrmRefGL6OTEEugYjAIvHmmQt9ztFlpyHNASNA=; b=nQ0wFwH/JSm3NvBiB4iXXMROkS5X1cxRpZC+mkFQ0ZaE60ohrOBMayhBzHCI5PEZF6 c5KbdNCQe4V9f4GrPWiw+xhjhyImN9opVOYPCtrrA7joMiVHrwgFR5VO1cCeKHPwat46 k2FxXh1CrVUjYAdu9XjwpNpppHxsjUF7PwD6mUHkrf5eEEez7Y2M3rorwy6CVPUU3igy 0atEFR3hXrenlirxom8E2d4Mbo78TB04Zy2cCzOihNldMBSrjABu4PfpwRXkN6lPUQuN FmczkAJjNyKO6vaszmC5SDn/jjHzqPNEgKoFzkxekE8xUtCxRoRAY+SLC/fppvKhZq9j 1dmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718830838; x=1719435638; 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=RL/dWFrmRefGL6OTEEugYjAIvHmmQt9ztFlpyHNASNA=; b=fXPsD0t8zM2+sfpHcnZ6b1l5B0lngJ5GYOVAMuc+9KxFgNLqo2HrN85y+bhjhed1i2 llmKcSRcAgaqajKeKH7KyxRXLBpB7REErGy2QJwdtaLRBGarWEbT/7ea+Kt4+L/7FB1T 9blVJHqjJQC9J/8jXI+goSgX/b9YSm7TksLUwitA7gMG6sK/5p74aSFcf0DnkyzUIGCF yM/5TEzymSpk1gY5aQznMPAeahfexwA1C2D9BJrkJnhrhFleLLSu6ABKlA7fa1o+dzLn 22HM55n+26il9tRPCr9Ak2bl3Ol4AkNSlUWQ80r3tzbfC7LQu/SKqPytZ0RgPsmOHP2P EMNQ== X-Gm-Message-State: AOJu0YwGP90ennyeMU++moo9DjotvdPMJ1XIftC0xbISgBLc6C+P81ql 33jyNPl/6x6LV0QA+ErBu2dECMOh35SzjYt0DkJHkbwY4A+8nboIsGrli17so0a4rg== X-Google-Smtp-Source: AGHT+IEzNHc3zJgFkCC3BMoQkLMLZet9v/XDNV2SuAt7Q9OagMENUmp8s3yC4e5LYTEgpiQObr8RrA== X-Received: by 2002:a05:620a:19a6:b0:795:60b9:fd8b with SMTP id af79cd13be357-79bb3e5b706mr445263385a.37.1718830837981; Wed, 19 Jun 2024 14:00:37 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.58.142.196]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b2a5bf55f8sm81113926d6.15.2024.06.19.14.00.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jun 2024 14:00:37 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id CFC91C0153 for ; Wed, 19 Jun 2024 14:00:32 -0700 (PDT) From: "H.J. Lu" To: libc-alpha@sourceware.org Subject: [PATCH] x32/cet: Enable shadow stack during startup for Linux 6.10-rc4 Date: Wed, 19 Jun 2024 14:00:32 -0700 Message-ID: <20240619210032.2141424-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Spam-Status: No, score=-3019.6 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_BARRACUDACENTRAL, 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 Enable shadow stack during startup for Linux 6.10-rc4: 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\