mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiaming Zhang <r772577952@gmail.com>
To: Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>,
	Joseph Qi <joseph.qi@linux.alibaba.com>,
	ocfs2-devel@lists.linux.dev
Cc: Heming Zhao <heming.zhao@suse.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org,
	Jiaming Zhang <r772577952@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] ocfs2: release system inodes when loading system_dir fails
Date: Sat,  5 Dec 2026 22:23:47 +0800	[thread overview]
Message-ID: <20261205142347.3563105-1-r772577952@gmail.com> (raw)

During mount, ocfs2_initialize_super() loads the root directory, system
directory, and global system inodes via ocfs2_init_global_system_inodes().
Since commit a8a986db6493 ("ocfs2: ocfs2_initialize_super does cleanup job
before return error"), it assumes none stay loaded if that helper fails,
jumping to out_dlm_out past ocfs2_release_system_inodes():

	status = ocfs2_init_global_system_inodes(osb);
	if (status < 0) {
		mlog_errno(status);
		goto out_dlm_out;
	}

In ocfs2_init_global_system_inodes(), ocfs2_iget() first loads the root
inode at s_root_blkno, hashes it in the VFS inode cache under (sb, i_ino),
and saves it in osb->root_inode.  If ocfs2_iget() then fails on a corrupt
or unreadable s_system_dir_blkno block, the function jumps to bail without
calling ocfs2_release_system_inodes(), never passing root_inode to iput().

Because the mount fails before sb->s_root is set, generic_shutdown_super()
skips its sb->s_root teardown and busy-inode poisoning, freeing sb while
osb->root_inode stays hashed.  When a later mount reuses that super_block
address, iget_locked() on the same inode number returns the stale OCFS2
inode attached to the new filesystem's superblock.

VFS operations on that file then run OCFS2 callbacks against the new
filesystem's s_fs_info, corrupting foreign superblock memory or crashing
the kernel (for example, openat() hits spinlock bad magic and an oops in
ocfs2_permission() when locking osb->osb_lock).  Triggering this requires
CAP_SYS_ADMIN to mount a corrupted OCFS2 volume and a second filesystem.

Call ocfs2_release_system_inodes() when loading s_system_dir_blkno fails
in ocfs2_init_global_system_inodes(), matching the cleanup in the global
system inode loop below so failed calls leave no system inodes behind.

Fixes: a8a986db6493 ("ocfs2: ocfs2_initialize_super does cleanup job before return error")
Closes: https://lore.kernel.org/lkml/CANypQFYAkHt6ARjeVAEb7pBeAroaHhqVm_1BL6gqQdKV4rAv1Q@mail.gmail.com/
Cc: stable@vger.kernel.org
Assisted-by: Antigravity:Gemini
Signed-off-by: Jiaming Zhang <r772577952@gmail.com>
---
 fs/ocfs2/super.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
index d2021405d408..1a8ff5d0f560 100644
--- a/fs/ocfs2/super.c
+++ b/fs/ocfs2/super.c
@@ -449,6 +449,7 @@ static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
 
 	new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
 	if (IS_ERR(new)) {
+		ocfs2_release_system_inodes(osb);
 		status = PTR_ERR(new);
 		mlog_errno(status);
 		goto bail;

base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
-- 
2.43.0


                 reply	other threads:[~2026-12-05 14:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261205142347.3563105-1-r772577952@gmail.com \
    --to=r772577952@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=heming.zhao@suse.com \
    --cc=jlbec@evilplan.org \
    --cc=joseph.qi@linux.alibaba.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark@fasheh.com \
    --cc=ocfs2-devel@lists.linux.dev \
    --cc=stable@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®