The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2] fs: add NULL check in drop_buffers() to prevent null-ptr-deref
@ 2025-12-08 19:03 Deepakkumar Karn
  2025-12-08 19:30 ` Darrick J. Wong
  0 siblings, 1 reply; 11+ messages in thread
From: Deepakkumar Karn @ 2025-12-08 19:03 UTC (permalink / raw)
  To: Alexander Viro
  Cc: Christian Brauner, Jan Kara, linux-fsdevel, linux-kernel,
	syzbot+e07658f51ca22ab65b4e, syzkaller-bugs, Deepakkumar Karn

drop_buffers() dereferences the buffer_head pointer returned by
folio_buffers() without checking for NULL. This leads to a null pointer
dereference when called from try_to_free_buffers() on a folio with no
buffers attached. This happens when filemap_release_folio() is called on
a folio belonging to a mapping with AS_RELEASE_ALWAYS set but without
release_folio address_space operation defined. In such case,
folio_needs_release() returns true because of AS_RELEASE_ALWAYS flag,
the folio has no private buffer data, causing the try_to_free_buffers()
with a folio that has no buffers.

Adding NULL check for the buffer_head pointer and return false early if
no buffers are attached to the folio.

Reported-by: syzbot+e07658f51ca22ab65b4e@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=e07658f51ca22ab65b4e
Fixes: 6439476311a6 ("fs: Convert drop_buffers() to use a folio")
Signed-off-by: Deepakkumar Karn <dkarn@redhat.com>
---
 fs/buffer.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/buffer.c b/fs/buffer.c
index 838c0c571022..fa5de0cdf540 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -2893,6 +2893,10 @@ drop_buffers(struct folio *folio, struct buffer_head **buffers_to_free)
 	struct buffer_head *head = folio_buffers(folio);
 	struct buffer_head *bh;
 
+	/* In cases of folio without buffer_head*/
+	if (!head)
+		return false;
+
 	bh = head;
 	do {
 		if (buffer_busy(bh))
-- 
2.52.0


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

end of thread, other threads:[~2025-12-11 12:51 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-08 19:03 [PATCH v2] fs: add NULL check in drop_buffers() to prevent null-ptr-deref Deepakkumar Karn
2025-12-08 19:30 ` Darrick J. Wong
2025-12-08 20:13   ` Deepakkumar Karn
2025-12-09 11:18     ` Jan Kara
2025-12-09 16:30       ` Deepak Karn
2025-12-10  9:55         ` Jan Kara
2025-12-10 15:29           ` Deepak Karn
2025-12-10 17:23             ` Jan Kara
2025-12-10 17:50               ` Deepak Karn
2025-12-11  9:15                 ` Jan Kara
2025-12-11 12:50                   ` Deepak Karn

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