From patchwork Sun Jul 17 23:16:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Hudson-Doyle X-Patchwork-Id: 56111 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 F32C7383643E for ; Sun, 17 Jul 2022 23:17:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F32C7383643E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1658099853; bh=qsr51iZ7pAwA8+w2N2RQwanSn5AH4hO5YpLTrErMfOo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=qx/5m7Sd4lT75VWcM0hvGn7HBEfER6vm2q0Itfo6/fp3vvxK0XYWsKQJSWKOtMkLG biJXSIzI04RmWKgiZjaYyZ3O29fwSKYkAoo/LRSNMBOF1BsBQibVNLg0YiLvim7180 IoCuxc5YyIpAsiRDdQWoEx/EHQ+lNHL80O5Azq4w= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by sourceware.org (Postfix) with ESMTPS id 909F9383642D for ; Sun, 17 Jul 2022 23:17:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 909F9383642D Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 41D545C0097; Sun, 17 Jul 2022 19:17:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sun, 17 Jul 2022 19:17:09 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudekjedgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefoihgthhgrvghlucfjuhgushhonhdqffhohihlvgcuoehm ihgthhgrvghlrdhhuhgushhonhestggrnhhonhhitggrlhdrtghomheqnecuggftrfgrth htvghrnhepgeejjeelveeltedtfeehiedtgeelgedthedukedujefhhfdthfdvfeejledu ieeinecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmh ifhhhuughsohhnsehfrghsthhmrghilhdrfhhm X-ME-Proxy: Feedback-ID: i833146b3:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 17 Jul 2022 19:17:08 -0400 (EDT) To: libc-alpha@sourceware.org Subject: [PATCH v3] linux: return UNSUPPORTED from tst-mount if entering mount namespace fails Date: Mon, 18 Jul 2022 11:16:57 +1200 Message-Id: <20220717231657.1269920-1-michael.hudson@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220715000657.1712606-1-michael.hudson@canonical.com> References: <20220715000657.1712606-1-michael.hudson@canonical.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Michael Hudson-Doyle via Libc-alpha From: Michael Hudson-Doyle Reply-To: Michael Hudson-Doyle Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Before this the test fails if run in a chroot by a non-root user: warning: could not become root outside namespace (Operation not permitted) ../sysdeps/unix/sysv/linux/tst-mount.c:36: numeric comparison failure left: 1 (0x1); from: errno right: 19 (0x13); from: ENODEV error: ../sysdeps/unix/sysv/linux/tst-mount.c:39: not true: fd != -1 error: ../sysdeps/unix/sysv/linux/tst-mount.c:46: not true: r != -1 error: ../sysdeps/unix/sysv/linux/tst-mount.c:48: not true: r != -1 ../sysdeps/unix/sysv/linux/tst-mount.c:52: numeric comparison failure left: 1 (0x1); from: errno right: 9 (0x9); from: EBADF error: ../sysdeps/unix/sysv/linux/tst-mount.c:55: not true: mfd != -1 ../sysdeps/unix/sysv/linux/tst-mount.c:58: numeric comparison failure left: 1 (0x1); from: errno right: 2 (0x2); from: ENOENT error: ../sysdeps/unix/sysv/linux/tst-mount.c:61: not true: r != -1 ../sysdeps/unix/sysv/linux/tst-mount.c:65: numeric comparison failure left: 1 (0x1); from: errno right: 2 (0x2); from: ENOENT error: ../sysdeps/unix/sysv/linux/tst-mount.c:68: not true: pfd != -1 error: ../sysdeps/unix/sysv/linux/tst-mount.c:75: not true: fd_tree != -1 ../sysdeps/unix/sysv/linux/tst-mount.c:88: numeric comparison failure left: 1 (0x1); from: errno right: 38 (0x26); from: ENOSYS error: 12 test failures Checking that the test can enter a new mount namespace is more correct than just checking the return value of support_become_root() as the test code changes the mount namespace it runs in so running it as root on a system that does not support mount namespaces should still skip. Also change the test to remove the unnecessary fork. Reviewed-by: Carlos O'Donell --- v3: check support_enter_mount_namespace() return value, remove fork v2: check support_can_chroot() rather than support_become_root return value --- sysdeps/unix/sysv/linux/tst-mount.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/sysdeps/unix/sysv/linux/tst-mount.c b/sysdeps/unix/sysv/linux/tst-mount.c index 502d7e3433..b6333a60e6 100644 --- a/sysdeps/unix/sysv/linux/tst-mount.c +++ b/sysdeps/unix/sysv/linux/tst-mount.c @@ -20,15 +20,18 @@ #include #include #include -#include #include _Static_assert (sizeof (struct mount_attr) == MOUNT_ATTR_SIZE_VER0, "sizeof (struct mount_attr) != MOUNT_ATTR_SIZE_VER0"); -static void -subprocess (void) +static int +do_test (void) { + support_become_root (); + if (!support_enter_mount_namespace ()) + FAIL_UNSUPPORTED ("cannot enter mount namespace, skipping test"); + int r = fsopen ("it_should_be_not_a_valid_mount", 0); TEST_VERIFY_EXIT (r == -1); if (errno == ENOSYS) @@ -100,20 +103,4 @@ subprocess (void) _exit (0); } -static int -do_test (void) -{ - support_become_root (); - - pid_t pid = xfork (); - if (pid == 0) - subprocess (); - - int status; - xwaitpid (pid, &status, 0); - TEST_VERIFY (WIFEXITED (status)); - - return 0; -} - #include