public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nfsd: free nfsd_file by gc after adding it to lru list
@ 2025-01-13  2:59 Li Lingfeng
  2025-01-13 14:07 ` Chuck Lever
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Li Lingfeng @ 2025-01-13  2:59 UTC (permalink / raw)
  To: chuck.lever, jlayton, neilb, okorniev, Dai.Ngo, tom
  Cc: linux-nfs, linux-kernel, yukuai1, houtao1, yi.zhang, yangerkun,
	lilingfeng, lilingfeng3

In nfsd_file_put, after inserting the nfsd_file into the nfsd_file_lru
list, gc may be triggered in another thread and immediately release this
nfsd_file, which will lead to a UAF when accessing this nfsd_file again.

All the places where unhash is done will also perform lru_remove, so there
is no need to do lru_remove separately here. After inserting the nfsd_file
into the nfsd_file_lru list, it can be released by relying on gc.

Fixes: 4a0e73e635e3 ("NFSD: Leave open files out of the filecache LRU")
Signed-off-by: Li Lingfeng <lilingfeng3@huawei.com>
---
 fs/nfsd/filecache.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c
index a1cdba42c4fa..37b65cb1579a 100644
--- a/fs/nfsd/filecache.c
+++ b/fs/nfsd/filecache.c
@@ -372,18 +372,10 @@ nfsd_file_put(struct nfsd_file *nf)
 		/* Try to add it to the LRU.  If that fails, decrement. */
 		if (nfsd_file_lru_add(nf)) {
 			/* If it's still hashed, we're done */
-			if (test_bit(NFSD_FILE_HASHED, &nf->nf_flags)) {
+			if (list_lru_count(&nfsd_file_lru))
 				nfsd_file_schedule_laundrette();
-				return;
-			}
 
-			/*
-			 * We're racing with unhashing, so try to remove it from
-			 * the LRU. If removal fails, then someone else already
-			 * has our reference.
-			 */
-			if (!nfsd_file_lru_remove(nf))
-				return;
+			return;
 		}
 	}
 	if (refcount_dec_and_test(&nf->nf_ref))
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2025-01-22 12:31 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-13  2:59 [PATCH] nfsd: free nfsd_file by gc after adding it to lru list Li Lingfeng
2025-01-13 14:07 ` Chuck Lever
2025-01-14  1:54   ` Li Lingfeng
2025-01-14 19:17     ` Chuck Lever
2025-01-14 19:27 ` Jeff Layton
2025-01-14 19:39   ` Jeff Layton
2025-01-15 15:03     ` Chuck Lever
2025-01-15 15:27       ` Jeff Layton
2025-01-22  1:33         ` Li Lingfeng
2025-01-21 20:50       ` Jeff Layton
2025-01-22  1:15         ` NeilBrown
2025-01-22  1:43           ` Li Lingfeng
2025-01-22  2:21             ` Li Lingfeng
2025-01-22  3:48           ` NeilBrown
2025-01-22  7:31             ` Li Lingfeng
2025-01-22 12:31             ` Jeff Layton
2025-01-14 19:40 ` cel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox