From patchwork Mon Aug 14 08:40:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksa Sarai X-Patchwork-Id: 13352563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10798EB64DD for ; Mon, 14 Aug 2023 08:41:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D9EF8E0003; Mon, 14 Aug 2023 04:41:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 88A9A8E0001; Mon, 14 Aug 2023 04:41:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72BE98E0003; Mon, 14 Aug 2023 04:41:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 647628E0001 for ; Mon, 14 Aug 2023 04:41:37 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 317B41A0886 for ; Mon, 14 Aug 2023 08:41:37 +0000 (UTC) X-FDA: 81122066634.03.6426837 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf21.hostedemail.com (Postfix) with ESMTP id 51C3C1C0011 for ; Mon, 14 Aug 2023 08:41:35 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=cyphar.com header.s=MBO0001 header.b=PWInDqWM; spf=pass (imf21.hostedemail.com: domain of cyphar@cyphar.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=cyphar@cyphar.com; dmarc=pass (policy=reject) header.from=cyphar.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692002495; a=rsa-sha256; cv=none; b=Rg9Eu5gUBSmyHaBsYfjoSDHJd7BHp2bvGYRamaRSw/nWfevPTLd1hjYC4zHpXSeYiYNBZO vZ3XWxIZCNw7HNEJk4dKW+WUZoH64szU4Q+OigokSh7aonKc7nTL8IzfiDg4QeE4UCJzZd D73A8RPXGs2dbTt4QJnc4WwaZlzUNPs= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=cyphar.com header.s=MBO0001 header.b=PWInDqWM; spf=pass (imf21.hostedemail.com: domain of cyphar@cyphar.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=cyphar@cyphar.com; dmarc=pass (policy=reject) header.from=cyphar.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692002495; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7gQyeuP4S02FF5qxYTiiXRiidByA4CAzLTryBvJ7G7w=; b=CMXvfQdWadCqXS1AzEyEdMJlaqU7ip6zZi02+4y40SvnjN8zZcdMbS3oUMQLLysQXb3RFr 9K8HUIX6rc71SJkuGtBXt94tjTul0Fm4q8Q9bfxbEMDNh01mrm8yHpRdic/fU/5Gd9gc3s f0+Psn3r+TiwpwUP0A6HRxD9LFW6Vd8= Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4RPSYR2bs0z9sWB; Mon, 14 Aug 2023 10:41:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cyphar.com; s=MBO0001; t=1692002491; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7gQyeuP4S02FF5qxYTiiXRiidByA4CAzLTryBvJ7G7w=; b=PWInDqWMMKzI/ONQxGwzOm9Nqjj0QWXmLPZUkhDGsxbUFUikujZWbEY1MqZPB1WBCvi77e kiKJ8pi/2PteW88+lQBK8ltXeZV9mb2bYVBIT+xToxGb7CsmZSjDBOtgWYsBzPZwis7wXQ RtHIduy6h2n0Y08EgBWVCaB3NB4595F6cDxfr1hTZLGJAVUq5dt4TkT/kmSYd5o/jIhMC4 ijPwqZ/3W9OYLr4Ca7Mt3QrZIxPfcKZbkuVIeM0k0uGsxknhulEqFewn6BGmOkqAjyH3EK i++D6TrN/b3E0iNQOwpKhc/n00nHwaN4m35+mYh5wEz06ygRPqfkMrBizyhlDw== From: Aleksa Sarai Date: Mon, 14 Aug 2023 18:40:57 +1000 Subject: [PATCH v2 1/5] selftests: memfd: error out test process when child test fails MIME-Version: 1.0 Message-Id: <20230814-memfd-vm-noexec-uapi-fixes-v2-1-7ff9e3e10ba6@cyphar.com> References: <20230814-memfd-vm-noexec-uapi-fixes-v2-0-7ff9e3e10ba6@cyphar.com> In-Reply-To: <20230814-memfd-vm-noexec-uapi-fixes-v2-0-7ff9e3e10ba6@cyphar.com> To: Andrew Morton , Shuah Khan , Jeff Xu , Kees Cook , Daniel Verkamp Cc: Christian Brauner , Dominique Martinet , stable@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Aleksa Sarai X-Developer-Signature: v=1; a=openpgp-sha256; l=1390; i=cyphar@cyphar.com; h=from:subject:message-id; bh=+Up0ghrBW/nfRj4bC3B4yqL0dFwv9KTB+GgoZwyV0aw=; b=owGbwMvMwCWmMf3Xpe0vXfIZT6slMaTcfLFiw/TsfmWDxoNz8nnmrvi1iHnrP6m7AWasOo8m3 1wekyNc2FHKwiDGxSArpsiyzc8zdNP8xVeSP61kg5nDygQyhIGLUwAmkpfFyDBRc+qvi5+lrvwq Uu9s9nvj/PqGRbrzrqg2Y4FZ6bO7O9cw/NPdWbdxP9tDl7XxbgXfxdZNaXf791I7X+J3+4PgVBu 9RXwA X-Developer-Key: i=cyphar@cyphar.com; a=openpgp; fpr=C9C370B246B09F6DBCFC744C34401015D1D2D386 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 51C3C1C0011 X-Stat-Signature: mzswb4gh6dz4xzu1cy4wqkf7xr5oqrtf X-Rspam-User: X-HE-Tag: 1692002495-160332 X-HE-Meta: U2FsdGVkX18tqKZcTtY5UaK9qIH0vPjC9ESjjZfIlb/P6aaxNMDP6GWlzJESrd9jk4vy3SQdQh7C3O42r/AHbg9unphaR4S3HG498E05A9cimz62D82UxYhg7/9use/nAYaGE1+TpyzwWnBeQXmHiJ+LkEdxj11wFiItFo39vVDuQ+HlpZpTwBfMirSqJHRVmFoVnwFoqPu6cppe9pJT53uKfGaAvVH9spKTWP/M+SkOYnCbFqOWtDmi91LET0fKDkeuTdHLqHhPHN2SUyOIWDnJK7jGZYT+5eb+X+FnDNdtuzMUNH8YnTJzhUsJFrgahPWhkO7L/T/c22o6zsMC7STZivpxaFcV6fUNFHcQc3uSz8gCShGZ+TIgx9MZzrhiMlrHdh5YTyEYTzPgfbFKCJDovvo1oiWYK30FePn/LzWUwAv3MqMVZQnOflvHYxJuWHLDYZZaFKiqSjrjSU0MnPEdflMlUw9qIYkRsLYdcfC6pg9MR+WLvXBX9mSSYtgX6K7hTPYVUdJrziN3FW7tFkn6ZoRJXaZg5fptZS6JJC2trgr/LuoKrYoJRzBglTmOqEldeDQk5xPFXWOfc+fxSHHaZ7fCBu0PM9+1JjMB9Xt3HdxDfLbVQGv12geCPXoiEOyHXlmNpHq4gdRgxpvllV+3rxuyuNKkjhsJw852VK71kV6ovNwXp1zfv6v130naRkA1Ws8fWF03xdnsszvCqwZinadWQNgGvJrgQebMNnKMhzRVstqpFamV4bEXtBo9SxxTCAj3n2w/yki25EN1mZFJ//8Hgz9R6oCTPo4JfrwCIUpSJ6wSCGd045ayYQ5P+1bRVzms0Iblg9zK0jiFaaM2Jh+OdbjkLZYgF/GceFtz/utNpXmN7+uY3wA2S/KFJf55G2ydAMCjh9t9Wy1fCmVTgyZ+zY9vU7ZvaEIEuk59M0XG6YRD/vNKIIJIGWptkmcljU9e5wP5V915M0K AO5wcKu0 wAyEr8osDdXjhpdu65sAZTLm54j+zQ/0oUbs1L3icDDsmHAKj091lWN6OgeEM/OiE+3GaRcbLlb/pSkgwknKow6VHgsorWDyPXC/Mo0/3WI7+v1nC4qH/bXhnz/6tA8wLmpI9YWEOarUYbgzyMEoF1b/oYttaCX+iA3BuzhbeSi/WHmb5kBK4Ky2cOPPaiEc5cLKqNZ3pxI7oahTHawzPadFLLouiX7T5lUub X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Before this change, a test runner using this self test would see a return code of 0 when the tests using a child process (namely the MFD_NOEXEC_SEAL and MFD_EXEC tests) failed, masking test failures. Fixes: 11f75a01448f ("selftests/memfd: add tests for MFD_NOEXEC_SEAL MFD_EXEC") Reviewed-by: Jeff Xu Signed-off-by: Aleksa Sarai --- tools/testing/selftests/memfd/memfd_test.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c index dbdd9ec5e397..8eb49204f9ea 100644 --- a/tools/testing/selftests/memfd/memfd_test.c +++ b/tools/testing/selftests/memfd/memfd_test.c @@ -1207,7 +1207,24 @@ static pid_t spawn_newpid_thread(unsigned int flags, int (*fn)(void *)) static void join_newpid_thread(pid_t pid) { - waitpid(pid, NULL, 0); + int wstatus; + + if (waitpid(pid, &wstatus, 0) < 0) { + printf("newpid thread: waitpid() failed: %m\n"); + abort(); + } + + if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) != 0) { + printf("newpid thread: exited with non-zero error code %d\n", + WEXITSTATUS(wstatus)); + abort(); + } + + if (WIFSIGNALED(wstatus)) { + printf("newpid thread: killed by signal %d\n", + WTERMSIG(wstatus)); + abort(); + } } /*