public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] NFS: Fix possible NULL pointer dereference in nfs_inode_remove_request()
@ 2025-10-12  8:39 Baolin Liu
  2025-10-12 11:21 ` [PATCH] " Markus Elfring
  2025-10-13  4:47 ` [PATCH v1] " Trond Myklebust
  0 siblings, 2 replies; 10+ messages in thread
From: Baolin Liu @ 2025-10-12  8:39 UTC (permalink / raw)
  To: trondmy, anna; +Cc: linux-nfs, linux-kernel, Baolin Liu

From: Baolin Liu <liubaolin@kylinos.cn>

nfs_page_to_folio(req->wb_head) may return NULL in certain conditions,
but the function dereferences folio->mapping and calls
folio_end_dropbehind(folio) unconditionally. This may cause a NULL
pointer dereference crash.

Fix this by checking folio before using it or calling
folio_end_dropbehind().

Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
 fs/nfs/write.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 0fb6905736d5..e148308c1923 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -739,17 +739,18 @@ static void nfs_inode_remove_request(struct nfs_page *req)
 	nfs_page_group_lock(req);
 	if (nfs_page_group_sync_on_bit_locked(req, PG_REMOVE)) {
 		struct folio *folio = nfs_page_to_folio(req->wb_head);
-		struct address_space *mapping = folio->mapping;
 
-		spin_lock(&mapping->i_private_lock);
 		if (likely(folio)) {
+			struct address_space *mapping = folio->mapping;
+
+			spin_lock(&mapping->i_private_lock);
 			folio->private = NULL;
 			folio_clear_private(folio);
 			clear_bit(PG_MAPPED, &req->wb_head->wb_flags);
-		}
-		spin_unlock(&mapping->i_private_lock);
+			spin_unlock(&mapping->i_private_lock);
 
-		folio_end_dropbehind(folio);
+			folio_end_dropbehind(folio);
+		}
 	}
 	nfs_page_group_unlock(req);
 
-- 
2.39.2


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

end of thread, other threads:[~2025-10-22  7:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-12  8:39 [PATCH v1] NFS: Fix possible NULL pointer dereference in nfs_inode_remove_request() Baolin Liu
2025-10-12 11:21 ` [PATCH] " Markus Elfring
2025-10-13  4:47 ` [PATCH v1] " Trond Myklebust
2025-10-17  6:57   ` liubaolin
2025-10-17 15:02     ` Trond Myklebust
2025-10-22  2:44       ` liubaolin
2025-10-22  3:15         ` Trond Myklebust
2025-10-22  3:26           ` Trond Myklebust
2025-10-22  7:34           ` Dan Carpenter
2025-10-22  7:36             ` Dan Carpenter

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