mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ocfs2: release system inodes when loading system_dir fails
@ 2026-12-05 14:23 Jiaming Zhang
  0 siblings, 0 replies; only message in thread
From: Jiaming Zhang @ 2026-12-05 14:23 UTC (permalink / raw)
  To: Mark Fasheh, Joel Becker, Joseph Qi, ocfs2-devel
  Cc: Heming Zhao, Andrew Morton, linux-kernel, Jiaming Zhang, stable

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-05 14:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-05 14:23 [PATCH] ocfs2: release system inodes when loading system_dir fails Jiaming Zhang

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®