[Linux Kernel Bug] INFO: task hung in gfs2_permission

From: Jiaming Zhang

Date: Sun Dec 06 2026 - 06:18:31 EST


Hi Linux kernel developers and maintainers,

We are writing to report a hung-task issue in the GFS2 subsystem,
reproducible on the latest version of linux (v7.4-rc5, commit
fe6ff8d5d675) and linux-gfs2 for-next branch (commit 02b63d3f6c2d).

It is triggered by mounting a crafted GFS2 image whose allocation
bitmap marks an already-live system inode block as free (requiring
CAP_SYS_ADMIN to mount), creating a file in a directory, and running
a concurrent path lookup through it. Below is the kernel report:

INFO: task repro.out:9446 blocked for more than 10 seconds.
Not tainted 7.4.0-rc5 #62
task:repro.out state:D stack:22384 pid:9446 tgid:9446
ppid:9445 task_flags:0x400100 flags:0x00080000
Call Trace:
<TASK>
context_switch kernel/sched/core.c:5615 [inline]
__schedule+0x17c5/0x5b30 kernel/sched/core.c:7437
__schedule_loop kernel/sched/core.c:7514 [inline]
schedule+0x165/0x2b0 kernel/sched/core.c:7529
bit_wait+0x13/0x110 kernel/sched/wait_bit.c:248
__wait_on_bit+0xb9/0x320 kernel/sched/wait_bit.c:52
out_of_line_wait_on_bit+0x134/0x180 kernel/sched/wait_bit.c:67
wait_on_bit include/linux/wait_bit.h:78 [inline]
gfs2_glock_wait+0xb3/0x2a0 fs/gfs2/glock.c:1239
gfs2_glock_nq_init fs/gfs2/glock.h:253 [inline]
gfs2_permission+0x246/0x440 fs/gfs2/inode.c:1997
do_inode_permission fs/namei.c:583 [inline]
inode_permission+0x44e/0x5d0 fs/namei.c:653
lookup_inode_permission_may_exec fs/namei.c:699 [inline]
may_lookup fs/namei.c:1982 [inline]
link_path_walk+0x11f5/0x19d0 fs/namei.c:2610
path_lookupat+0xe4/0x8c0 fs/namei.c:2818
filename_lookup+0x212/0x570 fs/namei.c:2848
filename_setxattr+0xae/0x610 fs/xattr.c:685
path_setxattrat+0x367/0x3b0 fs/xattr.c:734
__do_sys_lsetxattr fs/xattr.c:775 [inline]
__se_sys_lsetxattr fs/xattr.c:771 [inline]
__x64_sys_lsetxattr+0xbf/0xe0 fs/xattr.c:771
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>

Showing all locks held in the system:
locks held by repro.out/9462: 2, on CPU#0:
#0: ffff88804b8f4478 (sb_writers#11){.+.+}-{0:0}, at:
mnt_want_write+0x41/0x90 fs/namespace.c:531
#1: ffff888054ee4100 (&type->i_mutex_dir_key#7){+.+.}-{4:4}, at:
inode_lock include/linux/fs.h:1027 [inline]
#1: ffff888054ee4100 (&type->i_mutex_dir_key#7){+.+.}-{4:4}, at:
lookup_open+0x226/0x1760 fs/namei.c:4468

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 hung-task report triggers because a path lookup task sleeps forever
in gfs2_permission() waiting for the directory's cluster lock (glock),
while a concurrent file-creation task holds that glock exclusively and
spins indefinitely inside gfs2_create_inode().

When creating a file, gfs2_create_inode() acquires the parent
directory's exclusive glock, allocates a free block from a resource
group bitmap, and inserts the new VFS inode into the inode hash table
keyed by its disk block address via insert_inode_locked4().

Since commit 4ec3c19d058f ("gfs2: Handle -EBUSY result of
insert_inode_locked4"), gfs2_create_inode() retries unconditionally
whenever insert_inode_locked4() returns -EBUSY. That retry loop was
meant for brief races with an earlier lookup or failing create at the
same block address.

On a corrupt filesystem whose allocation bitmap marks a live, pinned
inode block (such as statfs, rindex, quota, or root) as free, the
allocator hands out that in-use block address. insert_inode_locked4()
finds the live inode in the hash table, drops its temporary reference
without unhashing the live inode, and returns -EBUSY on every attempt.

Because the live inode stays hashed, the creator task spins forever
while holding the directory's VFS lock, exclusive glock, and write
protection. Concurrent lookups and permission checks block permanently
on the directory glock, preventing directory access and unmount and
triggering a hung-task report.

To fix this issue, we can call inode_insert5() directly in
gfs2_create_inode(), retry with a bounded deadline only when the
colliding inode is NULL (still being created) or has zero links, and
otherwise report filesystem corruption via gfs2_consist_inode() and
fail with -EIO without deallocating the live block:

diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 75fb1a0c9142..2541c04b9d1f 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -18,6 +18,7 @@
#include <linux/iomap.h>
#include <linux/security.h>
#include <linux/fiemap.h>
+#include <linux/sched/signal.h>
#include <linux/uaccess.h>

#include "gfs2.h"
@@ -709,13 +710,14 @@ static int gfs2_create_inode(struct inode *dir,
struct dentry *dentry,
const struct qstr *name = &dentry->d_name;
struct posix_acl *default_acl, *acl;
struct gfs2_holder d_gh, gh;
- struct inode *inode = NULL;
+ struct inode *inode = NULL, *old;
struct gfs2_inode *dip = GFS2_I(dir), *ip;
struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
struct gfs2_glock *gl = NULL, *io_gl;
int error, dealloc_error;
u32 aflags = 0;
unsigned blocks = 1;
+ unsigned long deadline = 0;
struct gfs2_diradd da = { .bh = NULL, .save_loc = 1, };
bool xattr_initialized = false;

@@ -846,14 +848,33 @@ static int gfs2_create_inode(struct inode *dir,
struct dentry *dentry,
if (error)
goto fail_dealloc_inode;
gfs2_cancel_delete_work(io_gl);
- io_gl->gl_no_formal_ino = ip->i_no_formal_ino;

+ inode_state_set_raw(inode, I_CREATING);
retry:
- error = insert_inode_locked4(inode, ip->i_no_addr, iget_test, &ip->i_no_addr);
- if (error == -EBUSY)
- goto retry;
- if (error)
- goto fail_gunlock2;
+ old = inode_insert5(inode, ip->i_no_addr, iget_test, NULL,
+ &ip->i_no_addr);
+ if (old != inode) {
+ bool retry = !old || !old->i_nlink;
+
+ iput(old);
+ if (retry && !fatal_signal_pending(current)) {
+ if (!deadline) {
+ deadline = jiffies + HZ;
+ cond_resched();
+ goto retry;
+ }
+ if (time_before(jiffies, deadline)) {
+ schedule_timeout_killable(1);
+ goto retry;
+ }
+ }
+ gfs2_consist_inode(dip);
+ error = -EIO;
+ gfs2_glock_put(io_gl);
+ ip->i_no_addr = 0;
+ goto fail_free_inode;
+ }
+ io_gl->gl_no_formal_ino = ip->i_no_formal_ino;

error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT | GL_NOPID,
&ip->i_iopen_gh);

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

Best regards,
Jiaming Zhang