Re: [PATCH] bcachefs: Add error handling for bch2_folio()

From: Kent Overstreet
Date: Fri Mar 07 2025 - 13:03:20 EST


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@xxxxxxxxxxx>
> ---
> 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
>