[LTP] [PATCH 1/5] fanotify20: Allow FAN_REPORT_PIDFD with FAN_REPORT_TID on v7.2+
AnonymeMeow
anonymemeow@gmail.com
Mon Jun 15 20:06:25 CEST 2026
fanotify_init() used to reject FAN_REPORT_PIDFD combined with
FAN_REPORT_TID with EINVAL. Since Linux v7.2, fanotify supports
reporting pidfds for thread IDs, so this combination is expected to
succeed.
Keep expecting EINVAL on older kernels and adjust the test expectation
based on the running kernel version.
Signed-off-by: AnonymeMeow <anonymemeow@gmail.com>
---
.../kernel/syscalls/fanotify/fanotify20.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/testcases/kernel/syscalls/fanotify/fanotify20.c b/testcases/kernel/syscalls/fanotify/fanotify20.c
index b32ecf6aa..9a78f6ff0 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify20.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify20.c
@@ -8,13 +8,14 @@
/*\
* This source file contains a test case which ensures that the
- * :manpage:`fanotify(7)` API returns an expected error code when provided an
- * invalid initialization flag alongside FAN_REPORT_PIDFD. Additionally, it
- * checks that the operability with existing FAN_REPORT_* flags is maintained
- * and functioning as intended.
+ * :manpage:`fanotify(7)` API returns an expected error code when provided
+ * unsupported initialization flags, e.g. FAN_REPORT_PIDFD combined with
+ * FAN_REPORT_TID. Additionally, it checks that the operability with
+ * supported FAN_REPORT_* flags is maintained and functioning as intended.
*
* NOTE: FAN_REPORT_PIDFD support was added in v5.15-rc1 in
* af579beb666a ("fanotify: add pidfd support to the fanotify API").
+ * FAN_REPORT_PIDFD combined with FAN_REPORT_TID is supported since v7.2-rc1.
*/
#define _GNU_SOURCE
@@ -26,8 +27,10 @@
#define MOUNT_PATH "fs_mnt"
#define FLAGS_DESC(x) .flags = x, .desc = #x
+#define PIDFD_TID_FLAGS (FAN_REPORT_PIDFD | FAN_REPORT_TID)
static int fd;
+static int thread_pidfd_supported;
static struct test_case_t {
unsigned int flags;
@@ -51,17 +54,21 @@ static void do_setup(void)
*/
REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_PIDFD,
MOUNT_PATH);
+
+ thread_pidfd_supported = tst_kvercmp(7, 2, 0) >= 0;
}
static void do_test(unsigned int i)
{
struct test_case_t *tc = &test_cases[i];
+ int exp_errno = (tc->flags & PIDFD_TID_FLAGS) == PIDFD_TID_FLAGS &&
+ thread_pidfd_supported ? 0 : tc->exp_errno;
- tst_res(TINFO, "Test %s on %s", tc->exp_errno ? "fail" : "pass",
+ tst_res(TINFO, "Test %s on %s", exp_errno ? "fail" : "pass",
tc->desc);
TST_EXP_FD_OR_FAIL(fd = fanotify_init(tc->flags, O_RDONLY),
- tc->exp_errno);
+ exp_errno);
if (fd > 0)
SAFE_CLOSE(fd);
--
2.54.0
More information about the ltp
mailing list