Skip to content

Commit 3a9fb89

Browse files
committed
fsnotify: include vfsmount in should_send_event when appropriate
To ensure that a group will not duplicate events when it receives it based on the vfsmount and the inode should_send_event test we should distinguish those two cases. We pass a vfsmount to this function so groups can make their own determinations. Signed-off-by: Eric Paris <eparis@redhat.com>
1 parent 7131485 commit 3a9fb89

6 files changed

Lines changed: 29 additions & 26 deletions

File tree

‎fs/notify/dnotify/dnotify.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ static int dnotify_handle_event(struct fsnotify_group *group,
133133
* userspace notification for that pair.
134134
*/
135135
static bool dnotify_should_send_event(struct fsnotify_group *group,
136-
struct inode *inode, __u32 mask,
137-
void *data, int data_type)
136+
struct inode *inode, struct vfsmount *mnt,
137+
__u32 mask, void *data, int data_type)
138138
{
139139
struct fsnotify_mark_entry *entry;
140140
bool send;

‎fs/notify/fsnotify.c‎

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,12 @@ void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask)
135135
}
136136
EXPORT_SYMBOL_GPL(__fsnotify_parent);
137137

138-
static void send_to_group(__u32 mask,
139-
struct fsnotify_group *group,
140-
void *data, int data_is, const char *file_name,
141-
u32 cookie, struct fsnotify_event **event,
142-
struct inode *to_tell)
138+
static void send_to_group(struct fsnotify_group *group, struct inode *to_tell,
139+
struct vfsmount *mnt, __u32 mask, void *data,
140+
int data_is, u32 cookie, const char *file_name,
141+
struct fsnotify_event **event)
143142
{
144-
if (!group->ops->should_send_event(group, to_tell, mask,
143+
if (!group->ops->should_send_event(group, to_tell, mnt, mask,
145144
data, data_is))
146145
return;
147146
if (!*event) {
@@ -159,15 +158,9 @@ static void send_to_group(__u32 mask,
159158
group->ops->handle_event(group, *event);
160159
}
161160

162-
static bool needed_by_vfsmount(__u32 test_mask, void *data, int data_is)
161+
static bool needed_by_vfsmount(__u32 test_mask, struct vfsmount *mnt)
163162
{
164-
struct path *path;
165-
166-
if (data_is == FSNOTIFY_EVENT_PATH)
167-
path = (struct path *)data;
168-
else if (data_is == FSNOTIFY_EVENT_FILE)
169-
path = &((struct file *)data)->f_path;
170-
else
163+
if (!mnt)
171164
return false;
172165

173166
/* hook in this when mnt->mnt_fsnotify_mask is defined */
@@ -184,6 +177,7 @@ void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, const
184177
{
185178
struct fsnotify_group *group;
186179
struct fsnotify_event *event = NULL;
180+
struct vfsmount *mnt = NULL;
187181
int idx;
188182
/* global tests shouldn't care about events on child only the specific event */
189183
__u32 test_mask = (mask & ~FS_EVENT_ON_CHILD);
@@ -198,10 +192,15 @@ void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, const
198192
!(test_mask & fsnotify_vfsmount_mask))
199193
return;
200194

195+
if (data_is == FSNOTIFY_EVENT_PATH)
196+
mnt = ((struct path *)data)->mnt;
197+
else if (data_is == FSNOTIFY_EVENT_FILE)
198+
mnt = ((struct file *)data)->f_path.mnt;
199+
201200
/* if this inode's directed listeners don't care and nothing on the vfsmount
202201
* listeners list cares, nothing to do */
203202
if (!(test_mask & to_tell->i_fsnotify_mask) &&
204-
!needed_by_vfsmount(test_mask, data, data_is))
203+
!needed_by_vfsmount(test_mask, mnt))
205204
return;
206205

207206
/*
@@ -214,16 +213,16 @@ void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, const
214213
if (test_mask & to_tell->i_fsnotify_mask) {
215214
list_for_each_entry_rcu(group, &fsnotify_inode_groups, inode_group_list) {
216215
if (test_mask & group->mask) {
217-
send_to_group(mask, group, data, data_is,
218-
file_name, cookie, &event, to_tell);
216+
send_to_group(group, to_tell, NULL, mask, data, data_is,
217+
cookie, file_name, &event);
219218
}
220219
}
221220
}
222-
if (needed_by_vfsmount(test_mask, data, data_is)) {
221+
if (needed_by_vfsmount(test_mask, mnt)) {
223222
list_for_each_entry_rcu(group, &fsnotify_vfsmount_groups, vfsmount_group_list) {
224223
if (test_mask & group->mask) {
225-
send_to_group(mask, group, data, data_is,
226-
file_name, cookie, &event, to_tell);
224+
send_to_group(group, to_tell, mnt, mask, data, data_is,
225+
cookie, file_name, &event);
227226
}
228227
}
229228
}

‎fs/notify/inotify/inotify_fsnotify.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ static void inotify_freeing_mark(struct fsnotify_mark_entry *entry, struct fsnot
141141
}
142142

143143
static bool inotify_should_send_event(struct fsnotify_group *group, struct inode *inode,
144-
__u32 mask, void *data, int data_type)
144+
struct vfsmount *mnt, __u32 mask, void *data,
145+
int data_type)
145146
{
146147
struct fsnotify_mark_entry *entry;
147148
bool send;

‎include/linux/fsnotify_backend.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ struct fsnotify_event_private_data;
7979
*/
8080
struct fsnotify_ops {
8181
bool (*should_send_event)(struct fsnotify_group *group, struct inode *inode,
82-
__u32 mask, void *data, int data_type);
82+
struct vfsmount *mnt, __u32 mask, void *data,
83+
int data_type);
8384
int (*handle_event)(struct fsnotify_group *group, struct fsnotify_event *event);
8485
void (*free_group_priv)(struct fsnotify_group *group);
8586
void (*freeing_mark)(struct fsnotify_mark_entry *entry, struct fsnotify_group *group);

‎kernel/audit_tree.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,8 @@ static void audit_tree_freeing_mark(struct fsnotify_mark_entry *entry, struct fs
920920
}
921921

922922
static bool audit_tree_send_event(struct fsnotify_group *group, struct inode *inode,
923-
__u32 mask, void *data, int data_type)
923+
struct vfsmount *mnt, __u32 mask, void *data,
924+
int data_type)
924925
{
925926
return 0;
926927
}

‎kernel/audit_watch.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,8 @@ void audit_remove_watch_rule(struct audit_krule *krule)
514514
}
515515

516516
static bool audit_watch_should_send_event(struct fsnotify_group *group, struct inode *inode,
517-
__u32 mask, void *data, int data_type)
517+
struct vfsmount *mnt, __u32 mask, void *data,
518+
int data_type)
518519
{
519520
struct fsnotify_mark_entry *entry;
520521
bool send;

0 commit comments

Comments
 (0)