Commit d809daf1 authored by Amir Goldstein's avatar Amir Goldstein Committed by Jan Kara

fanotify: generalize test for FAN_REPORT_FID

As preparation for new flags that report fids, define a bit set
of flags for a group reporting fids, currently containing the
only bit FAN_REPORT_FID.

Link: https://lore.kernel.org/r/20200716084230.30611-5-amir73il@gmail.comSigned-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent 6ad1aadd
...@@ -207,13 +207,14 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, ...@@ -207,13 +207,14 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,
__u32 test_mask, user_mask = FANOTIFY_OUTGOING_EVENTS | __u32 test_mask, user_mask = FANOTIFY_OUTGOING_EVENTS |
FANOTIFY_EVENT_FLAGS; FANOTIFY_EVENT_FLAGS;
const struct path *path = fsnotify_data_path(data, data_type); const struct path *path = fsnotify_data_path(data, data_type);
unsigned int fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS);
struct fsnotify_mark *mark; struct fsnotify_mark *mark;
int type; int type;
pr_debug("%s: report_mask=%x mask=%x data=%p data_type=%d\n", pr_debug("%s: report_mask=%x mask=%x data=%p data_type=%d\n",
__func__, iter_info->report_mask, event_mask, data, data_type); __func__, iter_info->report_mask, event_mask, data, data_type);
if (!FAN_GROUP_FLAG(group, FAN_REPORT_FID)) { if (!fid_mode) {
/* Do we have path to open a file descriptor? */ /* Do we have path to open a file descriptor? */
if (!path) if (!path)
return 0; return 0;
...@@ -264,7 +265,7 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, ...@@ -264,7 +265,7 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,
* fanotify_alloc_event() when group is reporting fid as indication * fanotify_alloc_event() when group is reporting fid as indication
* that event happened on child. * that event happened on child.
*/ */
if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) { if (fid_mode) {
/* Do not report event flags without any event */ /* Do not report event flags without any event */
if (!(test_mask & ~FANOTIFY_EVENT_FLAGS)) if (!(test_mask & ~FANOTIFY_EVENT_FLAGS))
return 0; return 0;
...@@ -424,6 +425,7 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, ...@@ -424,6 +425,7 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group,
gfp_t gfp = GFP_KERNEL_ACCOUNT; gfp_t gfp = GFP_KERNEL_ACCOUNT;
struct inode *id = fanotify_fid_inode(mask, data, data_type, dir); struct inode *id = fanotify_fid_inode(mask, data, data_type, dir);
const struct path *path = fsnotify_data_path(data, data_type); const struct path *path = fsnotify_data_path(data, data_type);
unsigned int fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS);
bool name_event = false; bool name_event = false;
/* /*
...@@ -444,7 +446,7 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, ...@@ -444,7 +446,7 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group,
event = fanotify_alloc_perm_event(path, gfp); event = fanotify_alloc_perm_event(path, gfp);
} else if (name_event && file_name) { } else if (name_event && file_name) {
event = fanotify_alloc_name_event(id, fsid, file_name, gfp); event = fanotify_alloc_name_event(id, fsid, file_name, gfp);
} else if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) { } else if (fid_mode) {
event = fanotify_alloc_fid_event(id, fsid, gfp); event = fanotify_alloc_fid_event(id, fsid, gfp);
} else { } else {
event = fanotify_alloc_path_event(path, gfp); event = fanotify_alloc_path_event(path, gfp);
...@@ -551,7 +553,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask, ...@@ -551,7 +553,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask,
return 0; return 0;
} }
if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) { if (FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS)) {
fsid = fanotify_get_fsid(iter_info); fsid = fanotify_get_fsid(iter_info);
/* Racing with mark destruction or creation? */ /* Racing with mark destruction or creation? */
if (!fsid.val[0] && !fsid.val[1]) if (!fsid.val[0] && !fsid.val[1])
......
...@@ -100,7 +100,7 @@ static struct fanotify_event *get_one_event(struct fsnotify_group *group, ...@@ -100,7 +100,7 @@ static struct fanotify_event *get_one_event(struct fsnotify_group *group,
if (fsnotify_notify_queue_is_empty(group)) if (fsnotify_notify_queue_is_empty(group))
goto out; goto out;
if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) { if (FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS)) {
event_size += fanotify_event_info_len( event_size += fanotify_event_info_len(
FANOTIFY_E(fsnotify_peek_first_event(group))); FANOTIFY_E(fsnotify_peek_first_event(group)));
} }
...@@ -882,7 +882,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) ...@@ -882,7 +882,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
return -EINVAL; return -EINVAL;
} }
if ((flags & FAN_REPORT_FID) && if ((flags & FANOTIFY_FID_BITS) &&
(flags & FANOTIFY_CLASS_BITS) != FAN_CLASS_NOTIF) (flags & FANOTIFY_CLASS_BITS) != FAN_CLASS_NOTIF)
return -EINVAL; return -EINVAL;
...@@ -1040,7 +1040,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, ...@@ -1040,7 +1040,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
__kernel_fsid_t __fsid, *fsid = NULL; __kernel_fsid_t __fsid, *fsid = NULL;
u32 valid_mask = FANOTIFY_EVENTS | FANOTIFY_EVENT_FLAGS; u32 valid_mask = FANOTIFY_EVENTS | FANOTIFY_EVENT_FLAGS;
unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS;
unsigned int obj_type; unsigned int obj_type, fid_mode;
int ret; int ret;
pr_debug("%s: fanotify_fd=%d flags=%x dfd=%d pathname=%p mask=%llx\n", pr_debug("%s: fanotify_fd=%d flags=%x dfd=%d pathname=%p mask=%llx\n",
...@@ -1113,9 +1113,9 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, ...@@ -1113,9 +1113,9 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
* inode events are not supported on a mount mark, because they do not * inode events are not supported on a mount mark, because they do not
* carry enough information (i.e. path) to be filtered by mount point. * carry enough information (i.e. path) to be filtered by mount point.
*/ */
fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS);
if (mask & FANOTIFY_INODE_EVENTS && if (mask & FANOTIFY_INODE_EVENTS &&
(!FAN_GROUP_FLAG(group, FAN_REPORT_FID) || (!fid_mode || mark_type == FAN_MARK_MOUNT))
mark_type == FAN_MARK_MOUNT))
goto fput_and_out; goto fput_and_out;
if (flags & FAN_MARK_FLUSH) { if (flags & FAN_MARK_FLUSH) {
...@@ -1140,7 +1140,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, ...@@ -1140,7 +1140,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
goto path_put_and_out; goto path_put_and_out;
} }
if (FAN_GROUP_FLAG(group, FAN_REPORT_FID)) { if (fid_mode) {
ret = fanotify_test_fid(&path, &__fsid); ret = fanotify_test_fid(&path, &__fsid);
if (ret) if (ret)
goto path_put_and_out; goto path_put_and_out;
......
...@@ -18,8 +18,10 @@ ...@@ -18,8 +18,10 @@
#define FANOTIFY_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \ #define FANOTIFY_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \
FAN_CLASS_PRE_CONTENT) FAN_CLASS_PRE_CONTENT)
#define FANOTIFY_INIT_FLAGS (FANOTIFY_CLASS_BITS | \ #define FANOTIFY_FID_BITS (FAN_REPORT_FID)
FAN_REPORT_TID | FAN_REPORT_FID | \
#define FANOTIFY_INIT_FLAGS (FANOTIFY_CLASS_BITS | FANOTIFY_FID_BITS | \
FAN_REPORT_TID | \
FAN_CLOEXEC | FAN_NONBLOCK | \ FAN_CLOEXEC | FAN_NONBLOCK | \
FAN_UNLIMITED_QUEUE | FAN_UNLIMITED_MARKS) FAN_UNLIMITED_QUEUE | FAN_UNLIMITED_MARKS)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment