[Linux Kernel Bug] BUG: spinlock bad magic in ocfs2_permission

From: Jiaming Zhang

Date: Sat Dec 05 2026 - 08:58:03 EST


Hi Linux kernel developers and maintainers,

We are writing to report a spinlock bad magic crash (due to a leaked
inode on failed mount) in the OCFS2 subsystem, reproducible on the
latest version of Linux (v7.4-rc5, commit fe6ff8d5d675).

It is triggered by mounting a crafted OCFS2 image that fails during
system inode setup, mounting another filesystem (such as HFS+) that
reuses the freed superblock address (requiring CAP_SYS_ADMIN to mount),
and calling openat() on a file with the matching inode number. Below
is the kernel report:

BUG: spinlock bad magic on CPU#1, repro.out/9443
Oops: general protection fault, probably for non-canonical address
0xdffffc0000000148: 0000 [#1] SMP KASAN NOPTI
KASAN: null-ptr-deref in range [0x0000000000000a40-0x0000000000000a47]
CPU: 1 UID: 0 PID: 9443 Comm: repro.out Not tainted 7.4.0-rc5 #62 PREEMPT(full)
Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix,
1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:task_pid_nr include/linux/pid.h:298 [inline]
RIP: 0010:spin_dump kernel/locking/spinlock_debug.c:64 [inline]
RIP: 0010:spin_bug+0xda/0x1c0 kernel/locking/spinlock_debug.c:78
Call Trace:
<TASK>
debug_spin_lock_before kernel/locking/spinlock_debug.c:86 [inline]
do_raw_spin_lock+0x1bd/0x260 kernel/locking/spinlock_debug.c:115
spin_lock include/linux/spinlock.h:347 [inline]
ocfs2_is_hard_readonly fs/ocfs2/ocfs2.h:681 [inline]
ocfs2_inode_lock_full_nested+0x120/0x1b40 fs/ocfs2/dlmglue.c:2440
ocfs2_inode_lock_tracker+0x1be/0x660 fs/ocfs2/dlmglue.c:2685
ocfs2_permission+0xb7/0x1b0 fs/ocfs2/file.c:1386
do_inode_permission fs/namei.c:583 [inline]
inode_permission+0x44e/0x5d0 fs/namei.c:653
may_open+0x325/0x4c0 fs/namei.c:4275
do_open fs/namei.c:4849 [inline]
path_openat+0x14c4/0x1f80 fs/namei.c:5016
do_file_open+0x203/0x440 fs/namei.c:5045
do_sys_openat2+0x107/0x1e0 fs/open.c:1443
do_sys_open fs/open.c:1449 [inline]
__do_sys_openat fs/open.c:1465 [inline]
__se_sys_openat fs/open.c:1460 [inline]
__x64_sys_openat+0x138/0x170 fs/open.c:1460
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x17b/0x560 arch/x86/entry/syscall_64.c:89
entry_SYSCALL_64_after_hwframe+0x77/0x7f
</TASK>

Following is the root cause analysis for this issue. Note that the
analysis was performed with the assistance of an LLM, and we have tried
our best to ensure its accuracy.

The crash triggers because openat() on a mounted HFS+ filesystem looks
up a path and receives a stale OCFS2 inode left in the global VFS inode
cache from an earlier failed OCFS2 mount. Entering ocfs2_permission()
then reads the HFS+ superblock's s_fs_info as a struct ocfs2_super and
calls spin_lock(&osb->osb_lock) on non-spinlock memory.

That stale inode is leaked during OCFS2 mount in
ocfs2_init_global_system_inodes(). It first loads and hashes the root
directory inode (osb->root_inode) via ocfs2_iget(), and then loads the
system directory inode. If loading the system directory inode fails,
it jumps to bail without calling ocfs2_release_system_inodes().

Its caller ocfs2_initialize_super() also bypasses
ocfs2_release_system_inodes(), so osb->root_inode is never released with
iput(). Because the mount fails before sb->s_root is set,
generic_shutdown_super() skips busy-inode poisoning, and VFS frees sb
while osb->root_inode remains hashed under (sb, i_ino).

When a subsequent mount (such as HFS+) allocates its struct super_block
at the same slab address and looks up a file with the same inode number
via iget_locked(), VFS matches (sb, i_ino) and returns the leaked OCFS2
inode attached to the new filesystem's superblock.

Subsequent VFS operations on that file invoke OCFS2 inode callbacks
against the new filesystem's s_fs_info structure, causing superblock
type confusion. In ocfs2_permission(), locking osb->osb_lock hits
invalid spinlock metadata, triggering a spinlock bad magic report and a
kernel oops in spin_bug() when dumping the bogus lock owner pointer.

To fix this issue, we can call ocfs2_release_system_inodes(osb) when
loading the system directory inode fails in
ocfs2_init_global_system_inodes(), matching the error cleanup in the
global system inode loop right below it:

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;

The kernel console output, kernel config, and C reproducer are available
on Google Drive:
https://drive.google.com/drive/folders/15818V1oiyzLPQp7svkt5_GMJ1y7FO6bU?usp=sharing

Best regards,
Jiaming Zhang