* [PATCH] gfs2: Fix error pointer dereference
@ 2026-02-18 20:06 Ethan Tidmore
2026-02-18 21:14 ` Matthew Wilcox
0 siblings, 1 reply; 3+ messages in thread
From: Ethan Tidmore @ 2026-02-18 20:06 UTC (permalink / raw)
To: Andreas Gruenbacher, Matthew Wilcox
Cc: Andrew Morton, gfs2, linux-kernel, Ethan Tidmore
The function __filemap_get_folio() can return an error pointer and is
not checked for one. Add check for error pointer.
Detected by Smatch:
fs/gfs2/meta_io.c:147 gfs2_getbuf() error:
'folio' dereferencing possible ERR_PTR()
Fixes: 0eb751791df86 ("gfs2: convert gfs2_getbuf() to folios")
Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>
---
fs/gfs2/meta_io.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c
index 3c8e4553102d..9c0ba4c3cb29 100644
--- a/fs/gfs2/meta_io.c
+++ b/fs/gfs2/meta_io.c
@@ -144,6 +144,8 @@ struct buffer_head *gfs2_getbuf(struct gfs2_glock *gl, u64 blkno, int create)
folio = __filemap_get_folio(mapping, index,
FGP_LOCK | FGP_ACCESSED | FGP_CREAT,
mapping_gfp_mask(mapping) | __GFP_NOFAIL);
+ if (IS_ERR(folio))
+ return NULL;
bh = folio_buffers(folio);
if (!bh)
bh = create_empty_buffers(folio,
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] gfs2: Fix error pointer dereference
2026-02-18 20:06 [PATCH] gfs2: Fix error pointer dereference Ethan Tidmore
@ 2026-02-18 21:14 ` Matthew Wilcox
2026-02-18 21:53 ` Ethan Tidmore
0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2026-02-18 21:14 UTC (permalink / raw)
To: Ethan Tidmore; +Cc: Andreas Gruenbacher, Andrew Morton, gfs2, linux-kernel
On Wed, Feb 18, 2026 at 02:06:45PM -0600, Ethan Tidmore wrote:
> The function __filemap_get_folio() can return an error pointer and is
> not checked for one. Add check for error pointer.
Can you explain how __filemap_get_folio() would fail, given the
presence of __GFP_NOFAIL in the GFP flags?
> Detected by Smatch:
> fs/gfs2/meta_io.c:147 gfs2_getbuf() error:
> 'folio' dereferencing possible ERR_PTR()
>
> Fixes: 0eb751791df86 ("gfs2: convert gfs2_getbuf() to folios")
> Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>
> ---
> fs/gfs2/meta_io.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c
> index 3c8e4553102d..9c0ba4c3cb29 100644
> --- a/fs/gfs2/meta_io.c
> +++ b/fs/gfs2/meta_io.c
> @@ -144,6 +144,8 @@ struct buffer_head *gfs2_getbuf(struct gfs2_glock *gl, u64 blkno, int create)
> folio = __filemap_get_folio(mapping, index,
> FGP_LOCK | FGP_ACCESSED | FGP_CREAT,
> mapping_gfp_mask(mapping) | __GFP_NOFAIL);
> + if (IS_ERR(folio))
> + return NULL;
> bh = folio_buffers(folio);
> if (!bh)
> bh = create_empty_buffers(folio,
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] gfs2: Fix error pointer dereference
2026-02-18 21:14 ` Matthew Wilcox
@ 2026-02-18 21:53 ` Ethan Tidmore
0 siblings, 0 replies; 3+ messages in thread
From: Ethan Tidmore @ 2026-02-18 21:53 UTC (permalink / raw)
To: Matthew Wilcox, Ethan Tidmore
Cc: Andreas Gruenbacher, Andrew Morton, gfs2, linux-kernel
On Wed Feb 18, 2026 at 3:14 PM CST, Matthew Wilcox wrote:
> On Wed, Feb 18, 2026 at 02:06:45PM -0600, Ethan Tidmore wrote:
>> The function __filemap_get_folio() can return an error pointer and is
>> not checked for one. Add check for error pointer.
>
> Can you explain how __filemap_get_folio() would fail, given the
> presence of __GFP_NOFAIL in the GFP flags?
>
I hadn't thought of that, looks like Smatch gave me a false positive. I
just saw the same function being called a few lines down and its return
value being checked for error pointer so I just assumed this one was
missing. Sorry about that.
Thanks,
ET
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-18 21:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-18 20:06 [PATCH] gfs2: Fix error pointer dereference Ethan Tidmore
2026-02-18 21:14 ` Matthew Wilcox
2026-02-18 21:53 ` Ethan Tidmore
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox