From patchwork Tue Dec 19 16:07:32 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: 82516 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 73AC2385771F for ; Tue, 19 Dec 2023 16:08:23 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 5BD293858417 for ; Tue, 19 Dec 2023 16:08:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5BD293858417 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 5BD293858417 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703002090; cv=none; b=P8qWgW6oy2pFusg61A6x7cG9HybGObFXrce2VwQBe1CIJwIWiiXhkthbj1X+/L8wxym0/yvTsYcr4wgzmF12w/2MDq5G/3K17lN1S5SaTErQk+vI8/1KKRRkeBUc9roqucUyIGnrlHhjPBXnBbTiUHBXRImYK8V40rsfh/3Y6vw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703002090; c=relaxed/simple; bh=jxW/SkrVn18D8mOS3FpGySqq7q/7HGgXbFvR43enobU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=yFSMJXTio4Gr4SQ8HERQuXraXf8Cz6Uphy2ALIQ/8twI5KUZEmW1ZjaNBZvj7ukHRE3XahfQpjB08FuoLb6T9010wwzdqvw32IwiAFk72M+++m+cJKZfpoYklNAzXVnuv7VtVc62aqOoeS9X6V0svAwZCSeZ/UrnfWrw/xbj5lM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6d7609cb6d2so1394182b3a.1 for ; Tue, 19 Dec 2023 08:08:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703002086; x=1703606886; 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=qMvtHogobq6JlLL5ALFhdAK3OmuMdJlleYsUArs3zhg=; b=Y6bnx5HM687cWv2pR/3ngFIAUzI5aKyBaDHlP8Roq/sVFN0v+W+6CdwYLf0W57vrBW jF1SCunvLnQXNZ7jpGvKitpEzHmKhjiIw8FkeYECdA9t1DkE+mmiDdf6seo6vVR+7i8w 7NayPrSiWqy/r3ylOtnUnWtbzciT6PPHKdmHkJnzLD4FNPzmMs4GA37Z+nsAyTRmdohh bOoMFClnKrUVqnefuzX7yRnK12DLhQAv165gni6KsNa2Eorjo4wkbgIQvVAIEXh0zexx +ijAi1szTtT/epwuEuvh3h/2PEUmNeR6MHxLkfxwSAZDKHN1qnCvfHEu67HzPPgckSBc w0kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703002086; x=1703606886; 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=qMvtHogobq6JlLL5ALFhdAK3OmuMdJlleYsUArs3zhg=; b=H5u3izpPVer9IwZfFjVNR7QIdGirToKOqbmKfplcM6XqVlbpMJhpU9bz3W/DHiqyhD qesmONEHKVMObzyNhgO2gOeq8LHT+YzAgBKHYRQnutJjn6iYov8pXUvk9a8D2q9MP7HC WkKqqIHmyKcoI3WRrcrww955R24rByhI6rT6FMZy5fk6ZooJsvrtWEhVFX1FcraTGH3y S1F1eNVfwamZPKE6tNoF+XWVlTUe6aCRMCFKQBmipSwJuXwjoYIRk1PsMNuEDSIpP4Bu ZnmzeusxAQtF0YkPqLXY8Vtza9nqC/PfEG3kDW5wZxr0bob8rnvya9DQ6IV/GNM6HEpr 8nZA== X-Gm-Message-State: AOJu0Yygtml9MPRS4yCAawMT7F6FndydKYRo6X6pM7kOXOPo6X2FN354 5D1h+1wwsU9+wpmGB59zKmpcPaCrvpQ= X-Google-Smtp-Source: AGHT+IG9+1Fl3IAKOReZo8Jb8WjsK4y37PT7qU+7G8+/tORHb7kBCUmGpPeskjXVT9SnsfFuMqqSIg== X-Received: by 2002:a05:6a21:1f03:b0:18f:97c:4f66 with SMTP id ry3-20020a056a211f0300b0018f097c4f66mr8853410pzb.114.1703002086254; Tue, 19 Dec 2023 08:08:06 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.59.129.147]) by smtp.gmail.com with ESMTPSA id s10-20020a056a0008ca00b006ce4965fdbdsm6478287pfu.116.2023.12.19.08.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 08:07:55 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 1E48F7403BA; Tue, 19 Dec 2023 08:07:41 -0800 (PST) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: goldstein.w.n@gmail.com, rick.p.edgecombe@intel.com Subject: [PATCH v3 1/9] x86/cet: Update tst-cet-vfork-1 Date: Tue, 19 Dec 2023 08:07:32 -0800 Message-ID: <20231219160740.3079330-2-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231219160740.3079330-1-hjl.tools@gmail.com> References: <20231219160740.3079330-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3024.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_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+patchwork=sourceware.org@sourceware.org Change tst-cet-vfork-1.c to verify that vfork child return triggers SIGSEGV due to shadow stack mismatch. --- sysdeps/unix/sysv/linux/x86/tst-cet-vfork-1.c | 43 ++++++++----------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/sysdeps/unix/sysv/linux/x86/tst-cet-vfork-1.c b/sysdeps/unix/sysv/linux/x86/tst-cet-vfork-1.c index 9c4b6f4d42..c92ed9e737 100644 --- a/sysdeps/unix/sysv/linux/x86/tst-cet-vfork-1.c +++ b/sysdeps/unix/sysv/linux/x86/tst-cet-vfork-1.c @@ -18,34 +18,26 @@ . */ #include -#include #include #include #include #include #include #include -#include -#include __attribute__ ((noclone, noinline)) static void do_test_1 (void) { pid_t p1; - int fd[2]; - if (pipe (fd) == -1) - { - puts ("pipe failed"); - _exit (EXIT_FAILURE); - } + /* NB: Since child return pops shadow stack which is shared with + parent, child must not return after vfork. */ if ((p1 = vfork ()) == 0) { - pid_t p = getpid (); - TEMP_FAILURE_RETRY (write (fd[1], &p, sizeof (p))); - /* Child return should trigger SIGSEGV. */ + /* Child return should trigger SIGSEGV due to shadow stack + mismatch. */ return; } else if (p1 == -1) @@ -54,22 +46,22 @@ do_test_1 (void) _exit (EXIT_FAILURE); } - pid_t p2 = 0; - if (TEMP_FAILURE_RETRY (read (fd[0], &p2, sizeof (pid_t))) - != sizeof (pid_t)) - puts ("pipd read failed"); - else + int r; + if (TEMP_FAILURE_RETRY (waitpid (p1, &r, 0)) != p1) { - int r; - if (TEMP_FAILURE_RETRY (waitpid (p1, &r, 0)) != p1) - puts ("waitpid failed"); - else if (r != 0) - puts ("pip write in child failed"); + puts ("waitpid failed"); + _exit (EXIT_FAILURE); + } + + if (!WIFSIGNALED (r) || WTERMSIG (r) != SIGSEGV) + { + puts ("Child not terminated with SIGSEGV"); + _exit (EXIT_FAILURE); } /* Parent exits immediately so that parent returns without triggering - SIGSEGV when shadow stack isn't in use. */ - _exit (EXIT_FAILURE); + SIGSEGV when shadow stack is in use. */ + _exit (EXIT_SUCCESS); } static int @@ -80,9 +72,8 @@ do_test (void) return EXIT_UNSUPPORTED; do_test_1 (); /* Child exits immediately so that child returns without triggering - SIGSEGV when shadow stack isn't in use. */ + SIGSEGV when shadow stack is in use. */ _exit (EXIT_FAILURE); } -#define EXPECTED_SIGNAL (_get_ssp () == 0 ? 0 : SIGSEGV) #include