[LTP] [PATCH 3/4] fanotify24: Add test for FAN_PRE_ACCESS and FAN_DENY_ERRNO
Heiko Carstens
hca@linux.ibm.com
Fri Feb 28 21:11:17 CET 2025
On Mon, Feb 10, 2025 at 04:13:15PM +0100, Amir Goldstein wrote:
> Fork the test fanotify24 from test fanotify03, replacing the
> permission event FAN_ACCESS_PERM with the new pre-content event
> FAN_PRE_ACCESS.
>
> The test is changed to use class FAN_CLASS_PRE_CONTENT, which is
> required for FAN_PRE_ACCESS and this class also enabled the response
> with cutomer error code FAN_DENY_ERRNO.
>
> Unlike FAN_ACCESS_PERM, FAN_PRE_ACCESS is also created on write()
> system call. The test case expected results are adjusted to
> respond with the default error (EPERM) to open() and write() and
> to respond with custom errors (EIO, EBUSY) to read() and execve().
>
> Not all fs support pre-content events, so run on all filesystems
> to excercise FAN_PRE_ACCESS on all supported filesystems.
>
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
> include/lapi/fanotify.h | 7 +
> runtest/syscalls | 1 +
> testcases/kernel/syscalls/fanotify/.gitignore | 1 +
> testcases/kernel/syscalls/fanotify/fanotify.h | 3 +
> .../kernel/syscalls/fanotify/fanotify24.c | 433 ++++++++++++++++++
> 5 files changed, 445 insertions(+)
> create mode 100644 testcases/kernel/syscalls/fanotify/fanotify24.c
>
> diff --git a/include/lapi/fanotify.h b/include/lapi/fanotify.h
> index e5b930f4e..9076685e8 100644
> --- a/include/lapi/fanotify.h
> +++ b/include/lapi/fanotify.h
> @@ -124,6 +124,13 @@
> #define FAN_EPIDFD -2
> #endif
>
> +/* errno other than EPERM can specified in upper byte of deny response */
> +#ifndef FAN_DENY_ERRNO
> +#define FAN_ERRNO(err) (((((__u32)(err)) & 0xff) << 24))
> +#define FAN_DENY_ERRNO(err) (FAN_DENY | FAN_ERRNO(err))
> +#define FAN_RESPONSE_ERRNO(res) ((int)((res) >> 24))
> +#endif
> +
This does not work with latest+greatest kernel headers since there
FAN_DENY_ERRNO is defined but FAN_RESPONSE_ERRNO is not. Therefore
this ends up in a compile error:
fanotify24.c: In function ‘expected_errno’:
fanotify24.c:166:24: error: implicit declaration of function ‘FAN_RESPONSE_ERRNO’; did you mean ‘FAN_DENY_ERRNO’? [-Wimplicit-function-declaration]
166 | return FAN_RESPONSE_ERRNO(response);
| ^~~~~~~~~~~~~~~~~~
| FAN_DENY_ERRNO
FWIW, converting the above to:
/* errno other than EPERM can specified in upper byte of deny response */
#ifndef FAN_DENY_ERRNO
#define FAN_ERRNO(err) (((((__u32)(err)) & 0xff) << 24))
#define FAN_DENY_ERRNO(err) (FAN_DENY | FAN_ERRNO(err))
#endif
#ifndef FAN_RESPONSE_ERRNO
#define FAN_RESPONSE_ERRNO(res) ((int)((res) >> 24))
#endif
works for me.
More information about the ltp
mailing list