From: Drif Abdelmalek Mohamed Said <drifabdelmalekmohamedsaid@gmail.com>
To: Breno Leitao <leitao@debian.org>,
Andreas Hindborg <a.hindborg@kernel.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
syzkaller-bugs@googlegroups.com,
syzbot+63336d70e1af377d7388@syzkaller.appspotmail.com,
Ran Hongyun <ranhongyun1@huawei.com>,
Drif Abdelmalek Mohamed Said
<drifabdelmalekmohamedsaid@gmail.com>
Subject: [PATCH v3] configfs: fix slab-UAF Write in config_item_put
Date: Thu, 5 Nov 2026 17:50:54 +0100 [thread overview]
Message-ID: <20261105165055.362-1-drifabdelmalekmohamedsaid@gmail.com> (raw)
syzbot reported:
BUG: KASAN: slab-use-after-free in config_item_put+0x26/0x90
fs/configfs/item.c:149
Call Trace:
...
config_item_put+0x26/0x90 fs/configfs/item.c:149
configfs_symlink+0x6be/0x11d0 fs/configfs/symlink.c:225
vfs_symlink+0x18b/0x330 fs/namei.c:5823
filename_symlinkat+0x1cd/0x420 fs/namei.c:5848
Allocated by task 5712:
...
nvmet_ports_make+0xe6/0xf00 drivers/nvme/target/configfs.c:2054
configfs_mkdir+0x4f6/0x9e0 fs/configfs/dir.c:1369
vfs_mkdir+0x408/0x620 fs/namei.c:5439
filename_mkdirat+0x289/0x520 fs/namei.c:5472
Freed by task 5712:
...
config_item_cleanup fs/configfs/item.c:128 [inline]
config_item_release+0x13a/0x2d0 fs/configfs/item.c:137
configfs_rmdir+0x885/0x950 fs/configfs/dir.c:1580
vfs_rmdir+0x3e9/0x6b0 fs/namei.c:5544
filename_rmdir+0x292/0x520 fs/namei.c:5601
configfs_symlink() takes a reference on parent_item, drops the directory
inode lock around get_target(), and puts the reference at the end. If a
concurrent rmdir removes the group in that window, and parent_item is a
default group embedded in a larger object (e.g. nvmet_port.subsys_group),
the reference does not keep the containing object alive. The object is
freed, and the final config_item_put(parent_item) hits freed memory.
The syzbot reproducer hits this by racing symlinkat() into
ports/1/subsystems against rmdir of ports/1.
Fix this by not holding parent_item across the unlocked window: put it
before inode_unlock(), and look it up again from dentry->d_parent after
inode_lock(), returning -ENOENT if the lookup fails.
That is not enough on its own. configfs_get_config_item() only fails if
the parent dentry was unhashed, but if simple_rmdir() fails, rmdir skips
d_drop() and the dentry stays hashed even though the directory is already
detached. Default groups are detached through configfs_detach_group(),
which marks children S_DEAD, so also check IS_DEADDIR(dir) after retaking
the lock and return -ENOENT.
Reported-by: syzbot+63336d70e1af377d7388@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=63336d70e1af377d7388
Tested-by: syzbot+63336d70e1af377d7388@syzkaller.appspotmail.com
Signed-off-by: Drif Abdelmalek Mohamed Said <drifabdelmalekmohamedsaid@gmail.com>
---
v3:
- Removed redundant null assignment to parent_item
- Simplified commit body to not rely heavily on repro
explain bug and fix logic
v2: https://lore.kernel.org/all/20261023162906.2938-1-drifabdelmalekmohamedsaid@gmail.com/T/
v1: https://lore.kernel.org/all/20261017123748.4430-1-drifabdelmalekmohamedsaid@gmail.com/T/
fs/configfs/symlink.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/fs/configfs/symlink.c b/fs/configfs/symlink.c
index 89178f5d371a..62d13ce5b46a 100644
--- a/fs/configfs/symlink.c
+++ b/fs/configfs/symlink.c
@@ -196,12 +196,26 @@ int configfs_symlink(const struct mnt_idmap *idmap, struct inode *dir,
*
* AV, a thoroughly annoyed bastard.
*/
+
+ /* Put the reference back, retake and check after relocking */
+ config_item_put(parent_item);
inode_unlock(dir);
ret = get_target(symname, &target_item, &target_sd, dentry->d_sb);
inode_lock(dir);
if (ret)
goto out_put;
+ if (IS_DEADDIR(dir)) {
+ ret = -ENOENT;
+ goto out_put_target;
+ }
+
+ parent_item = configfs_get_config_item(dentry->d_parent);
+ if (!parent_item) {
+ ret = -ENOENT;
+ goto out_put_target;
+ }
+
if (dentry->d_inode || d_unhashed(dentry))
ret = -EEXIST;
else
@@ -218,6 +232,7 @@ int configfs_symlink(const struct mnt_idmap *idmap, struct inode *dir,
target_item);
}
+out_put_target:
configfs_put(target_sd);
config_item_put(target_item);
--
2.43.0
next reply other threads:[~2026-11-05 16:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 16:50 Drif Abdelmalek Mohamed Said [this message]
2026-11-06 16:43 ` Breno Leitao
2026-11-06 17:30 ` DRIF ABDELMALEK MOHAMED SAID
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=20261105165055.362-1-drifabdelmalekmohamedsaid@gmail.com \
--to=drifabdelmalekmohamedsaid@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=leitao@debian.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ranhongyun1@huawei.com \
--cc=syzbot+63336d70e1af377d7388@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=viro@zeniv.linux.org.uk \
/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®