]>
Commit | Line | Data |
---|---|---|
52761858 SL |
1 | From f87ba5af7861b93908c0f4889f846c98f6c212e2 Mon Sep 17 00:00:00 2001 |
2 | From: Sasha Levin <sashal@kernel.org> | |
3 | Date: Mon, 25 Oct 2021 16:27:26 -0300 | |
4 | Subject: fsnotify: Protect fsnotify_handle_inode_event from no-inode events | |
5 | ||
6 | From: Gabriel Krisman Bertazi <krisman@collabora.com> | |
7 | ||
8 | [ Upstream commit 24dca90590509a7a6cbe0650100c90c5b8a3468a ] | |
9 | ||
10 | FAN_FS_ERROR allows events without inodes - i.e. for file system-wide | |
11 | errors. Even though fsnotify_handle_inode_event is not currently used | |
12 | by fanotify, this patch protects other backends from cases where neither | |
13 | inode or dir are provided. Also document the constraints of the | |
14 | interface (inode and dir cannot be both NULL). | |
15 | ||
16 | Link: https://lore.kernel.org/r/20211025192746.66445-12-krisman@collabora.com | |
17 | Suggested-by: Amir Goldstein <amir73il@gmail.com> | |
18 | Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com> | |
19 | Reviewed-by: Amir Goldstein <amir73il@gmail.com> | |
20 | Reviewed-by: Jan Kara <jack@suse.cz> | |
21 | Signed-off-by: Jan Kara <jack@suse.cz> | |
22 | Signed-off-by: Chuck Lever <chuck.lever@oracle.com> | |
23 | --- | |
24 | fs/nfsd/filecache.c | 3 +++ | |
25 | fs/notify/fsnotify.c | 3 +++ | |
26 | include/linux/fsnotify_backend.h | 1 + | |
27 | 3 files changed, 7 insertions(+) | |
28 | ||
29 | diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c | |
30 | index 1e8c31ed6c7c4..fbc0628c599af 100644 | |
31 | --- a/fs/nfsd/filecache.c | |
32 | +++ b/fs/nfsd/filecache.c | |
33 | @@ -595,6 +595,9 @@ nfsd_file_fsnotify_handle_event(struct fsnotify_mark *mark, u32 mask, | |
34 | struct inode *inode, struct inode *dir, | |
35 | const struct qstr *name, u32 cookie) | |
36 | { | |
37 | + if (WARN_ON_ONCE(!inode)) | |
38 | + return 0; | |
39 | + | |
40 | trace_nfsd_file_fsnotify_handle_event(inode, mask); | |
41 | ||
42 | /* Should be no marks on non-regular files */ | |
43 | diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c | |
44 | index fde3a1115a170..4034ca566f95c 100644 | |
45 | --- a/fs/notify/fsnotify.c | |
46 | +++ b/fs/notify/fsnotify.c | |
47 | @@ -252,6 +252,9 @@ static int fsnotify_handle_inode_event(struct fsnotify_group *group, | |
48 | if (WARN_ON_ONCE(!ops->handle_inode_event)) | |
49 | return 0; | |
50 | ||
51 | + if (WARN_ON_ONCE(!inode && !dir)) | |
52 | + return 0; | |
53 | + | |
54 | if ((inode_mark->mask & FS_EXCL_UNLINK) && | |
55 | path && d_unlinked(path->dentry)) | |
56 | return 0; | |
57 | diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h | |
58 | index 035438fe4a435..b71dc788018e4 100644 | |
59 | --- a/include/linux/fsnotify_backend.h | |
60 | +++ b/include/linux/fsnotify_backend.h | |
61 | @@ -136,6 +136,7 @@ struct mem_cgroup; | |
62 | * @dir: optional directory associated with event - | |
63 | * if @file_name is not NULL, this is the directory that | |
64 | * @file_name is relative to. | |
65 | + * Either @inode or @dir must be non-NULL. | |
66 | * @file_name: optional file name associated with event | |
67 | * @cookie: inotify rename cookie | |
68 | * | |
69 | -- | |
70 | 2.43.0 | |
71 |