Skip to content

Commit 07c8f3b

Browse files
committed
Merge tag 'fsnotify_for_v5.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
Pull fsnotify updates from Jan Kara: "Several smaller fixes and cleanups for fsnotify subsystem" * tag 'fsnotify_for_v5.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs: fanotify: fix ignore mask logic for events on child and on dir fanotify: don't write with size under sizeof(response) fsnotify: Remove proc_fs.h include fanotify: remove reference to fill_event_metadata() fsnotify: add mutex destroy fanotify: prefix should_merge() fanotify: Replace zero-length array with flexible-array inotify: Fix error return code assignment flow. fsnotify: Add missing annotation for fsnotify_finish_user_wait() and for fsnotify_prepare_user_wait()
2 parents d77d1db + 2f02fd3 commit 07c8f3b

File tree

7 files changed

+19
-12
lines changed

7 files changed

+19
-12
lines changed

fs/notify/fanotify/fanotify.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static bool fanotify_name_event_equal(struct fanotify_name_event *fne1,
7070
return !memcmp(fne1->name, fne2->name, fne1->name_len);
7171
}
7272

73-
static bool should_merge(struct fsnotify_event *old_fsn,
73+
static bool fanotify_should_merge(struct fsnotify_event *old_fsn,
7474
struct fsnotify_event *new_fsn)
7575
{
7676
struct fanotify_event *old, *new;
@@ -129,7 +129,7 @@ static int fanotify_merge(struct list_head *list, struct fsnotify_event *event)
129129
return 0;
130130

131131
list_for_each_entry_reverse(test_event, list, list) {
132-
if (should_merge(test_event, event)) {
132+
if (fanotify_should_merge(test_event, event)) {
133133
FANOTIFY_E(test_event)->mask |= new->mask;
134134
return 1;
135135
}
@@ -232,6 +232,10 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,
232232
if (!fsnotify_iter_should_report_type(iter_info, type))
233233
continue;
234234
mark = iter_info->marks[type];
235+
236+
/* Apply ignore mask regardless of ISDIR and ON_CHILD flags */
237+
marks_ignored_mask |= mark->ignored_mask;
238+
235239
/*
236240
* If the event is on dir and this mark doesn't care about
237241
* events on dir, don't send it!
@@ -249,7 +253,6 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,
249253
continue;
250254

251255
marks_mask |= mark->mask;
252-
marks_ignored_mask |= mark->ignored_mask;
253256
}
254257

255258
test_mask = event_mask & marks_mask & ~marks_ignored_mask;

fs/notify/fanotify/fanotify.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct fanotify_name_event {
8989
__kernel_fsid_t fsid;
9090
struct fanotify_fh dir_fh;
9191
u8 name_len;
92-
char name[0];
92+
char name[];
9393
};
9494

9595
static inline struct fanotify_name_event *

fs/notify/fanotify/fanotify_user.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
328328
ret = -EFAULT;
329329
/*
330330
* Sanity check copy size in case get_one_event() and
331-
* fill_event_metadata() event_len sizes ever get out of sync.
331+
* event_len sizes ever get out of sync.
332332
*/
333333
if (WARN_ON_ONCE(metadata.event_len > count))
334334
goto out_close_fd;
@@ -487,8 +487,10 @@ static ssize_t fanotify_write(struct file *file, const char __user *buf, size_t
487487

488488
group = file->private_data;
489489

490-
if (count > sizeof(response))
491-
count = sizeof(response);
490+
if (count < sizeof(response))
491+
return -EINVAL;
492+
493+
count = sizeof(response);
492494

493495
pr_debug("%s: group=%p count=%zu\n", __func__, group, count);
494496

fs/notify/fdinfo.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <linux/sched.h>
1212
#include <linux/types.h>
1313
#include <linux/seq_file.h>
14-
#include <linux/proc_fs.h>
1514
#include <linux/exportfs.h>
1615

1716
#include "inotify/inotify.h"

fs/notify/group.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ static void fsnotify_final_destroy_group(struct fsnotify_group *group)
2525
group->ops->free_group_priv(group);
2626

2727
mem_cgroup_put(group->memcg);
28+
mutex_destroy(&group->mark_mutex);
2829

2930
kfree(group);
3031
}

fs/notify/inotify/inotify_user.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,20 +764,18 @@ SYSCALL_DEFINE2(inotify_rm_watch, int, fd, __s32, wd)
764764
struct fsnotify_group *group;
765765
struct inotify_inode_mark *i_mark;
766766
struct fd f;
767-
int ret = 0;
767+
int ret = -EINVAL;
768768

769769
f = fdget(fd);
770770
if (unlikely(!f.file))
771771
return -EBADF;
772772

773773
/* verify that this is indeed an inotify instance */
774-
ret = -EINVAL;
775774
if (unlikely(f.file->f_op != &inotify_fops))
776775
goto out;
777776

778777
group = f.file->private_data;
779778

780-
ret = -EINVAL;
781779
i_mark = inotify_idr_find(group, wd);
782780
if (unlikely(!i_mark))
783781
goto out;

fs/notify/mark.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,16 @@ static void fsnotify_put_mark_wake(struct fsnotify_mark *mark)
325325
}
326326

327327
bool fsnotify_prepare_user_wait(struct fsnotify_iter_info *iter_info)
328+
__releases(&fsnotify_mark_srcu)
328329
{
329330
int type;
330331

331332
fsnotify_foreach_obj_type(type) {
332333
/* This can fail if mark is being removed */
333-
if (!fsnotify_get_mark_safe(iter_info->marks[type]))
334+
if (!fsnotify_get_mark_safe(iter_info->marks[type])) {
335+
__release(&fsnotify_mark_srcu);
334336
goto fail;
337+
}
335338
}
336339

337340
/*
@@ -350,6 +353,7 @@ bool fsnotify_prepare_user_wait(struct fsnotify_iter_info *iter_info)
350353
}
351354

352355
void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info)
356+
__acquires(&fsnotify_mark_srcu)
353357
{
354358
int type;
355359

0 commit comments

Comments
 (0)