[PATCH v2 1/2] configfs: fix use-after-free of default group in configfs_symlink()

From: Izaac Chong

Date: Sat Nov 14 2026 - 00:30:15 EST


configfs_symlink() drops the parent directory's inode lock while it
resolves the link target, and keeps a reference to parent_item across
that window. When the parent is a default group, such as
ports/<n>/subsystems/ in the NVMe target, parent_item is embedded in
the containing object (struct nvmet_port). A reference on the embedded
item does not keep the containing object alive, so a concurrent rmdir of
the port can free it. allow_link() and the final config_item_put() then
touch freed memory:

BUG: KASAN: slab-use-after-free in nvmet_port_subsys_allow_link+0x41/0x2e0
Call Trace:
nvmet_port_subsys_allow_link+0x41/0x2e0 drivers/nvme/target/configfs.c:1059
configfs_symlink+0x59a/0x1030 fs/configfs/symlink.c:196
vfs_symlink+0x18b/0x330 fs/namei.c:5794

detach_groups() marks a default group's directory S_DEAD while holding
that directory's inode lock, before the containing object can be freed.
So drop the parent_item reference before unlocking dir, and after
re-taking the lock return -ENOENT if dir is dead. Otherwise look
parent_item up again, which is safe while dir is locked and alive.

Fixes: 351e5d869e5a ("configfs: fix a deadlock in configfs_symlink()")
Reported-by: syzbot+b0996ac2197dd7420c3e@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=b0996ac2197dd7420c3e
Cc: linux-nvme@xxxxxxxxxxxxxxxxxxx
Signed-off-by: Izaac Chong <izaacchong934@xxxxxxxxx>
---
fs/configfs/symlink.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/fs/configfs/symlink.c b/fs/configfs/symlink.c
index 89178f5d371a..1b2c9048a920 100644
--- a/fs/configfs/symlink.c
+++ b/fs/configfs/symlink.c
@@ -166,11 +166,11 @@ int configfs_symlink(const struct mnt_idmap *idmap, struct inode *dir,

parent_item = configfs_get_config_item(dentry->d_parent);
type = parent_item->ci_type;
+ config_item_put(parent_item);

- ret = -EPERM;
if (!type || !type->ct_item_ops ||
!type->ct_item_ops->allow_link)
- goto out_put;
+ return -EPERM;

/*
* This is really sick. What they wanted was a hybrid of
@@ -200,7 +200,20 @@ int configfs_symlink(const struct mnt_idmap *idmap, struct inode *dir,
ret = get_target(symname, &target_item, &target_sd, dentry->d_sb);
inode_lock(dir);
if (ret)
- goto out_put;
+ return ret;
+
+ /*
+ * parent_item may be a default group embedded in an object that a
+ * concurrent rmdir freed while dir was unlocked, so we dropped our
+ * reference above. detach_groups() marks dir S_DEAD under its inode
+ * lock before the containing object can go away, so it is safe to
+ * look parent_item up again only if dir is still alive.
+ */
+ if (IS_DEADDIR(dir)) {
+ ret = -ENOENT;
+ goto out_put_target;
+ }
+ parent_item = configfs_get_config_item(dentry->d_parent);

if (dentry->d_inode || d_unhashed(dentry))
ret = -EEXIST;
@@ -218,11 +231,10 @@ int configfs_symlink(const struct mnt_idmap *idmap, struct inode *dir,
target_item);
}

+ config_item_put(parent_item);
+out_put_target:
configfs_put(target_sd);
config_item_put(target_item);
-
-out_put:
- config_item_put(parent_item);
return ret;
}


--
Git-143)