]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - queue-5.15/fsnotify-protect-fsnotify_handle_inode_event-from-no.patch
6.8-stable patches
[thirdparty/kernel/stable-queue.git] / queue-5.15 / fsnotify-protect-fsnotify_handle_inode_event-from-no.patch
CommitLineData
52761858
SL
1From f87ba5af7861b93908c0f4889f846c98f6c212e2 Mon Sep 17 00:00:00 2001
2From: Sasha Levin <sashal@kernel.org>
3Date: Mon, 25 Oct 2021 16:27:26 -0300
4Subject: fsnotify: Protect fsnotify_handle_inode_event from no-inode events
5
6From: Gabriel Krisman Bertazi <krisman@collabora.com>
7
8[ Upstream commit 24dca90590509a7a6cbe0650100c90c5b8a3468a ]
9
10FAN_FS_ERROR allows events without inodes - i.e. for file system-wide
11errors. Even though fsnotify_handle_inode_event is not currently used
12by fanotify, this patch protects other backends from cases where neither
13inode or dir are provided. Also document the constraints of the
14interface (inode and dir cannot be both NULL).
15
16Link: https://lore.kernel.org/r/20211025192746.66445-12-krisman@collabora.com
17Suggested-by: Amir Goldstein <amir73il@gmail.com>
18Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
19Reviewed-by: Amir Goldstein <amir73il@gmail.com>
20Reviewed-by: Jan Kara <jack@suse.cz>
21Signed-off-by: Jan Kara <jack@suse.cz>
22Signed-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
29diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c
30index 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 */
43diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
44index 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;
57diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
58index 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--
702.43.0
71