From patchwork Wed Dec 6 17:19:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1872904 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=elEkEtex; 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 4Slkhv65GZz23nD for ; Thu, 7 Dec 2023 04:21:35 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 39AC2386100C for ; Wed, 6 Dec 2023 17:21:27 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 66F45385840C for ; Wed, 6 Dec 2023 17:20:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 66F45385840C 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 66F45385840C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701883217; cv=none; b=eMDuEgRcaIxFRf4kL1Wn1i5Hxvt0b+M5Dlci/WmK79jIsInuse7re9hYXdwluffPvtZehgSiFIaKarDsKCgHfzBjiTPKDBSMVXSepw/1ZDFBvvr5kVsnFAwtK/FGMCbyr/X7ULvtp7wcDjy+odS1kZbsceq9ZnbCBIoXOmeIqv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701883217; c=relaxed/simple; bh=deFYwnx7KfgvCTJ+z6zcdr1XwG/yWR4L/YEp8Qg84A8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=LlIBpmLK7U2OtWRlJrx3ak4l+JYq2vOOeStaD/GHA2/Vs/TgESPE5dfi05iMHD/T2e44r1iYllSpIg2pzr7Jga80fyV9yyfSRgXqV4gy2rC51eIuNoMpeU2t/2M+1bdYT+swkaFuXktVN6fijH1yPwcQgCbx3rp22CzvYRkgrzQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6ce972ac39dso47717b3a.3 for ; Wed, 06 Dec 2023 09:20:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701883212; x=1702488012; 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=P3qExcyLMx22FpOGhd0HGApIlxD0z1QRLqYTfzf8yyI=; b=elEkEtexcTqWG4VL3BXiI9wqq1YPG95jjgu+0Z0xXYQzAbljcqfTC0r6ASCpkCP5Sj yjlj7XdOxUihmdNYKngtTcsyMjQLE1/39iOzYwsOPF8dCFY+no9N55msmbbRGLHQXFer CZGSq67k1ZzfF5bCBjNaPP3/vV/cfYtbwPzy5Xfocd1be+xCkh2UlnglPX8oss1j9Wvg Qt+0vLOwSv+9X8MQ/zN36WtSISpskhjtrxFjLPxVRuwyO+y8v7dAEWr+++QDRDuMMayx ySGdTca6+wMRLRWnQrZY42Ib8GdjIf0Yhx0AtkbxlU5jnRiAtboBeMPXX1dnqqsQTEfM u2vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701883212; x=1702488012; 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=P3qExcyLMx22FpOGhd0HGApIlxD0z1QRLqYTfzf8yyI=; b=Xd+TL9yyx6FypVPTwQv6w6iVsBUv21bzxwa3r5r+Md0qu33LZuvhJOQDsg04OV17Tj LbCvPSwBrYQ6UcFuoB32iKqe5pxcG3dYbHtJqYeEHAXBMJHDDwtXlV0HOjsa162lJkOg 3/ryVGUPgZeOJaUXRuf1jusdyCYmwsMJ06TX5SlF7ulCVpNkRbS7PupbVBY/jNfjzHYv A+naFlSeDuJf5Da2aS7vFvVz+H9FhZ6d3ROd93oLwDN9vICiagBEffccfFReBjlYCtKk W6ZnFsMl71IRUwzgW52KFEs5PkEfL7nqTeqkiJOPZYlZPCgbFP34bAvceycKlUJIOY/A Ar2g== X-Gm-Message-State: AOJu0YxpD3mFMlAdgOnR+V7/YvKrbN91NT/CVvYj6kaokJIBR84P0QI+ iHNEIeDJAbP5gVm1/XUn8aPPM/GCXsg= X-Google-Smtp-Source: AGHT+IGEg/2d/x+BTsSwly/O5O7X0J4wzmSheNUV1C6s2AIWTLaTFQouwR9oFdHcv1uPeUbzNS9fKQ== X-Received: by 2002:a05:6a20:3d27:b0:18b:d823:5362 with SMTP id y39-20020a056a203d2700b0018bd8235362mr1093286pzi.48.1701883212039; Wed, 06 Dec 2023 09:20:12 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.59.161.253]) by smtp.gmail.com with ESMTPSA id p21-20020a056a000b5500b006cea1e12564sm234388pfo.81.2023.12.06.09.20.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 09:20:11 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 69C5174062C; Wed, 6 Dec 2023 09:20:10 -0800 (PST) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: rick.p.edgecombe@intel.com Subject: [PATCH 03/17] x86/cet: Don't assume that SHSTK implies IBT Date: Wed, 6 Dec 2023 09:19:56 -0800 Message-ID: <20231206172010.1023415-4-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231206172010.1023415-1-hjl.tools@gmail.com> References: <20231206172010.1023415-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3024.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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 shadow stack (SHSTK) is enabled in the Linux kernel without enabling indirect branch tracking (IBT), don't assume that SHSTK implies IBT. Use "CPU_FEATURE_ACTIVE (IBT)" to check if IBT is active and "CPU_FEATURE_ACTIVE (SHSTK)" to check if SHSTK is active. --- sysdeps/x86/Makefile | 1 - sysdeps/x86/tst-cet-legacy-10.c | 6 +++--- sysdeps/x86/tst-cet-legacy-8.c | 15 ++++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile index 917c26f116..ea45aad34c 100644 --- a/sysdeps/x86/Makefile +++ b/sysdeps/x86/Makefile @@ -165,7 +165,6 @@ CFLAGS-tst-cet-legacy-mod-6a.c += -fcf-protection=branch CFLAGS-tst-cet-legacy-mod-6b.c += -fcf-protection CFLAGS-tst-cet-legacy-mod-6c.c += -fcf-protection CFLAGS-tst-cet-legacy-7.c += -fcf-protection=none -CFLAGS-tst-cet-legacy-8.c += -mshstk CFLAGS-tst-cet-legacy-10.c += -mshstk CFLAGS-tst-cet-legacy-10-static.c += -mshstk diff --git a/sysdeps/x86/tst-cet-legacy-10.c b/sysdeps/x86/tst-cet-legacy-10.c index a85cdc3171..ae2c34de3e 100644 --- a/sysdeps/x86/tst-cet-legacy-10.c +++ b/sysdeps/x86/tst-cet-legacy-10.c @@ -21,19 +21,19 @@ #include #include -/* Check that CPU_FEATURE_ACTIVE on IBT and SHSTK matches _get_ssp. */ +/* Check that CPU_FEATURE_ACTIVE on SHSTK matches _get_ssp. */ static int do_test (void) { if (_get_ssp () != 0) { - if (CPU_FEATURE_ACTIVE (IBT) && CPU_FEATURE_ACTIVE (SHSTK)) + if (CPU_FEATURE_ACTIVE (SHSTK)) return EXIT_SUCCESS; } else { - if (!CPU_FEATURE_ACTIVE (IBT) && !CPU_FEATURE_ACTIVE (SHSTK)) + if (!CPU_FEATURE_ACTIVE (SHSTK)) return EXIT_SUCCESS; } diff --git a/sysdeps/x86/tst-cet-legacy-8.c b/sysdeps/x86/tst-cet-legacy-8.c index 5d8d9ba7dc..77d77a5408 100644 --- a/sysdeps/x86/tst-cet-legacy-8.c +++ b/sysdeps/x86/tst-cet-legacy-8.c @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include #include @@ -29,11 +29,6 @@ static int do_test (void) { - /* NB: This test should trigger SIGSEGV on CET platforms. If SHSTK - is disabled, assuming IBT is also disabled. */ - if (_get_ssp () == 0) - return EXIT_UNSUPPORTED; - void (*funcp) (void); funcp = xmmap (NULL, 0x1000, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1); @@ -41,8 +36,14 @@ do_test (void) /* Write RET instruction. */ *(char *) funcp = 0xc3; funcp (); + + /* NB: This test should trigger SIGSEGV when IBT is active. We should + reach here if IBT isn't active. */ + if (!CPU_FEATURE_ACTIVE (IBT)) + return EXIT_UNSUPPORTED; + return EXIT_FAILURE; } -#define EXPECTED_SIGNAL (_get_ssp () == 0 ? 0 : SIGSEGV) +#define EXPECTED_SIGNAL (CPU_FEATURE_ACTIVE (IBT) ? SIGSEGV : 0) #include