Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795038849; b=gSK0NMZwA9SNmc5E5U6cPpTL0ronWOY4UaBMZ+Q3lWTclUcY/DTCAiS0GT/2V0toi5X3 elAOkuCdb12sXq1A01/QJaTstBucQwFR6kX26IhbeROyoMQqczcuDZvA5+4RQNwyj5zZ1 L1IznzTjhGeucMUV+MkY9AzVJLK56Usz4VeoHORxiEfxm+EZvw4l/Tai0dM6RLwoahJeu 4SGI+zeoljcSpks0Iwxa2Sydx4l/I1AvVvbfCK+Em4+dIOwy78iJOvlhqoS8raymDAJ9E ceTmi78bsLXxnkfQxIbxWVbogpipZmLxFUXPol1PuT4b4NY6y8NXRWdfPqd49z4izxA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795038849; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=mjOXWJnXoq9nA26Fy8kJnaEKLkyPURCX1G6WOyNyWVk=; b=A7FddwkCGPT4b+jUxAZyQUprTnzm/YsS4B7r0tmBPL0CJGJO4IrNwv1kXC8wbK9UZZ3E A0P6ZT9HyQQRmqlPL0AckyFftBqppuHstSlUs0jqO7dnrvv8okQSvOfFy4AyzY8/tYeJv ikbOWxUJmR+6u2gBBKQFECeL0bdI4w7nvxwJ20UIR73/KkQclvpM055RjzKbOb/2BCR0r A+zLTz7UPYVor+y2dWXy8tT+0knqmYHGgx1OMEq/S6bM8LOFkAHA3GEq076YT3q7AkCyW iBqH0ZGm3jZr6kRKmX+gYidAUTmbD3pQRM/Y5FALrIxIqopDacXXbZpETadSwR83AxQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=pOZKYDeS; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05F13606A31C; Wed, 18 Nov 2026 21:54:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=pOZKYDeS Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B1FF1F000C4; Wed, 18 Nov 2026 21:54:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795038848; bh=mjOXWJnXoq9nA26Fy8kJnaEKLkyPURCX1G6WOyNyWVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pOZKYDeSVYFT8IWQZQCTa3Nv0RQOVnzJWl1NFVuQjvblkAX3otUNSP1IWLhWW5WQY 7RD04Ll3ekDqZgj3A2ioP2LOt8/WBaAoZx4mpes7Zn/EN4NxBmDBOZMWSZiNn2lsXz kjYjtyFIgZ6dHVl52CCpHxnqHY4SVrG24IxhxlT4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Konstantin Khorenko , Eva Kurchatova , Andrew Morton , Shuah Khan , Wei Yang , Sasha Levin Subject: [PATCH 6.6 1890/3318] selftests/core: fix unshare_test with large fs.nr_open Date: Wed, 18 Nov 2026 15:41:52 +0100 Message-ID: <20261118150418.699151637@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Konstantin Khorenko [ Upstream commit df0b7e0ea59c43708cff8c7e34da5e2f8d430e5e ] The test assumes fs.nr_open is close to the default 1048576, but some systems set it much higher (e.g. 1073741816). This is systemd's doing: since systemd v240 (2018), PID 1 bumps fs.nr_open and fs.file-max to their largest possible values on boot, as file descriptors are already accounted for by memcg [1]. In that case, dup2() to nr_open + 64 requires the kernel to allocate a file descriptor table with ~1 billion entries, which fails with ENOMEM. On a kernel that already carries 04a2c4b4511d1, dup2() no longer fails with ENOMEM. The allocation is now rejected up front and the caller gets EMFILE instead, without the WARNING, but the test still fails. Cap the nr_open value used for the test's own arithmetic to a known reasonable base value (1048576) and restore the true original value once the test has completed. Link: https://lore.kernel.org/20260814165709.513263-1-khorenko@virtuozzo.com Link: https://github.com/systemd/systemd/commit/a8b627aaed409a15260c25988970c795bf963812 [1] Signed-off-by: Konstantin Khorenko Signed-off-by: Eva Kurchatova Signed-off-by: Andrew Morton Cc: Shuah Khan Cc: Wei Yang Cc: Signed-off-by: Sasha Levin --- tools/testing/selftests/core/unshare_test.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/core/unshare_test.c b/tools/testing/selftests/core/unshare_test.c index 7fec9dfb1b0e3..6716e0f74d7da 100644 --- a/tools/testing/selftests/core/unshare_test.c +++ b/tools/testing/selftests/core/unshare_test.c @@ -40,6 +40,14 @@ TEST(unshare_EMFILE) ASSERT_EQ(sscanf(buf, "%d", &nr_open), 1); + /* + * Cap nr_open for the duration of the test to avoid ENOMEM from a + * huge fd table allocation; buf/n keep the real original value so + * fs.nr_open can be restored to it once the test is done. + */ + if (nr_open > 1024 * 1024) + nr_open = 1024 * 1024; + ASSERT_EQ(0, getrlimit(RLIMIT_NOFILE, &rlimit)); /* bump fs.nr_open */ @@ -73,10 +81,13 @@ TEST(unshare_EMFILE) if (pid == 0) { int err; + char buf3[32]; + ssize_t n3; - /* restore fs.nr_open */ + /* restore fs.nr_open to the (possibly capped) test baseline */ + n3 = sprintf(buf3, "%d\n", nr_open); lseek(fd, 0, SEEK_SET); - write(fd, buf, n); + write(fd, buf3, n3); /* ... and now unshare(CLONE_FILES) must fail with EMFILE */ err = unshare(CLONE_FILES); EXPECT_EQ(err, -1) @@ -89,6 +100,10 @@ TEST(unshare_EMFILE) EXPECT_EQ(waitpid(pid, &status, 0), pid); EXPECT_EQ(true, WIFEXITED(status)); EXPECT_EQ(0, WEXITSTATUS(status)); + + /* restore the real fs.nr_open value */ + lseek(fd, 0, SEEK_SET); + write(fd, buf, n); } TEST_HARNESS_MAIN -- 2.53.0