[LTP] syscalls/fanotify26: Add test for nested permission events
linuxtestproject.agent@gmail.com
linuxtestproject.agent@gmail.com
Wed Oct 28 00:20:28 CET 2026
Hi Edvard,
On Tue, Oct 27, 2026 at 08:37:01PM +0100, Edvard Conrad wrote:
> syscalls/fanotify26: Add test for nested permission events
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fanotify/fanotify26.c
> @@ -0,0 +1,185 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*\
> + * Check that a permission event on a stacked filesystem does not deadlock the
A copyright header block ("/* Copyright (c) 2026 Edvard Conrad
<edvard@tuta.io> */") is missing after the SPDX license identifier.
> + if (tc->mark_backing && filesystem_mark_unsupported) {
> + tst_res(TCONF, "FAN_MARK_FILESYSTEM not supported");
> + return;
> + }
> +
> + fd_notify = SAFE_FANOTIFY_INIT(FAN_CLASS_CONTENT, O_RDONLY);
> +
> + SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD | FAN_MARK_FILESYSTEM,
> + FAN_OPEN_PERM, AT_FDCWD, OVL_MNT);
Both test cases use FAN_MARK_FILESYSTEM on OVL_MNT, so gating
filesystem_mark_unsupported on tc->mark_backing causes the first test case to
fail with TBROK when FAN_MARK_FILESYSTEM is unsupported on overlayfs or in
the kernel. Use REQUIRE_MARK_TYPE_SUPPORTED_ON_FS(FAN_MARK_FILESYSTEM,
OVL_MNT) and REQUIRE_MARK_TYPE_SUPPORTED_ON_FS(FAN_MARK_FILESYSTEM,
BACKING_MNT) in setup() and drop filesystem_mark_unsupported.
> + fd = open(OVL_FILE, O_RDONLY);
> + if (fd >= 0)
> + SAFE_CLOSE(fd);
> + exit(0);
> + }
> +
> + /* The opener sleeps in the kernel once its event is queued. */
> + if (TST_PROCESS_STATE_WAIT(opener, 'D', WAIT_MSEC)) {
> + SAFE_CLOSE(fd_notify);
> + tst_brk(TBROK, "Open generated no permission event");
> + }
Use "if (fd != -1)" to check file descriptor validity in opener. Also,
SAFE_CLOSE(fd_notify) before tst_brk() is redundant because cleanup() already
closes fd_notify.
> + reader = SAFE_FORK();
> + if (!reader) {
> + answer_one_event();
> + exit(0);
> + }
> +
> + if (TST_PROCESS_STATE_WAIT(reader, 'Z', WAIT_MSEC)) {
> + tst_res(TFAIL,
> + "Listener blocked in read() by a nested event");
> + SAFE_KILL(reader, SIGKILL);
> + } else {
> + tst_res(TPASS, "Listener answered the event");
> + }
> +
> + SAFE_WAITPID(reader, NULL, 0);
Inferring TPASS from the child reaching 'Z' state and reaping it with
SAFE_WAITPID(reader, NULL, 0) hides abnormal child termination. Call
tst_res(TPASS, "Listener answered the event") at the end of
answer_one_event() in the child, and only call SAFE_WAITPID(reader, NULL, 0)
after SAFE_KILL(reader, SIGKILL), letting the library reap the children on
the normal path.
> + /* Releases whatever is still queued, so the opener can finish. */
> + SAFE_CLOSE(fd_notify);
> + fd_notify = -1;
Setting fd_notify = -1 is redundant because SAFE_CLOSE() already resets its
argument to -1.
> +static void cleanup(void)
> +{
> + if (fd_notify >= 0)
> + SAFE_CLOSE(fd_notify);
> +}
Use "if (fd_notify != -1)" instead of "if (fd_notify >= 0)".
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
More information about the ltp
mailing list