fs/bcachefs/fs-io-pagecache.c | 3 +++ 1 file changed, 3 insertions(+)
Add error handling for the case where bch2_folio() returns NULL
in __bch2_folio_set(). Return immediately to prevent null pointer
dereference.
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
fs/bcachefs/fs-io-pagecache.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/bcachefs/fs-io-pagecache.c b/fs/bcachefs/fs-io-pagecache.c
index e072900e6a5b..1dc65fef3ff4 100644
--- a/fs/bcachefs/fs-io-pagecache.c
+++ b/fs/bcachefs/fs-io-pagecache.c
@@ -159,6 +159,9 @@ static void __bch2_folio_set(struct folio *folio,
struct bch_folio *s = bch2_folio(folio);
unsigned i, sectors = folio_sectors(folio);
+ if (!s)
+ return;
+
BUG_ON(pg_offset >= sectors);
BUG_ON(pg_offset + pg_len > sectors);
--
2.42.0.windows.2
On Tue, Mar 04, 2025 at 12:03:11PM +0800, Wentao Liang wrote: > Add error handling for the case where bch2_folio() returns NULL > in __bch2_folio_set(). Return immediately to prevent null pointer > dereference. There is no null ptr deref, this is only called from paths where we preallocate bch_folio (and there's only two). > Signed-off-by: Wentao Liang <vulab@iscas.ac.cn> > --- > fs/bcachefs/fs-io-pagecache.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/fs/bcachefs/fs-io-pagecache.c b/fs/bcachefs/fs-io-pagecache.c > index e072900e6a5b..1dc65fef3ff4 100644 > --- a/fs/bcachefs/fs-io-pagecache.c > +++ b/fs/bcachefs/fs-io-pagecache.c > @@ -159,6 +159,9 @@ static void __bch2_folio_set(struct folio *folio, > struct bch_folio *s = bch2_folio(folio); > unsigned i, sectors = folio_sectors(folio); > > + if (!s) > + return; > + > BUG_ON(pg_offset >= sectors); > BUG_ON(pg_offset + pg_len > sectors); > > -- > 2.42.0.windows.2 >
> Add error handling for the case where bch2_folio() returns NULL > in __bch2_folio_set(). Return immediately to prevent null pointer > dereference. How do you think about to add any tags (like “Fixes” and “Cc”) accordingly? https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.14-rc5#n145 Regards, Markus
On Fri, Mar 07, 2025 at 07:01:03PM +0100, Markus Elfring wrote: > > Add error handling for the case where bch2_folio() returns NULL > > in __bch2_folio_set(). Return immediately to prevent null pointer > > dereference. > > How do you think about to add any tags (like “Fixes” and “Cc”) accordingly? > https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.14-rc5#n145 I'm only doing backports for _really_ critical fixes until the experimental tag is lifted, so don't worry about it yet
© 2016 - 2026 Red Hat, Inc.