linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/filemap: fix NULL pointer dereference in do_read_cache_folio()
@ 2025-11-14 19:37 ssrane_b23
  2025-11-14 20:44 ` Matthew Wilcox
  0 siblings, 1 reply; 22+ messages in thread
From: ssrane_b23 @ 2025-11-14 19:37 UTC (permalink / raw)
  To: willy
  Cc: akpm, shakeel.butt, eddyz87, andrii, ast, linux-fsdevel,
	linux-mm, linux-kernel, linux-kernel-mentees, skhan,
	david.hunter.linux, khalid, Shaurya Rane,
	syzbot+09b7d050e4806540153d

From: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>

When read_cache_folio() is called with a NULL filler function on a
mapping that does not implement read_folio, a NULL pointer
dereference occurs in filemap_read_folio().

The crash occurs when:

build_id_parse() is called on a VMA backed by a file from a
filesystem that does not implement ->read_folio() (e.g. procfs,
sysfs, or other virtual filesystems).

read_cache_folio() is called with filler = NULL.

do_read_cache_folio() assigns filler = mapping->a_ops->read_folio,
which is still NULL.

filemap_read_folio() calls filler(), causing a NULL pointer
dereference.

The fix is to add a NULL check after the fallback assignment and return
-EIO. Callers handle this error safely.

Reported-by: syzbot+09b7d050e4806540153d@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=09b7d050e4806540153d
Fixes: ad41251c290d ("lib/buildid: implement sleepable build_id_parse() API")
Signed-off-by: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
---
 mm/filemap.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/filemap.c b/mm/filemap.c
index 13f0259d993c..f700fe931d61 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -3980,6 +3980,8 @@ static struct folio *do_read_cache_folio(struct address_space *mapping,
 
 	if (!filler)
 		filler = mapping->a_ops->read_folio;
+	if (!filler)
+		return ERR_PTR(-EIO);
 repeat:
 	folio = filemap_get_folio(mapping, index);
 	if (IS_ERR(folio)) {
-- 
2.34.1



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

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

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-14 19:37 [PATCH] mm/filemap: fix NULL pointer dereference in do_read_cache_folio() ssrane_b23
2025-11-14 20:44 ` Matthew Wilcox
2025-11-16  5:42   ` [PATCH v2] " ssrane_b23
2025-11-16  5:43   ` [PATCH] " SHAURYA RANE
2025-11-16 22:32     ` Matthew Wilcox
2025-11-17 14:10       ` Shaurya Rane
2025-11-17 18:42         ` Andrii Nakryiko
2025-11-17 16:41       ` Darrick J. Wong
2025-11-17 18:03         ` Matthew Wilcox
2025-11-17 18:45           ` Andrii Nakryiko
2025-11-18 13:03             ` Christoph Hellwig
2025-11-18 15:37               ` Matthew Wilcox
2025-11-18 16:12                 ` Darrick J. Wong
2025-11-18 19:38                   ` Andrii Nakryiko
2025-11-19  5:52                     ` Christoph Hellwig
2025-11-19  6:29                     ` Darrick J. Wong
2025-11-18 19:27                 ` Andrii Nakryiko
2025-11-19  5:50                   ` Christoph Hellwig
2025-11-19 17:12                     ` Andrii Nakryiko
2025-11-18  5:05       ` Christoph Hellwig
2025-11-18 12:51         ` Matthew Wilcox
2025-11-18 12:56           ` Christoph Hellwig

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