From mboxrd@z Thu Jan 1 00:00:00 1970 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 picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4DA53C28D13 for ; Thu, 25 Aug 2022 11:09:32 +0000 (UTC) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 7415C3C8854 for ; Thu, 25 Aug 2022 13:09:30 +0200 (CEST) Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 3A2963CA44B for ; Thu, 25 Aug 2022 13:09:02 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by in-7.smtp.seeweb.it (Postfix) with ESMTP id A2F81200276 for ; Thu, 25 Aug 2022 13:09:01 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1E6B81FB; Thu, 25 Aug 2022 04:09:04 -0700 (PDT) Received: from e129169.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1424F3FAF5; Thu, 25 Aug 2022 04:08:58 -0700 (PDT) From: Tudor Cretu To: ltp@lists.linux.it Date: Thu, 25 Aug 2022 12:10:14 +0100 Message-Id: <20220825111014.210185-3-tudor.cretu@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220825111014.210185-1-tudor.cretu@arm.com> References: <20220825111014.210185-1-tudor.cretu@arm.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v3 2/2] syscalls/statfs02, fstatfs02: Accept segfault instead of EFAULT X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ltp-bounces+ltp=archiver.kernel.org@lists.linux.it Sender: "ltp" The [f]statfs02 testsuites check that [f]statfs returns EFUALT when the provided buf parameter is invalid. There are cases in which the supported libcs don't exhibit this behaviour. glibc versions newer than 2.34 and on systems that support [f]statfs64, call the syscall with a local struct statfs and then copy the result into buf. This throws a segfault for an invalid buf. musl dereferences buf before the syscall is called and, similarly, throws a segfault. Allow the tests to pass if segfault is thrown instead of returning EFAULT. Signed-off-by: Tudor Cretu --- testcases/kernel/syscalls/fstatfs/fstatfs02.c | 22 ++++++++++++++++++- testcases/kernel/syscalls/statfs/statfs02.c | 22 ++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/testcases/kernel/syscalls/fstatfs/fstatfs02.c b/testcases/kernel/syscalls/fstatfs/fstatfs02.c index 4267bd02b..f2a4c0abd 100644 --- a/testcases/kernel/syscalls/fstatfs/fstatfs02.c +++ b/testcases/kernel/syscalls/fstatfs/fstatfs02.c @@ -33,7 +33,26 @@ static struct test_case_t { static void fstatfs_verify(unsigned int n) { - TST_EXP_FAIL(fstatfs(tests[n].fd, tests[n].sbuf), tests[n].error, "fstatfs()"); + int pid, status; + + pid = SAFE_FORK(); + if (!pid) { + TST_EXP_FAIL(fstatfs(tests[n].fd, tests[n].sbuf), tests[n].error, "fstatfs()"); + exit(0); + } + + SAFE_WAITPID(pid, &status, 0); + + if (WIFEXITED(status)) + return; + + if (tests[n].error == EFAULT && + WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) { + tst_res(TPASS, "Got SIGSEGV instead of EFAULT"); + return; + } + + tst_res(TFAIL, "Child %s", tst_strstatus(status)); } static void setup(void) @@ -57,4 +76,5 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .needs_tmpdir = 1, + .forks_child = 1, }; diff --git a/testcases/kernel/syscalls/statfs/statfs02.c b/testcases/kernel/syscalls/statfs/statfs02.c index f906c84ff..0869b1632 100644 --- a/testcases/kernel/syscalls/statfs/statfs02.c +++ b/testcases/kernel/syscalls/statfs/statfs02.c @@ -56,7 +56,26 @@ static void cleanup(void); static void statfs_verify(unsigned int n) { - TST_EXP_FAIL(statfs(tests[n].path, tests[n].buf), tests[n].exp_error, "statfs()"); + int pid, status; + + pid = SAFE_FORK(); + if (!pid) { + TST_EXP_FAIL(statfs(tests[n].path, tests[n].buf), tests[n].exp_error, "statfs()"); + exit(0); + } + + SAFE_WAITPID(pid, &status, 0); + + if (WIFEXITED(status)) + return; + + if (tests[n].exp_error == EFAULT && + WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) { + tst_res(TPASS, "Got SIGSEGV instead of EFAULT"); + return; + } + + tst_res(TFAIL, "Child %s", tst_strstatus(status)); } static void setup(void) @@ -86,4 +105,5 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .needs_tmpdir = 1, + .forks_child = 1, }; -- 2.25.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp