mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mauricio Faria de Oliveira <mfo@igalia.com>
To: Andreas Gruenbacher <agruenba@redhat.com>
Cc: kernel-dev@igalia.com, gfs2@lists.linux.dev,
	 linux-kernel@vger.kernel.org,
	Mauricio Faria de Oliveira <mfo@igalia.com>
Subject: [PATCH 1/5] gfs2: handle errors from __filemap_get_folio() with FGP_CREAT in gfs2_getbuf()
Date: Tue, 08 Sep 2026 18:16:12 -0300	[thread overview]
Message-ID: <20260908-gfs2_getbuf-error-checks-v1-1-7c59698f178f@igalia.com> (raw)
In-Reply-To: <20260908-gfs2_getbuf-error-checks-v1-0-7c59698f178f@igalia.com>

Function __filemap_get_folio() with FGP_CREAT might fail, for example, with
ERR_PTR(-ENOMEM). This hits a kernel oops, as gfs2_getbuf() dereferences an
error pointer:

 gfs2: fsid=loop0: Trying to join cluster "lock_nolock", "loop0"
 gfs2: fsid=loop0: Now mounting FS (format 1802)...
 Oops: general protection fault, probably for non-canonical address
                      0xdffffc0000000003: 0000 [#1] SMP KASAN NOPTI
 KASAN: null-ptr-deref in range [0x0000000000000018-0x000000000000001f]
 ...
 RIP: 0010:gfs2_getbuf+0x492/0x5a0
 [  ...
 Call Trace:
  <TASK>
  gfs2_meta_read+0x106/0x7a0
  gfs2_meta_buffer+0x125/0x360
  inode_go_instantiate+0xde/0x1510
  gfs2_instantiate+0x102/0x1c0
  gfs2_glock_wait+0x19a/0x2c0
  gfs2_lookupi+0x2ba/0x570
  gfs2_lookup_meta+0xad/0x160
  init_inodes+0x350/0x20b0
  gfs2_fill_super+0x19b6/0x2730
  get_tree_bdev_flags+0x2f4/0x560
  gfs2_get_tree+0x48/0x230
  vfs_get_tree+0x87/0x2d0
  vfs_cmd_create+0xb2/0x240
  __do_sys_fsconfig+0x3d2/0x980
  do_syscall_64+0xce/0x450
  entry_SYSCALL_64_after_hwframe+0x77/0x7f
 ...
  </TASK>

That is noted more clearly in convenience function filemap_grab_folio()
(snippet below) and checked by virtually all other callers in the kernel.

 ...
  * Return: A found or created folio. ERR_PTR(-ENOMEM) if no folio is found
  * and failed to create a folio.
 ...
 static inline struct folio *filemap_grab_folio(...)
 {
         return __filemap_get_folio(...,
                                    ... | FGP_CREAT,
                                    ...);
 }

Thus, if __filemap_get_folio() returns an error, log it (as it's lost) and
return NULL. Callers will be handled.

Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
---
 fs/gfs2/meta_io.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c
index a87cfbf0df38706e6b7c63cc55f5251765d6b398..51b1a2e2bfadea6dabfac5ecba983c615a1a69fa 100644
--- a/fs/gfs2/meta_io.c
+++ b/fs/gfs2/meta_io.c
@@ -145,6 +145,10 @@ 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)) {
+			fs_err(sdp, "Error %ld creating buffer\n", PTR_ERR(folio));
+			return NULL;
+		}
 		bh = folio_buffers(folio);
 		if (!bh)
 			bh = create_empty_buffers(folio,

-- 
2.47.3


  reply	other threads:[~2026-09-08 21:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08 21:16 [PATCH 0/5] gfs2: handle errors from __filemap_get_folio() with FGP_CREAT in gfs2_getbuf() and its caller chain Mauricio Faria de Oliveira
2026-09-08 21:16 ` Mauricio Faria de Oliveira [this message]
2026-09-08 21:16 ` [PATCH 2/5] gfs2: handle NULL return value in callers of gfs2_getbuf() with CREATE Mauricio Faria de Oliveira
2026-09-08 21:16 ` [PATCH 3/5] gfs2: handle NULL return value in callers of gfs2_meta_new() Mauricio Faria de Oliveira
2026-09-08 21:16 ` [PATCH 4/5] gfs2: handle NULL return value in callers of gfs2_meta_ra() Mauricio Faria de Oliveira
2026-09-08 21:16 ` [PATCH 5/5] gfs2: check for errors from filemap_get_folio() in gfs2_jhead_process_page() Mauricio Faria de Oliveira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260908-gfs2_getbuf-error-checks-v1-1-7c59698f178f@igalia.com \
    --to=mfo@igalia.com \
    --cc=agruenba@redhat.com \
    --cc=gfs2@lists.linux.dev \
    --cc=kernel-dev@igalia.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®