Re: [LTP] [PATCH] listmount04: Detect EBADF behavior dynamically at runtime
Wake Liu via ltp <[email protected]> Mon, 27 Jul 2026 20:21:19 +0800
| Newsgroups | it.linux.lists.ltp |
|---|---|
| Message-ID | <CAOcRiAG48VW3EqxSdAauBx0PFUQcXMy8b52B1Vnr=hjLcgNS=w@mail.gmail.com> |
Hi Petr, Thanks for the review. I've just sent out v2. To address your comments: - listmount() helper: We can't use it here because it constructs the request struct internally with `mnt_ns_fd = 0`. We need to set `mnt_ns_fd = -1` to trigger the error behavior we are probing. - Macro rename: Renamed BEFORE/AFTER_6_17_9 to BEFORE/AFTER_6_18 and added a note about stable backports. - ENOSYS check: Removed since `.min_kver = "6.11"` guarantees listmount support. Best regards, Wake On Fri, Jul 24, 2026 at 8:11 PM Petr Vorel <[email protected]> wrote: > > > 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 <[email protected]> > > --- > > .../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)); > I wonder if we should use listmount() from listmount.h. > > > + if (TST_RET >= 0) > > + tst_brk(TBROK, "listmount() succeeded unexpectedly with invalid fd"); > Maybe we could have TST_EXP_FAIL_ARR_SILENT_BRK() in the future :) > > > + > > + if (TST_ERR == EBADF) { > > kver = AFTER_6_17_9; > At this point we may rename macros back to AFTER_6_18 and BEFORE_6_18, with > keeping note that it got backported into stable. > > > - 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"); > This is IMHO not supported, because it's part of tst_syscall(). > Other than this LGTM. > Reviewed-by: Petr Vorel <[email protected]> > > Kind regards, > Petr > > > + } else { > > + tst_brk(TBROK | TTERRNO, "Unexpected error during probe"); > > + } -- Best Regards, Wake Liu -- Mailing list info: https://lists.linux.it/listinfo/ltp