]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
nfsd: Fix a soft lockup race in nfsd_file_mark_find_or_create()
authorTrond Myklebust <trondmy@gmail.com>
Mon, 6 Jan 2020 18:20:47 +0000 (13:20 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 1 Oct 2020 11:17:28 +0000 (13:17 +0200)
[ Upstream commit 90d2f1da832fd23290ef0c0d964d97501e5e8553 ]

If nfsd_file_mark_find_or_create() keeps winning the race for the
nfsd_file_fsnotify_group->mark_mutex against nfsd_file_mark_put()
then it can soft lock up, since fsnotify_add_inode_mark() ends
up always finding an existing entry.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/nfsd/filecache.c

index 3007b8945d3883f565a9f935d28328b62681ff9c..51c08ae79063ce015ec9f5ebcb29a3fdcd51aa13 100644 (file)
@@ -133,9 +133,13 @@ nfsd_file_mark_find_or_create(struct nfsd_file *nf)
                                                 struct nfsd_file_mark,
                                                 nfm_mark));
                        mutex_unlock(&nfsd_file_fsnotify_group->mark_mutex);
-                       fsnotify_put_mark(mark);
-                       if (likely(nfm))
+                       if (nfm) {
+                               fsnotify_put_mark(mark);
                                break;
+                       }
+                       /* Avoid soft lockup race with nfsd_file_mark_put() */
+                       fsnotify_destroy_mark(mark, nfsd_file_fsnotify_group);
+                       fsnotify_put_mark(mark);
                } else
                        mutex_unlock(&nfsd_file_fsnotify_group->mark_mutex);