[LTP] fanotify: prepare tests for thread pidfd reporting

linuxtestproject.agent@gmail.com linuxtestproject.agent@gmail.com
Wed May 27 11:53:40 CEST 2026


Hi AnonymeMeow,

On Wed May 27 2026, AnonymeMeow wrote:
> fanotify: prepare tests for thread pidfd reporting

Commit message body is an email exchange transcript rather than a clean
description of what the patch does and why. Please rewrite it as a
standalone commit message.

---

> diff --git a/include/lapi/pidfd.h b/include/lapi/pidfd.h

PIDFD_THREAD is used in fanotify21.c but is not defined in
include/lapi/pidfd.h. On systems with kernel headers older than 6.9
this will fail to compile. Add a fallback:

  #ifndef PIDFD_THREAD
  # define PIDFD_THREAD O_EXCL
  #endif

---

> diff --git a/testcases/kernel/syscalls/fanotify/fanotify20.c b/...

[...]

> +unsigned int needs_thread_pidfd;

Other boolean-like fields in test_case_t use int. Make this int for
consistency.

[...]

The file-level docstring says the test "ensures that the fanotify(7) API
returns an expected error code when provided an invalid initialization
flag". The new third test case behaves differently depending on kernel
support (may expect success). Update the docstring.

---

> diff --git a/testcases/kernel/syscalls/fanotify/fanotify21.c b/...

[...]

> +if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
> +tst_brk(TBROK, "child process terminated incorrectly");
> +

Trailing whitespace on the blank line above.

[...]

> +static pthread_t do_pthread_create(int want_pidfd_err)
> +{
[...]
> +SAFE_PTHREAD_JOIN(worker, (void **)&status);
> +if (status != 0)

status is int (4 bytes) but pthread_join writes a void* (8 bytes on
64-bit) at that address, corrupting the stack. Use NULL since the return
value is not needed:

  SAFE_PTHREAD_JOIN(worker, NULL);

[...]

> +if (tc->trigger_in_child && !tc->want_pidfd_err) {
> +int status;
> +TST_CHECKPOINT_WAKE(0);
> +if (TST_VARIANT_PIDFD_THREAD) {
> +SAFE_PTHREAD_JOIN(worker_id.pthread_id, (void **)&status);
> +if (status != 0)

Same bug: (void **)&status writes 8 bytes to a 4-byte int. Use NULL or
a void* variable here too.

---

Needs revision:
- Add PIDFD_THREAD fallback to include/lapi/pidfd.h
- Fix SAFE_PTHREAD_JOIN (void **)&status type mismatch in both call sites
- Clean up commit message
- Update fanotify20 docstring to cover the new kernel-conditional test case
- Fix trailing whitespace and needs_thread_pidfd type

---
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