Linux Test Project
 help / color / mirror / Atom feed
* [LTP] [PATCH] listmount04: Detect EBADF behavior dynamically at runtime
@ 2026-07-24  9:57 Wake Liu via ltp
  2026-07-24 12:11 ` Petr Vorel
  0 siblings, 1 reply; 2+ messages in thread
From: Wake Liu via ltp @ 2026-07-24  9:57 UTC (permalink / raw)
  To: ltp; +Cc: wakel

Upstream commit 78f0e33cd6c9 ("fs/namespace: correctly handle errors
returned by grab_requested_mnt_ns") changed the errno from EINVAL to
EBADF when an invalid mount namespace file descriptor is passed to
listmount(). This change has been backported to various stable kernels
(e.g., 6.12.59 LTS).

Instead of hardcoding version checks for every stable backport, probe
the behavior dynamically in setup() by calling listmount() with an
invalid fd (-1) and checking the returned errno.

Signed-off-by: Wake Liu <wakel@google.com>
---
 .../kernel/syscalls/listmount/listmount04.c   | 27 ++++++++++++++++---
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/testcases/kernel/syscalls/listmount/listmount04.c b/testcases/kernel/syscalls/listmount/listmount04.c
index 919f4c854..f7343608f 100644
--- a/testcases/kernel/syscalls/listmount/listmount04.c
+++ b/testcases/kernel/syscalls/listmount/listmount04.c
@@ -153,16 +153,35 @@ static void run(unsigned int n)
 	}
 
 	TST_EXP_FAIL(tst_syscall(__NR_listmount, req, tc->mnt_ids,
-		tc->nr_mnt_ids, tc->flags), tc->exp_errno,
-		"%s", tc->msg);
+				 tc->nr_mnt_ids, tc->flags),
+		     tc->exp_errno,
+		     "%s", tc->msg);
 }
 
 static void setup(void)
 {
-	if (tst_kvercmp(6, 17, 9) >= 0)
+	mnt_id_req req = {
+		.size = MNT_ID_REQ_SIZE_VER0,
+		.mnt_id = LSMT_ROOT,
+		.mnt_ns_fd = -1,
+	};
+	uint64_t ids[MNT_SIZE];
+
+	TEST(tst_syscall(__NR_listmount, &req, ids, MNT_SIZE, 0));
+	if (TST_RET >= 0)
+		tst_brk(TBROK, "listmount() succeeded unexpectedly with invalid fd");
+
+	if (TST_ERR == EBADF) {
 		kver = AFTER_6_17_9;
-	else
+		tst_res(TINFO, "Detected kernel with EBADF behavior for invalid mnt_ns_fd");
+	} else if (TST_ERR == EINVAL) {
 		kver = BEFORE_6_17_9;
+		tst_res(TINFO, "Detected kernel with EINVAL behavior for invalid mnt_ns_fd");
+	} else if (TST_ERR == ENOSYS) {
+		tst_brk(TCONF, "listmount() syscall not supported");
+	} else {
+		tst_brk(TBROK | TTERRNO, "Unexpected error during probe");
+	}
 }
 
 static struct tst_test test = {
-- 
2.55.0.487.gaf234c4eb3-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-24 12:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-24  9:57 [LTP] [PATCH] listmount04: Detect EBADF behavior dynamically at runtime Wake Liu via ltp
2026-07-24 12:11 ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox