From patchwork Sat Dec 16 16:53:11 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: 82301 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 4E7D53864844 for ; Sat, 16 Dec 2023 16:54:44 +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 E7516385C41B for ; Sat, 16 Dec 2023 16:53:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E7516385C41B 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 E7516385C41B 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=1702745613; cv=none; b=umHUrN2V3v9x5oxWSYF9eykxEMivrh9suH+Rtn2ejsItJtBO0NZpxC+81pVskK08TDKe1xifF+NR7Nf3Y57Oq0NI+/YJqx1OC8ql5n2ck0I0/wOiod7Rhw60KSEKfxdnLubVyRA4mr+IoMz9hZ7nsEt22sY8rwTv7S6livc+Ogk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702745613; c=relaxed/simple; bh=jxW/SkrVn18D8mOS3FpGySqq7q/7HGgXbFvR43enobU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dd6VT2S5vml6OeTw04YLBaXUQ+8FVDNDEG8QPuEArv9FEv7GgFsyjPb91kNcTkWioXP8nfwoTBetlP+7UYz3J4ORiZwL+Sa70wb1+YCSoGc+CrrGBCHKJhGpoTp6Xi4D2B+9j/RehwsE9DY/xUcBO58j4QnTlR4GXVUalWwsKiY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6cea2a38b48so1611155b3a.3 for ; Sat, 16 Dec 2023 08:53:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702745610; x=1703350410; 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=Y1vwKhLPFk8bqXayy5O/BhdCeHzKgqelcteYX7iELTvU/OS5LcCP4rRm5gX4IYZ2V6 2rgF9Y1Wz7NqFDuTDb1lzZXJQDd42P0T2XkjYqW7Wa2jE5PxDwFmEY6ED3KlXSaiTG8q MrV6AmuiDysrJM6HZEQGDTFwuzUdT/QCeCVUOQhL+eWL4+TgRlpyzK2nBP1n1uUR9/L/ 9arzCVqTMjsHLIzYyxNlgDW3Fz6qGqIXugrBa11J1uS0PZbFR3Ae9/2voH/KilKT/ft1 rVHdsfEQ2WMvHnG7o+yhmCjR1GpqOjqVkFd4gvk7CbMohw2rRuOFq54CGP/I8Ny+MyS2 32Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702745610; x=1703350410; 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=dxaplNl90/U6VVIKXVAJU0W7CG1lsy0p6N3gw1srPZwHw9cQyUo0SP8NeTqL/xNSx8 oxhml0XJ6cyo0SsXn10sSk1ANdJtBmIfcqoPjjnB4JVZOtk1pUU3lXixwoVuXJhtFnfi Pcw3gBWXy10SjjwYlXaIoiM/Z8U2l5h9IpPuEcIfy5Fg22WVFChgk4fKjETy6mOciWzW KfrPzlaLESaemE7VuPmYunrgf4rlxNKugabzVnFKy1H5CGbEDJO7vaPguBOr6MgtQGwn gk83IuX41eE8ddrAo3+G9vqUX3+ry6K7pqcaUtlynOWEMfwxPxP8lwUoqs5FvvEwDagD Eztg== X-Gm-Message-State: AOJu0YwwH9WdMjohZu7C2ac0QXKXjdFrayrCycNiWyOADEJXfl02mSGx fTNXEdzOtT8wco1l3HvVHpo= X-Google-Smtp-Source: AGHT+IHmhuxr05UPthpjpf285zsNsbyah1sTmwWcX/vQ+tzyKoVLMpb4I+4AdFhIHlNe2ulfWV592Q== X-Received: by 2002:a05:6a00:8cb:b0:6ce:2731:e868 with SMTP id s11-20020a056a0008cb00b006ce2731e868mr16194286pfu.47.1702745609719; Sat, 16 Dec 2023 08:53:29 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.59.129.147]) by smtp.gmail.com with ESMTPSA id n8-20020a654508000000b005c65fcca22csm13009263pgq.85.2023.12.16.08.53.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Dec 2023 08:53:27 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 63F6D74061E; Sat, 16 Dec 2023 08:53:25 -0800 (PST) From: "H.J. Lu" To: libc-alpha@sourceware.org Cc: rick.p.edgecombe@intel.com Subject: [PATCH v2 02/16] x86/cet: Update tst-cet-vfork-1 Date: Sat, 16 Dec 2023 08:53:11 -0800 Message-ID: <20231216165325.2584919-3-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231216165325.2584919-1-hjl.tools@gmail.com> References: <20231216165325.2584919-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3024.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, 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