* [LTP] [PATCH 0/3] fanotify tests update for 6.14-rc7
@ 2025-03-19 19:27 Amir Goldstein
2025-03-19 19:27 ` [LTP] [PATCH 1/3] fanotify24: remove redundant event_count field Amir Goldstein
` (2 more replies)
0 siblings, 3 replies; 14+ messages in thread
From: Amir Goldstein @ 2025-03-19 19:27 UTC (permalink / raw)
To: Petr Vorel; +Cc: Jan Kara, ltp
Petr,
6.14-rc7 had a minor change of semantics for pre-conent events.
This change adapts the pre-content event tests to the latest
semantics.
There is no git tag annotation, because the kernel fix is before
a final kernel release, so no backporting is expected.
Thanks,
Amir.
Amir Goldstein (3):
fanotify24: remove redundant event_count field
fanotify24: print range info for pre-content events
fanotify24: add mmap() and user page fault to test
configure.ac | 3 +-
include/lapi/fanotify.h | 12 +++
.../kernel/syscalls/fanotify/fanotify24.c | 90 ++++++++++++++-----
3 files changed, 82 insertions(+), 23 deletions(-)
--
2.34.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* [LTP] [PATCH 1/3] fanotify24: remove redundant event_count field
2025-03-19 19:27 [LTP] [PATCH 0/3] fanotify tests update for 6.14-rc7 Amir Goldstein
@ 2025-03-19 19:27 ` Amir Goldstein
2025-03-24 13:23 ` Jan Kara
2025-03-19 19:27 ` [LTP] [PATCH 2/3] fanotify24: print range info for pre-content events Amir Goldstein
2025-03-19 19:27 ` [LTP] [PATCH 3/3] fanotify24: add mmap() and user page fault to test Amir Goldstein
2 siblings, 1 reply; 14+ messages in thread
From: Amir Goldstein @ 2025-03-19 19:27 UTC (permalink / raw)
To: Petr Vorel; +Cc: Jan Kara, ltp
treat the event-set as a null terminated array.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
.../kernel/syscalls/fanotify/fanotify24.c | 31 +++++++++----------
1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/testcases/kernel/syscalls/fanotify/fanotify24.c b/testcases/kernel/syscalls/fanotify/fanotify24.c
index 8a448ea50..539f74137 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify24.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify24.c
@@ -60,13 +60,12 @@ static struct tcase {
const char *tname;
struct fanotify_mark_type mark;
unsigned long long mask;
- int event_count;
struct event event_set[EVENT_SET_MAX];
} tcases[] = {
{
"inode mark, FAN_OPEN_PERM | FAN_PRE_ACCESS events",
INIT_FANOTIFY_MARK_TYPE(INODE),
- FAN_OPEN_PERM | FAN_PRE_ACCESS, 4,
+ FAN_OPEN_PERM | FAN_PRE_ACCESS,
{
{FAN_OPEN_PERM, FAN_ALLOW},
{FAN_PRE_ACCESS, FAN_DENY},
@@ -77,7 +76,7 @@ static struct tcase {
{
"inode mark, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
INIT_FANOTIFY_MARK_TYPE(INODE),
- FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM, 3,
+ FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
{
{FAN_PRE_ACCESS, FAN_DENY},
{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
@@ -87,7 +86,7 @@ static struct tcase {
{
"mount mark, FAN_OPEN_PERM | FAN_PRE_ACCESS events",
INIT_FANOTIFY_MARK_TYPE(MOUNT),
- FAN_OPEN_PERM | FAN_PRE_ACCESS, 4,
+ FAN_OPEN_PERM | FAN_PRE_ACCESS,
{
{FAN_OPEN_PERM, FAN_ALLOW},
{FAN_PRE_ACCESS, FAN_DENY},
@@ -98,7 +97,7 @@ static struct tcase {
{
"mount mark, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
INIT_FANOTIFY_MARK_TYPE(MOUNT),
- FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM, 3,
+ FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
{
{FAN_PRE_ACCESS, FAN_DENY},
{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
@@ -108,7 +107,7 @@ static struct tcase {
{
"filesystem mark, FAN_OPEN_PERM | FAN_PRE_ACCESS events",
INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
- FAN_OPEN_PERM | FAN_PRE_ACCESS, 4,
+ FAN_OPEN_PERM | FAN_PRE_ACCESS,
{
{FAN_OPEN_PERM, FAN_ALLOW},
{FAN_PRE_ACCESS, FAN_DENY},
@@ -119,7 +118,7 @@ static struct tcase {
{
"filesystem mark, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
- FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM, 3,
+ FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
{
{FAN_PRE_ACCESS, FAN_DENY},
{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
@@ -129,7 +128,7 @@ static struct tcase {
{
"parent watching children, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
INIT_FANOTIFY_MARK_TYPE(PARENT),
- FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM | FAN_EVENT_ON_CHILD, 3,
+ FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM | FAN_EVENT_ON_CHILD,
{
{FAN_PRE_ACCESS, FAN_DENY},
{FAN_PRE_ACCESS, FAN_DENY},
@@ -139,14 +138,14 @@ static struct tcase {
{
"parent not watching children, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
INIT_FANOTIFY_MARK_TYPE(PARENT),
- FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM, 0,
+ FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
{
}
},
{
"inode mark, FAN_PRE_ACCESS event allowed",
INIT_FANOTIFY_MARK_TYPE(INODE),
- FAN_PRE_ACCESS, 1,
+ FAN_PRE_ACCESS,
{
/* This allows multiple FAN_PRE_ACCESS events */
{FAN_PRE_ACCESS, FAN_ALLOW},
@@ -225,7 +224,7 @@ static void generate_events(struct tcase *tc)
*/
if (!exp_errno) {
fd = SAFE_OPEN(FILE_EXEC_PATH, O_RDWR);
- if (!tc->event_count)
+ if (!tc->event_set[0].mask)
exp_errno = ETXTBSY;
}
@@ -335,10 +334,10 @@ static void test_fanotify(unsigned int n)
/*
* Process events
*
- * tc->count + 1 is to let read() wait for child process to exit
- * and to accomodate for extra access events
+ * even if we do not expect another event, let read() wait for child
+ * process to exit and accomodate for multiple access events
*/
- while (test_num < tc->event_count + 1 && fd_notify != -1) {
+ while (test_num < EVENT_SET_MAX && fd_notify != -1) {
struct fanotify_event_metadata *event;
if (i == len) {
@@ -363,7 +362,7 @@ static void test_fanotify(unsigned int n)
* generate an unknown number of access permission events if they
* are allowed.
*/
- if (test_num > 0 && test_num == tc->event_count &&
+ if (test_num > 0 && !event_set[test_num].mask &&
event_set[test_num-1].response == FAN_ALLOW)
test_num--;
@@ -418,7 +417,7 @@ static void test_fanotify(unsigned int n)
test_num++;
}
- for (; test_num < tc->event_count; test_num++) {
+ for (; event_set[test_num].mask && test_num < EVENT_SET_MAX; test_num++) {
tst_res(TFAIL, "didn't get event: mask=%llx",
event_set[test_num].mask);
--
2.34.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [LTP] [PATCH 2/3] fanotify24: print range info for pre-content events
2025-03-19 19:27 [LTP] [PATCH 0/3] fanotify tests update for 6.14-rc7 Amir Goldstein
2025-03-19 19:27 ` [LTP] [PATCH 1/3] fanotify24: remove redundant event_count field Amir Goldstein
@ 2025-03-19 19:27 ` Amir Goldstein
2025-03-26 15:04 ` Jan Kara
2025-03-19 19:27 ` [LTP] [PATCH 3/3] fanotify24: add mmap() and user page fault to test Amir Goldstein
2 siblings, 1 reply; 14+ messages in thread
From: Amir Goldstein @ 2025-03-19 19:27 UTC (permalink / raw)
To: Petr Vorel; +Cc: Jan Kara, ltp
range info is expected only for pre-content events
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
configure.ac | 3 ++-
include/lapi/fanotify.h | 12 ++++++++++++
.../kernel/syscalls/fanotify/fanotify24.c | 18 ++++++++++++++++++
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index 344b2ae2c..9b9883eac 100644
--- a/configure.ac
+++ b/configure.ac
@@ -179,7 +179,8 @@ AC_CHECK_TYPES([enum kcmp_type],,,[#include <linux/kcmp.h>])
AC_CHECK_TYPES([struct acct_v3],,,[#include <sys/acct.h>])
AC_CHECK_TYPES([struct af_alg_iv, struct sockaddr_alg],,,[# include <linux/if_alg.h>])
AC_CHECK_TYPES([struct fanotify_event_info_fid, struct fanotify_event_info_error,
- struct fanotify_event_info_header, struct fanotify_event_info_pidfd],,,[#include <sys/fanotify.h>])
+ struct fanotify_event_info_header, struct fanotify_event_info_pidfd,
+ struct fanotify_event_info_range],,,[#include <sys/fanotify.h>])
AC_CHECK_TYPES([struct file_clone_range],,,[#include <linux/fs.h>])
AC_CHECK_TYPES([struct file_dedupe_range],,,[#include <linux/fs.h>])
diff --git a/include/lapi/fanotify.h b/include/lapi/fanotify.h
index 9076685e8..76907ea5f 100644
--- a/include/lapi/fanotify.h
+++ b/include/lapi/fanotify.h
@@ -178,6 +178,9 @@ typedef struct {
#ifndef FAN_EVENT_INFO_TYPE_ERROR
#define FAN_EVENT_INFO_TYPE_ERROR 5
#endif
+#ifndef FAN_EVENT_INFO_TYPE_RANGE
+#define FAN_EVENT_INFO_TYPE_RANGE 6
+#endif
#ifndef FAN_EVENT_INFO_TYPE_OLD_DFID_NAME
#define FAN_EVENT_INFO_TYPE_OLD_DFID_NAME 10
@@ -217,6 +220,15 @@ struct fanotify_event_info_error {
};
#endif /* HAVE_STRUCT_FANOTIFY_EVENT_INFO_ERROR */
+#ifndef HAVE_STRUCT_FANOTIFY_EVENT_INFO_RANGE
+struct fanotify_event_info_range {
+ struct fanotify_event_info_header hdr;
+ __u32 pad;
+ __u64 offset;
+ __u64 count;
+};
+#endif /* HAVE_STRUCT_FANOTIFY_EVENT_INFO_RANGE */
+
/* NOTE: only for struct fanotify_event_info_fid */
#ifdef HAVE_STRUCT_FANOTIFY_EVENT_INFO_FID_FSID___VAL
# define FSID_VAL_MEMBER(fsid, i) (fsid.__val[i])
diff --git a/testcases/kernel/syscalls/fanotify/fanotify24.c b/testcases/kernel/syscalls/fanotify/fanotify24.c
index 539f74137..2d2479b39 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify24.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify24.c
@@ -339,6 +339,7 @@ static void test_fanotify(unsigned int n)
*/
while (test_num < EVENT_SET_MAX && fd_notify != -1) {
struct fanotify_event_metadata *event;
+ struct fanotify_event_info_range *range;
if (i == len) {
/* Get more events */
@@ -367,6 +368,7 @@ static void test_fanotify(unsigned int n)
test_num--;
event = (struct fanotify_event_metadata *)&event_buf[i];
+ range = (struct fanotify_event_info_range *)(event + 1);
/* Permission events cannot be merged, so the event mask
* reported should exactly match the event mask within the
* event set.
@@ -386,6 +388,22 @@ static void test_fanotify(unsigned int n)
(unsigned int)event->pid,
(unsigned int)child_pid,
event->fd);
+ } else if (event->mask & LTP_PRE_CONTENT_EVENTS) {
+ if (range->hdr.info_type != FAN_EVENT_INFO_TYPE_RANGE) {
+ tst_res(TFAIL,
+ "got event: mask=%llx pid=%u fd=%d "
+ "(expected range info)",
+ (unsigned long long)event->mask,
+ (unsigned int)event->pid,
+ event->fd);
+ } else {
+ tst_res(TPASS,
+ "got event: mask=%llx pid=%u fd=%d "
+ "offset=%llu count=%llu",
+ (unsigned long long)event->mask,
+ (unsigned int)event->pid, event->fd,
+ range->offset, range->count);
+ }
} else {
tst_res(TPASS,
"got event: mask=%llx pid=%u fd=%d",
--
2.34.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [LTP] [PATCH 3/3] fanotify24: add mmap() and user page fault to test
2025-03-19 19:27 [LTP] [PATCH 0/3] fanotify tests update for 6.14-rc7 Amir Goldstein
2025-03-19 19:27 ` [LTP] [PATCH 1/3] fanotify24: remove redundant event_count field Amir Goldstein
2025-03-19 19:27 ` [LTP] [PATCH 2/3] fanotify24: print range info for pre-content events Amir Goldstein
@ 2025-03-19 19:27 ` Amir Goldstein
2025-03-20 17:00 ` Petr Vorel
2025-03-26 15:08 ` Jan Kara
2 siblings, 2 replies; 14+ messages in thread
From: Amir Goldstein @ 2025-03-19 19:27 UTC (permalink / raw)
To: Petr Vorel; +Cc: Jan Kara, ltp
Commit 066e053fe208a ("fsnotify: add pre-content hooks on mmap()")
in 6.14-rc7 added a pre-content hooh in mmap() before the final release
of the fsnotify pre-content event feature.
To test pre-content hook on mmap(), increase the size of the test file
to 101 pages use mmap() to setup a buffer from the end of the test file.
Change some of the test cases to allow the write() and use this buffer
as the input buffer to write(), which tests deadlock avoidance by
suppresing pre-content hook on user page faults.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
.../kernel/syscalls/fanotify/fanotify24.c | 41 ++++++++++++++++---
1 file changed, 35 insertions(+), 6 deletions(-)
diff --git a/testcases/kernel/syscalls/fanotify/fanotify24.c b/testcases/kernel/syscalls/fanotify/fanotify24.c
index 2d2479b39..3a76f2c1b 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify24.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify24.c
@@ -46,6 +46,7 @@
static char fname[BUF_SIZE];
static char buf[BUF_SIZE];
static volatile int fd_notify;
+static size_t page_sz;
static pid_t child_pid;
@@ -68,7 +69,8 @@ static struct tcase {
FAN_OPEN_PERM | FAN_PRE_ACCESS,
{
{FAN_OPEN_PERM, FAN_ALLOW},
- {FAN_PRE_ACCESS, FAN_DENY},
+ {FAN_PRE_ACCESS, FAN_ALLOW},
+ {FAN_PRE_ACCESS, FAN_ALLOW},
{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
{FAN_OPEN_PERM, FAN_DENY_ERRNO(EBUSY)}
}
@@ -78,6 +80,7 @@ static struct tcase {
INIT_FANOTIFY_MARK_TYPE(INODE),
FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
{
+ {FAN_PRE_ACCESS, FAN_ALLOW},
{FAN_PRE_ACCESS, FAN_DENY},
{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
{FAN_OPEN_EXEC_PERM, FAN_DENY_ERRNO(EBUSY)}
@@ -89,7 +92,8 @@ static struct tcase {
FAN_OPEN_PERM | FAN_PRE_ACCESS,
{
{FAN_OPEN_PERM, FAN_ALLOW},
- {FAN_PRE_ACCESS, FAN_DENY},
+ {FAN_PRE_ACCESS, FAN_ALLOW},
+ {FAN_PRE_ACCESS, FAN_ALLOW},
{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
{FAN_OPEN_PERM, FAN_DENY_ERRNO(EBUSY)}
}
@@ -99,6 +103,7 @@ static struct tcase {
INIT_FANOTIFY_MARK_TYPE(MOUNT),
FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
{
+ {FAN_PRE_ACCESS, FAN_ALLOW},
{FAN_PRE_ACCESS, FAN_DENY},
{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
{FAN_OPEN_EXEC_PERM, FAN_DENY_ERRNO(EBUSY)}
@@ -110,7 +115,8 @@ static struct tcase {
FAN_OPEN_PERM | FAN_PRE_ACCESS,
{
{FAN_OPEN_PERM, FAN_ALLOW},
- {FAN_PRE_ACCESS, FAN_DENY},
+ {FAN_PRE_ACCESS, FAN_ALLOW},
+ {FAN_PRE_ACCESS, FAN_ALLOW},
{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
{FAN_OPEN_PERM, FAN_DENY_ERRNO(EBUSY)}
}
@@ -120,6 +126,7 @@ static struct tcase {
INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
{
+ {FAN_PRE_ACCESS, FAN_ALLOW},
{FAN_PRE_ACCESS, FAN_DENY},
{FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
{FAN_OPEN_EXEC_PERM, FAN_DENY_ERRNO(EBUSY)}
@@ -130,6 +137,7 @@ static struct tcase {
INIT_FANOTIFY_MARK_TYPE(PARENT),
FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM | FAN_EVENT_ON_CHILD,
{
+ {FAN_PRE_ACCESS, FAN_ALLOW},
{FAN_PRE_ACCESS, FAN_DENY},
{FAN_PRE_ACCESS, FAN_DENY},
{FAN_OPEN_EXEC_PERM, FAN_DENY}
@@ -169,6 +177,7 @@ static int expected_errno(unsigned int response)
static void generate_events(struct tcase *tc)
{
int fd;
+ char *addr;
char *const argv[] = {FILE_EXEC_PATH, NULL};
struct event *event = tc->event_set;
int exp_ret, exp_errno = 0;
@@ -186,8 +195,25 @@ static void generate_events(struct tcase *tc)
exp_ret = exp_errno ? -1 : 1;
errno = 0;
- /* FAN_PRE_ACCESS events are reported also on write */
- if (write(fd, fname, 1) != exp_ret || errno != exp_errno) {
+ /*
+ * FAN_PRE_ACCESS events are reported on map() and write(), but should
+ * not be reported when faulting in the user page at offset page_sz*100
+ * that is used as an input buffer to the write() syscall.
+ */
+ addr = SAFE_MMAP(NULL, page_sz, PROT_READ, MAP_PRIVATE, fd, page_sz*100);
+ if (!addr || errno != exp_errno) {
+ tst_res(TFAIL, "mmap() got errno %d (expected %d)", errno, exp_errno);
+ exit(3);
+ } else if (errno == exp_errno) {
+ tst_res(TINFO, "mmap() got errno %d as expected", errno);
+ }
+
+ exp_errno = expected_errno(event->response);
+ event++;
+
+ exp_ret = exp_errno ? -1 : 1;
+ errno = 0;
+ if (write(fd, addr, 1) != exp_ret || errno != exp_errno) {
tst_res(TFAIL, "write() got errno %d (expected %d)", errno, exp_errno);
exit(3);
} else if (errno == exp_errno) {
@@ -199,7 +225,7 @@ static void generate_events(struct tcase *tc)
exp_errno = expected_errno(event->response);
event++;
- exp_ret = exp_errno ? -1 : 1;
+ exp_ret = exp_errno ? -1 : BUF_SIZE;
errno = 0;
if (read(fd, buf, BUF_SIZE) != exp_ret || errno != exp_errno) {
tst_res(TFAIL, "read() got errno %d (expected %d)", errno, exp_errno);
@@ -449,8 +475,11 @@ static void test_fanotify(unsigned int n)
static void setup(void)
{
+ page_sz = getpagesize();
+
sprintf(fname, MOUNT_PATH"/fname_%d", getpid());
SAFE_FILE_PRINTF(fname, "1");
+ SAFE_TRUNCATE(fname, page_sz*101);
REQUIRE_FANOTIFY_EVENTS_SUPPORTED_ON_FS(FAN_CLASS_PRE_CONTENT, FAN_MARK_FILESYSTEM,
FAN_PRE_ACCESS, fname);
--
2.34.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH 3/3] fanotify24: add mmap() and user page fault to test
2025-03-19 19:27 ` [LTP] [PATCH 3/3] fanotify24: add mmap() and user page fault to test Amir Goldstein
@ 2025-03-20 17:00 ` Petr Vorel
2025-03-20 17:42 ` Amir Goldstein
2025-03-26 15:08 ` Jan Kara
1 sibling, 1 reply; 14+ messages in thread
From: Petr Vorel @ 2025-03-20 17:00 UTC (permalink / raw)
To: Amir Goldstein; +Cc: Jan Kara, ltp
Hi Amir,
> Commit 066e053fe208a ("fsnotify: add pre-content hooks on mmap()")
> in 6.14-rc7 added a pre-content hooh in mmap() before the final release
> of the fsnotify pre-content event feature.
> To test pre-content hook on mmap(), increase the size of the test file
> to 101 pages use mmap() to setup a buffer from the end of the test file.
> Change some of the test cases to allow the write() and use this buffer
> as the input buffer to write(), which tests deadlock avoidance by
> suppresing pre-content hook on user page faults.
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
> .../kernel/syscalls/fanotify/fanotify24.c | 41 ++++++++++++++++---
> 1 file changed, 35 insertions(+), 6 deletions(-)
> diff --git a/testcases/kernel/syscalls/fanotify/fanotify24.c b/testcases/kernel/syscalls/fanotify/fanotify24.c
> index 2d2479b39..3a76f2c1b 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify24.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify24.c
> @@ -46,6 +46,7 @@
> static char fname[BUF_SIZE];
> static char buf[BUF_SIZE];
> static volatile int fd_notify;
> +static size_t page_sz;
> static pid_t child_pid;
> @@ -68,7 +69,8 @@ static struct tcase {
> FAN_OPEN_PERM | FAN_PRE_ACCESS,
> {
> {FAN_OPEN_PERM, FAN_ALLOW},
> - {FAN_PRE_ACCESS, FAN_DENY},
> + {FAN_PRE_ACCESS, FAN_ALLOW},
> + {FAN_PRE_ACCESS, FAN_ALLOW},
If I understand correctly, these doubled FAN_PRE_ACCESS, FAN_ALLOW are for
reusing the write buffer, right? Obviously it's needed but on the first look it
looks like error.
<snip>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH 3/3] fanotify24: add mmap() and user page fault to test
2025-03-20 17:00 ` Petr Vorel
@ 2025-03-20 17:42 ` Amir Goldstein
2025-03-20 18:18 ` Petr Vorel
0 siblings, 1 reply; 14+ messages in thread
From: Amir Goldstein @ 2025-03-20 17:42 UTC (permalink / raw)
To: Petr Vorel; +Cc: Jan Kara, ltp
On Thu, Mar 20, 2025 at 6:00 PM Petr Vorel <pvorel@suse.cz> wrote:
>
> Hi Amir,
>
> > Commit 066e053fe208a ("fsnotify: add pre-content hooks on mmap()")
> > in 6.14-rc7 added a pre-content hooh in mmap() before the final release
> > of the fsnotify pre-content event feature.
>
> > To test pre-content hook on mmap(), increase the size of the test file
> > to 101 pages use mmap() to setup a buffer from the end of the test file.
>
> > Change some of the test cases to allow the write() and use this buffer
> > as the input buffer to write(), which tests deadlock avoidance by
> > suppresing pre-content hook on user page faults.
>
> > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> > ---
> > .../kernel/syscalls/fanotify/fanotify24.c | 41 ++++++++++++++++---
> > 1 file changed, 35 insertions(+), 6 deletions(-)
>
> > diff --git a/testcases/kernel/syscalls/fanotify/fanotify24.c b/testcases/kernel/syscalls/fanotify/fanotify24.c
> > index 2d2479b39..3a76f2c1b 100644
> > --- a/testcases/kernel/syscalls/fanotify/fanotify24.c
> > +++ b/testcases/kernel/syscalls/fanotify/fanotify24.c
> > @@ -46,6 +46,7 @@
> > static char fname[BUF_SIZE];
> > static char buf[BUF_SIZE];
> > static volatile int fd_notify;
> > +static size_t page_sz;
>
> > static pid_t child_pid;
>
> > @@ -68,7 +69,8 @@ static struct tcase {
> > FAN_OPEN_PERM | FAN_PRE_ACCESS,
> > {
> > {FAN_OPEN_PERM, FAN_ALLOW},
> > - {FAN_PRE_ACCESS, FAN_DENY},
> > + {FAN_PRE_ACCESS, FAN_ALLOW},
> > + {FAN_PRE_ACCESS, FAN_ALLOW},
>
> If I understand correctly, these doubled FAN_PRE_ACCESS, FAN_ALLOW are for
> reusing the write buffer, right? Obviously it's needed but on the first look it
> looks like error.
Sorry, this wasn't properly explained.
This change adds a test for pre-mmap events.
First of all, we added an mmap() call before the write(),
so we need to add another expected FAN_PRE_ACCESS
for the mmap() and we allow the mmap for all test cases.
Secondly, we Change some of the test cases to allow the write()
and use the mmaped buffer as the input buffer.
The reason that we allow the write() is to verify that we do not
get another FAN_PRE_ACCESS event from reading from the
mmaped input buffer.
Thanks,
Amir.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH 3/3] fanotify24: add mmap() and user page fault to test
2025-03-20 17:42 ` Amir Goldstein
@ 2025-03-20 18:18 ` Petr Vorel
0 siblings, 0 replies; 14+ messages in thread
From: Petr Vorel @ 2025-03-20 18:18 UTC (permalink / raw)
To: Amir Goldstein; +Cc: Jan Kara, ltp
> On Thu, Mar 20, 2025 at 6:00 PM Petr Vorel <pvorel@suse.cz> wrote:
> > Hi Amir,
> > > Commit 066e053fe208a ("fsnotify: add pre-content hooks on mmap()")
> > > in 6.14-rc7 added a pre-content hooh in mmap() before the final release
> > > of the fsnotify pre-content event feature.
> > > To test pre-content hook on mmap(), increase the size of the test file
> > > to 101 pages use mmap() to setup a buffer from the end of the test file.
> > > Change some of the test cases to allow the write() and use this buffer
> > > as the input buffer to write(), which tests deadlock avoidance by
> > > suppresing pre-content hook on user page faults.
> > > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> > > ---
> > > .../kernel/syscalls/fanotify/fanotify24.c | 41 ++++++++++++++++---
> > > 1 file changed, 35 insertions(+), 6 deletions(-)
> > > diff --git a/testcases/kernel/syscalls/fanotify/fanotify24.c b/testcases/kernel/syscalls/fanotify/fanotify24.c
> > > index 2d2479b39..3a76f2c1b 100644
> > > --- a/testcases/kernel/syscalls/fanotify/fanotify24.c
> > > +++ b/testcases/kernel/syscalls/fanotify/fanotify24.c
> > > @@ -46,6 +46,7 @@
> > > static char fname[BUF_SIZE];
> > > static char buf[BUF_SIZE];
> > > static volatile int fd_notify;
> > > +static size_t page_sz;
> > > static pid_t child_pid;
> > > @@ -68,7 +69,8 @@ static struct tcase {
> > > FAN_OPEN_PERM | FAN_PRE_ACCESS,
> > > {
> > > {FAN_OPEN_PERM, FAN_ALLOW},
> > > - {FAN_PRE_ACCESS, FAN_DENY},
> > > + {FAN_PRE_ACCESS, FAN_ALLOW},
> > > + {FAN_PRE_ACCESS, FAN_ALLOW},
> > If I understand correctly, these doubled FAN_PRE_ACCESS, FAN_ALLOW are for
> > reusing the write buffer, right? Obviously it's needed but on the first look it
> > looks like error.
> Sorry, this wasn't properly explained.
> This change adds a test for pre-mmap events.
> First of all, we added an mmap() call before the write(),
> so we need to add another expected FAN_PRE_ACCESS
> for the mmap() and we allow the mmap for all test cases.
> Secondly, we Change some of the test cases to allow the write()
> and use the mmaped buffer as the input buffer.
> The reason that we allow the write() is to verify that we do not
> get another FAN_PRE_ACCESS event from reading from the
> mmaped input buffer.
Thanks for the explanation. It would deserve to update the commit message,
but it's probably obvious to Jan and I add link to lore before merging,
therefore maybe it's enough as is.
Anyway, whole patchset LGTM. Waiting till tomorrow before merging if Jan has
some input.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
> Thanks,
> Amir.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH 1/3] fanotify24: remove redundant event_count field
2025-03-19 19:27 ` [LTP] [PATCH 1/3] fanotify24: remove redundant event_count field Amir Goldstein
@ 2025-03-24 13:23 ` Jan Kara
2025-03-25 20:46 ` Petr Vorel
0 siblings, 1 reply; 14+ messages in thread
From: Jan Kara @ 2025-03-24 13:23 UTC (permalink / raw)
To: Amir Goldstein; +Cc: Jan Kara, ltp
On Wed 19-03-25 20:27:40, Amir Goldstein wrote:
> treat the event-set as a null terminated array.
>
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> .../kernel/syscalls/fanotify/fanotify24.c | 31 +++++++++----------
> 1 file changed, 15 insertions(+), 16 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/fanotify/fanotify24.c b/testcases/kernel/syscalls/fanotify/fanotify24.c
> index 8a448ea50..539f74137 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify24.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify24.c
> @@ -60,13 +60,12 @@ static struct tcase {
> const char *tname;
> struct fanotify_mark_type mark;
> unsigned long long mask;
> - int event_count;
> struct event event_set[EVENT_SET_MAX];
> } tcases[] = {
> {
> "inode mark, FAN_OPEN_PERM | FAN_PRE_ACCESS events",
> INIT_FANOTIFY_MARK_TYPE(INODE),
> - FAN_OPEN_PERM | FAN_PRE_ACCESS, 4,
> + FAN_OPEN_PERM | FAN_PRE_ACCESS,
> {
> {FAN_OPEN_PERM, FAN_ALLOW},
> {FAN_PRE_ACCESS, FAN_DENY},
> @@ -77,7 +76,7 @@ static struct tcase {
> {
> "inode mark, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
> INIT_FANOTIFY_MARK_TYPE(INODE),
> - FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM, 3,
> + FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
> {
> {FAN_PRE_ACCESS, FAN_DENY},
> {FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
> @@ -87,7 +86,7 @@ static struct tcase {
> {
> "mount mark, FAN_OPEN_PERM | FAN_PRE_ACCESS events",
> INIT_FANOTIFY_MARK_TYPE(MOUNT),
> - FAN_OPEN_PERM | FAN_PRE_ACCESS, 4,
> + FAN_OPEN_PERM | FAN_PRE_ACCESS,
> {
> {FAN_OPEN_PERM, FAN_ALLOW},
> {FAN_PRE_ACCESS, FAN_DENY},
> @@ -98,7 +97,7 @@ static struct tcase {
> {
> "mount mark, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
> INIT_FANOTIFY_MARK_TYPE(MOUNT),
> - FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM, 3,
> + FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
> {
> {FAN_PRE_ACCESS, FAN_DENY},
> {FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
> @@ -108,7 +107,7 @@ static struct tcase {
> {
> "filesystem mark, FAN_OPEN_PERM | FAN_PRE_ACCESS events",
> INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
> - FAN_OPEN_PERM | FAN_PRE_ACCESS, 4,
> + FAN_OPEN_PERM | FAN_PRE_ACCESS,
> {
> {FAN_OPEN_PERM, FAN_ALLOW},
> {FAN_PRE_ACCESS, FAN_DENY},
> @@ -119,7 +118,7 @@ static struct tcase {
> {
> "filesystem mark, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
> INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
> - FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM, 3,
> + FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
> {
> {FAN_PRE_ACCESS, FAN_DENY},
> {FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
> @@ -129,7 +128,7 @@ static struct tcase {
> {
> "parent watching children, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
> INIT_FANOTIFY_MARK_TYPE(PARENT),
> - FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM | FAN_EVENT_ON_CHILD, 3,
> + FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM | FAN_EVENT_ON_CHILD,
> {
> {FAN_PRE_ACCESS, FAN_DENY},
> {FAN_PRE_ACCESS, FAN_DENY},
> @@ -139,14 +138,14 @@ static struct tcase {
> {
> "parent not watching children, FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM events",
> INIT_FANOTIFY_MARK_TYPE(PARENT),
> - FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM, 0,
> + FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
> {
> }
> },
> {
> "inode mark, FAN_PRE_ACCESS event allowed",
> INIT_FANOTIFY_MARK_TYPE(INODE),
> - FAN_PRE_ACCESS, 1,
> + FAN_PRE_ACCESS,
> {
> /* This allows multiple FAN_PRE_ACCESS events */
> {FAN_PRE_ACCESS, FAN_ALLOW},
> @@ -225,7 +224,7 @@ static void generate_events(struct tcase *tc)
> */
> if (!exp_errno) {
> fd = SAFE_OPEN(FILE_EXEC_PATH, O_RDWR);
> - if (!tc->event_count)
> + if (!tc->event_set[0].mask)
> exp_errno = ETXTBSY;
> }
>
> @@ -335,10 +334,10 @@ static void test_fanotify(unsigned int n)
> /*
> * Process events
> *
> - * tc->count + 1 is to let read() wait for child process to exit
> - * and to accomodate for extra access events
> + * even if we do not expect another event, let read() wait for child
> + * process to exit and accomodate for multiple access events
> */
> - while (test_num < tc->event_count + 1 && fd_notify != -1) {
> + while (test_num < EVENT_SET_MAX && fd_notify != -1) {
> struct fanotify_event_metadata *event;
>
> if (i == len) {
> @@ -363,7 +362,7 @@ static void test_fanotify(unsigned int n)
> * generate an unknown number of access permission events if they
> * are allowed.
> */
> - if (test_num > 0 && test_num == tc->event_count &&
> + if (test_num > 0 && !event_set[test_num].mask &&
> event_set[test_num-1].response == FAN_ALLOW)
> test_num--;
>
> @@ -418,7 +417,7 @@ static void test_fanotify(unsigned int n)
> test_num++;
> }
>
> - for (; test_num < tc->event_count; test_num++) {
> + for (; event_set[test_num].mask && test_num < EVENT_SET_MAX; test_num++) {
> tst_res(TFAIL, "didn't get event: mask=%llx",
> event_set[test_num].mask);
>
> --
> 2.34.1
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH 1/3] fanotify24: remove redundant event_count field
2025-03-24 13:23 ` Jan Kara
@ 2025-03-25 20:46 ` Petr Vorel
0 siblings, 0 replies; 14+ messages in thread
From: Petr Vorel @ 2025-03-25 20:46 UTC (permalink / raw)
To: Jan Kara; +Cc: ltp
Hi Amir, Jan,
> On Wed 19-03-25 20:27:40, Amir Goldstein wrote:
> > treat the event-set as a null terminated array.
> > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> Looks good. Feel free to add:
> Reviewed-by: Jan Kara <jack@suse.cz>
Thanks Jan, merged this one.
Amir, because Jan plans to have look on the remaining two, I'll wait for him.
Kind regards,
Petr
> Honza
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH 2/3] fanotify24: print range info for pre-content events
2025-03-19 19:27 ` [LTP] [PATCH 2/3] fanotify24: print range info for pre-content events Amir Goldstein
@ 2025-03-26 15:04 ` Jan Kara
2025-03-27 9:11 ` Amir Goldstein
0 siblings, 1 reply; 14+ messages in thread
From: Jan Kara @ 2025-03-26 15:04 UTC (permalink / raw)
To: Amir Goldstein; +Cc: Jan Kara, ltp
On Wed 19-03-25 20:27:41, Amir Goldstein wrote:
> range info is expected only for pre-content events
>
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Just one nit below. Otherwise feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
> diff --git a/testcases/kernel/syscalls/fanotify/fanotify24.c b/testcases/kernel/syscalls/fanotify/fanotify24.c
> index 539f74137..2d2479b39 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify24.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify24.c
> @@ -339,6 +339,7 @@ static void test_fanotify(unsigned int n)
> */
> while (test_num < EVENT_SET_MAX && fd_notify != -1) {
> struct fanotify_event_metadata *event;
> + struct fanotify_event_info_range *range;
>
> if (i == len) {
> /* Get more events */
> @@ -367,6 +368,7 @@ static void test_fanotify(unsigned int n)
> test_num--;
>
> event = (struct fanotify_event_metadata *)&event_buf[i];
> + range = (struct fanotify_event_info_range *)(event + 1);
> /* Permission events cannot be merged, so the event mask
> * reported should exactly match the event mask within the
> * event set.
> @@ -386,6 +388,22 @@ static void test_fanotify(unsigned int n)
> (unsigned int)event->pid,
> (unsigned int)child_pid,
> event->fd);
> + } else if (event->mask & LTP_PRE_CONTENT_EVENTS) {
You should probably check here that the event->len is sufficiently large to
contain the range info. Otherwise 'range' might point beyond the end of
event and result in odd behavior...
Honza
> + if (range->hdr.info_type != FAN_EVENT_INFO_TYPE_RANGE) {
> + tst_res(TFAIL,
> + "got event: mask=%llx pid=%u fd=%d "
> + "(expected range info)",
> + (unsigned long long)event->mask,
> + (unsigned int)event->pid,
> + event->fd);
> + } else {
> + tst_res(TPASS,
> + "got event: mask=%llx pid=%u fd=%d "
> + "offset=%llu count=%llu",
> + (unsigned long long)event->mask,
> + (unsigned int)event->pid, event->fd,
> + range->offset, range->count);
> + }
> } else {
> tst_res(TPASS,
> "got event: mask=%llx pid=%u fd=%d",
> --
> 2.34.1
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH 3/3] fanotify24: add mmap() and user page fault to test
2025-03-19 19:27 ` [LTP] [PATCH 3/3] fanotify24: add mmap() and user page fault to test Amir Goldstein
2025-03-20 17:00 ` Petr Vorel
@ 2025-03-26 15:08 ` Jan Kara
1 sibling, 0 replies; 14+ messages in thread
From: Jan Kara @ 2025-03-26 15:08 UTC (permalink / raw)
To: Amir Goldstein; +Cc: Jan Kara, ltp
On Wed 19-03-25 20:27:42, Amir Goldstein wrote:
> Commit 066e053fe208a ("fsnotify: add pre-content hooks on mmap()")
> in 6.14-rc7 added a pre-content hooh in mmap() before the final release
> of the fsnotify pre-content event feature.
>
> To test pre-content hook on mmap(), increase the size of the test file
> to 101 pages use mmap() to setup a buffer from the end of the test file.
>
> Change some of the test cases to allow the write() and use this buffer
> as the input buffer to write(), which tests deadlock avoidance by
> suppresing pre-content hook on user page faults.
>
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> .../kernel/syscalls/fanotify/fanotify24.c | 41 ++++++++++++++++---
> 1 file changed, 35 insertions(+), 6 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/fanotify/fanotify24.c b/testcases/kernel/syscalls/fanotify/fanotify24.c
> index 2d2479b39..3a76f2c1b 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify24.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify24.c
> @@ -46,6 +46,7 @@
> static char fname[BUF_SIZE];
> static char buf[BUF_SIZE];
> static volatile int fd_notify;
> +static size_t page_sz;
>
> static pid_t child_pid;
>
> @@ -68,7 +69,8 @@ static struct tcase {
> FAN_OPEN_PERM | FAN_PRE_ACCESS,
> {
> {FAN_OPEN_PERM, FAN_ALLOW},
> - {FAN_PRE_ACCESS, FAN_DENY},
> + {FAN_PRE_ACCESS, FAN_ALLOW},
> + {FAN_PRE_ACCESS, FAN_ALLOW},
> {FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
> {FAN_OPEN_PERM, FAN_DENY_ERRNO(EBUSY)}
> }
> @@ -78,6 +80,7 @@ static struct tcase {
> INIT_FANOTIFY_MARK_TYPE(INODE),
> FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
> {
> + {FAN_PRE_ACCESS, FAN_ALLOW},
> {FAN_PRE_ACCESS, FAN_DENY},
> {FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
> {FAN_OPEN_EXEC_PERM, FAN_DENY_ERRNO(EBUSY)}
> @@ -89,7 +92,8 @@ static struct tcase {
> FAN_OPEN_PERM | FAN_PRE_ACCESS,
> {
> {FAN_OPEN_PERM, FAN_ALLOW},
> - {FAN_PRE_ACCESS, FAN_DENY},
> + {FAN_PRE_ACCESS, FAN_ALLOW},
> + {FAN_PRE_ACCESS, FAN_ALLOW},
> {FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
> {FAN_OPEN_PERM, FAN_DENY_ERRNO(EBUSY)}
> }
> @@ -99,6 +103,7 @@ static struct tcase {
> INIT_FANOTIFY_MARK_TYPE(MOUNT),
> FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
> {
> + {FAN_PRE_ACCESS, FAN_ALLOW},
> {FAN_PRE_ACCESS, FAN_DENY},
> {FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
> {FAN_OPEN_EXEC_PERM, FAN_DENY_ERRNO(EBUSY)}
> @@ -110,7 +115,8 @@ static struct tcase {
> FAN_OPEN_PERM | FAN_PRE_ACCESS,
> {
> {FAN_OPEN_PERM, FAN_ALLOW},
> - {FAN_PRE_ACCESS, FAN_DENY},
> + {FAN_PRE_ACCESS, FAN_ALLOW},
> + {FAN_PRE_ACCESS, FAN_ALLOW},
> {FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
> {FAN_OPEN_PERM, FAN_DENY_ERRNO(EBUSY)}
> }
> @@ -120,6 +126,7 @@ static struct tcase {
> INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
> FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM,
> {
> + {FAN_PRE_ACCESS, FAN_ALLOW},
> {FAN_PRE_ACCESS, FAN_DENY},
> {FAN_PRE_ACCESS, FAN_DENY_ERRNO(EIO)},
> {FAN_OPEN_EXEC_PERM, FAN_DENY_ERRNO(EBUSY)}
> @@ -130,6 +137,7 @@ static struct tcase {
> INIT_FANOTIFY_MARK_TYPE(PARENT),
> FAN_PRE_ACCESS | FAN_OPEN_EXEC_PERM | FAN_EVENT_ON_CHILD,
> {
> + {FAN_PRE_ACCESS, FAN_ALLOW},
> {FAN_PRE_ACCESS, FAN_DENY},
> {FAN_PRE_ACCESS, FAN_DENY},
> {FAN_OPEN_EXEC_PERM, FAN_DENY}
> @@ -169,6 +177,7 @@ static int expected_errno(unsigned int response)
> static void generate_events(struct tcase *tc)
> {
> int fd;
> + char *addr;
> char *const argv[] = {FILE_EXEC_PATH, NULL};
> struct event *event = tc->event_set;
> int exp_ret, exp_errno = 0;
> @@ -186,8 +195,25 @@ static void generate_events(struct tcase *tc)
>
> exp_ret = exp_errno ? -1 : 1;
> errno = 0;
> - /* FAN_PRE_ACCESS events are reported also on write */
> - if (write(fd, fname, 1) != exp_ret || errno != exp_errno) {
> + /*
> + * FAN_PRE_ACCESS events are reported on map() and write(), but should
> + * not be reported when faulting in the user page at offset page_sz*100
> + * that is used as an input buffer to the write() syscall.
> + */
> + addr = SAFE_MMAP(NULL, page_sz, PROT_READ, MAP_PRIVATE, fd, page_sz*100);
> + if (!addr || errno != exp_errno) {
> + tst_res(TFAIL, "mmap() got errno %d (expected %d)", errno, exp_errno);
> + exit(3);
> + } else if (errno == exp_errno) {
> + tst_res(TINFO, "mmap() got errno %d as expected", errno);
> + }
> +
> + exp_errno = expected_errno(event->response);
> + event++;
> +
> + exp_ret = exp_errno ? -1 : 1;
> + errno = 0;
> + if (write(fd, addr, 1) != exp_ret || errno != exp_errno) {
> tst_res(TFAIL, "write() got errno %d (expected %d)", errno, exp_errno);
> exit(3);
> } else if (errno == exp_errno) {
> @@ -199,7 +225,7 @@ static void generate_events(struct tcase *tc)
> exp_errno = expected_errno(event->response);
> event++;
>
> - exp_ret = exp_errno ? -1 : 1;
> + exp_ret = exp_errno ? -1 : BUF_SIZE;
> errno = 0;
> if (read(fd, buf, BUF_SIZE) != exp_ret || errno != exp_errno) {
> tst_res(TFAIL, "read() got errno %d (expected %d)", errno, exp_errno);
> @@ -449,8 +475,11 @@ static void test_fanotify(unsigned int n)
>
> static void setup(void)
> {
> + page_sz = getpagesize();
> +
> sprintf(fname, MOUNT_PATH"/fname_%d", getpid());
> SAFE_FILE_PRINTF(fname, "1");
> + SAFE_TRUNCATE(fname, page_sz*101);
>
> REQUIRE_FANOTIFY_EVENTS_SUPPORTED_ON_FS(FAN_CLASS_PRE_CONTENT, FAN_MARK_FILESYSTEM,
> FAN_PRE_ACCESS, fname);
> --
> 2.34.1
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH 2/3] fanotify24: print range info for pre-content events
2025-03-26 15:04 ` Jan Kara
@ 2025-03-27 9:11 ` Amir Goldstein
2025-03-27 10:54 ` Petr Vorel
0 siblings, 1 reply; 14+ messages in thread
From: Amir Goldstein @ 2025-03-27 9:11 UTC (permalink / raw)
To: Jan Kara; +Cc: ltp
On Wed, Mar 26, 2025 at 4:04 PM Jan Kara <jack@suse.cz> wrote:
>
> On Wed 19-03-25 20:27:41, Amir Goldstein wrote:
> > range info is expected only for pre-content events
> >
> > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
>
> Just one nit below. Otherwise feel free to add:
>
> Reviewed-by: Jan Kara <jack@suse.cz>
>
> > diff --git a/testcases/kernel/syscalls/fanotify/fanotify24.c b/testcases/kernel/syscalls/fanotify/fanotify24.c
> > index 539f74137..2d2479b39 100644
> > --- a/testcases/kernel/syscalls/fanotify/fanotify24.c
> > +++ b/testcases/kernel/syscalls/fanotify/fanotify24.c
> > @@ -339,6 +339,7 @@ static void test_fanotify(unsigned int n)
> > */
> > while (test_num < EVENT_SET_MAX && fd_notify != -1) {
> > struct fanotify_event_metadata *event;
> > + struct fanotify_event_info_range *range;
> >
> > if (i == len) {
> > /* Get more events */
> > @@ -367,6 +368,7 @@ static void test_fanotify(unsigned int n)
> > test_num--;
> >
> > event = (struct fanotify_event_metadata *)&event_buf[i];
> > + range = (struct fanotify_event_info_range *)(event + 1);
> > /* Permission events cannot be merged, so the event mask
> > * reported should exactly match the event mask within the
> > * event set.
> > @@ -386,6 +388,22 @@ static void test_fanotify(unsigned int n)
> > (unsigned int)event->pid,
> > (unsigned int)child_pid,
> > event->fd);
> > + } else if (event->mask & LTP_PRE_CONTENT_EVENTS) {
>
> You should probably check here that the event->len is sufficiently large to
> contain the range info. Otherwise 'range' might point beyond the end of
> event and result in odd behavior...
>
Right. feel free to use the amended version below
> Honza
>
> > + if (range->hdr.info_type != FAN_EVENT_INFO_TYPE_RANGE) {
> > + tst_res(TFAIL,
> > + "got event: mask=%llx pid=%u fd=%d "
> > + "(expected range info)",
> > + (unsigned long long)event->mask,
> > + (unsigned int)event->pid,
> > + event->fd);
if (event->event_len < sizeof(*event) +
sizeof(*range) ||
range->hdr.info_type != FAN_EVENT_INFO_TYPE_RANGE) {
tst_res(TFAIL,
"got event: mask=%llx pid=%u
len=%d fd=%d "
"(expected range info)",
(unsigned long long)event->mask,
(unsigned int)event->pid,
(unsigned int)event->event_len,
event->fd);
Thanks,
Amir.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH 2/3] fanotify24: print range info for pre-content events
2025-03-27 9:11 ` Amir Goldstein
@ 2025-03-27 10:54 ` Petr Vorel
2025-03-27 17:15 ` Amir Goldstein
0 siblings, 1 reply; 14+ messages in thread
From: Petr Vorel @ 2025-03-27 10:54 UTC (permalink / raw)
To: Amir Goldstein; +Cc: Jan Kara, ltp
Hi Amir, Jan,
> > > @@ -386,6 +388,22 @@ static void test_fanotify(unsigned int n)
> > > (unsigned int)event->pid,
> > > (unsigned int)child_pid,
> > > event->fd);
> > > + } else if (event->mask & LTP_PRE_CONTENT_EVENTS) {
> > You should probably check here that the event->len is sufficiently large to
> > contain the range info. Otherwise 'range' might point beyond the end of
> > event and result in odd behavior...
> Right. feel free to use the amended version below
> > Honza
> > > + if (range->hdr.info_type != FAN_EVENT_INFO_TYPE_RANGE) {
> > > + tst_res(TFAIL,
> > > + "got event: mask=%llx pid=%u fd=%d "
> > > + "(expected range info)",
> > > + (unsigned long long)event->mask,
> > > + (unsigned int)event->pid,
> > > + event->fd);
> if (event->event_len < sizeof(*event) +
> sizeof(*range) ||
> range->hdr.info_type != FAN_EVENT_INFO_TYPE_RANGE) {
> tst_res(TFAIL,
> "got event: mask=%llx pid=%u
> len=%d fd=%d "
> "(expected range info)",
> (unsigned long long)event->mask,
> (unsigned int)event->pid,
> (unsigned int)event->event_len,
> event->fd);
Thanks! I dared instead of copy pasting to use fan_hsm branch from your fork.
Jan, thanks for the review!
Merged the rest of the pachset.
Kind regards,
Petr
> Thanks,
> Amir.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH 2/3] fanotify24: print range info for pre-content events
2025-03-27 10:54 ` Petr Vorel
@ 2025-03-27 17:15 ` Amir Goldstein
0 siblings, 0 replies; 14+ messages in thread
From: Amir Goldstein @ 2025-03-27 17:15 UTC (permalink / raw)
To: Petr Vorel; +Cc: Jan Kara, ltp
On Thu, Mar 27, 2025 at 11:54 AM Petr Vorel <pvorel@suse.cz> wrote:
>
> Hi Amir, Jan,
>
> > > > @@ -386,6 +388,22 @@ static void test_fanotify(unsigned int n)
> > > > (unsigned int)event->pid,
> > > > (unsigned int)child_pid,
> > > > event->fd);
> > > > + } else if (event->mask & LTP_PRE_CONTENT_EVENTS) {
>
> > > You should probably check here that the event->len is sufficiently large to
> > > contain the range info. Otherwise 'range' might point beyond the end of
> > > event and result in odd behavior...
>
>
> > Right. feel free to use the amended version below
>
>
>
> > > Honza
>
> > > > + if (range->hdr.info_type != FAN_EVENT_INFO_TYPE_RANGE) {
> > > > + tst_res(TFAIL,
> > > > + "got event: mask=%llx pid=%u fd=%d "
> > > > + "(expected range info)",
> > > > + (unsigned long long)event->mask,
> > > > + (unsigned int)event->pid,
> > > > + event->fd);
>
> > if (event->event_len < sizeof(*event) +
> > sizeof(*range) ||
> > range->hdr.info_type != FAN_EVENT_INFO_TYPE_RANGE) {
> > tst_res(TFAIL,
> > "got event: mask=%llx pid=%u
> > len=%d fd=%d "
> > "(expected range info)",
> > (unsigned long long)event->mask,
> > (unsigned int)event->pid,
> > (unsigned int)event->event_len,
> > event->fd);
>
> Thanks! I dared instead of copy pasting to use fan_hsm branch from your fork.
Sure. That's good too.
Thanks,
Amir.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2025-03-27 17:15 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-19 19:27 [LTP] [PATCH 0/3] fanotify tests update for 6.14-rc7 Amir Goldstein
2025-03-19 19:27 ` [LTP] [PATCH 1/3] fanotify24: remove redundant event_count field Amir Goldstein
2025-03-24 13:23 ` Jan Kara
2025-03-25 20:46 ` Petr Vorel
2025-03-19 19:27 ` [LTP] [PATCH 2/3] fanotify24: print range info for pre-content events Amir Goldstein
2025-03-26 15:04 ` Jan Kara
2025-03-27 9:11 ` Amir Goldstein
2025-03-27 10:54 ` Petr Vorel
2025-03-27 17:15 ` Amir Goldstein
2025-03-19 19:27 ` [LTP] [PATCH 3/3] fanotify24: add mmap() and user page fault to test Amir Goldstein
2025-03-20 17:00 ` Petr Vorel
2025-03-20 17:42 ` Amir Goldstein
2025-03-20 18:18 ` Petr Vorel
2025-03-26 15:08 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox