* [PATCH] ksmbd: pin parent dentry in rename share check
@ 2026-11-16 16:19 Yuansheng Yang
0 siblings, 0 replies; only message in thread
From: Yuansheng Yang @ 2026-11-16 16:19 UTC (permalink / raw)
To: Namjae Jeon
Cc: Sergey Senozhatsky, Tom Talpey, ChenXiaoSong, linux-cifs,
linux-kernel, stable
ksmbd_vfs_check_rename_share() passes old_path->dentry->d_parent to
ksmbd_lookup_fd_inode() without taking a reference to the parent.
Although the call in ksmbd_vfs_rename() runs with the parent directory
locked, smb2_rename() also calls this helper before entering the VFS
rename path, without that lock.
A concurrent rename can move the child to another directory and drop
the last reference to its old parent. If that parent is then removed
and freed, ksmbd_lookup_fd_inode() reads d_inode from a freed dentry.
Holding a reference to the child does not keep its old parent alive
across a rename.
KASAN caught this on an x86_64 QEMU guest with a test-only 100 ms delay
between sampling d_parent and calling ksmbd_lookup_fd_inode():
BUG: KASAN: slab-use-after-free in ksmbd_lookup_fd_inode+0x28c/0x2b0
Read of size 8 at addr ffff88810faa6f30 by task kworker/3:2/76
Workqueue: ksmbd-io handle_ksmbd_work
Call Trace:
ksmbd_lookup_fd_inode+0x28c/0x2b0
ksmbd_vfs_check_rename_share+0x8e/0x240
smb2_set_info+0x2b71/0x3bb0
handle_ksmbd_work+0xad4/0x2110
The read is 48 bytes into a freed 192-byte dentry, at its d_inode
member. The stack reaches the unlocked smb2_rename() call, inlined
into smb2_set_info(), rather than the check inside ksmbd_vfs_rename().
Take a parent reference with dget_parent() and hold it until the
lookup completes. If the parent has no inode, skip the lookup and
report no parent sharing conflict. The returned ksmbd_file has its
own reference, so the parent can be released before checking sharing.
OpenAI Codex assisted with reviewing the archived fix and preparing
the changelog and validation materials.
Fixes: 7f8029591bed ("ksmbd: synchronize lease breaks before renaming files")
Cc: stable@vger.kernel.org
Signed-off-by: Yuansheng Yang <0xbeac@gmail.com>
---
This is a standalone fix against ksmbd-for-next at c710c654b8a3.
It is independent of the maximal-access patch sent separately.
The existing KASAN report was captured on 7e1392a42ea2 using a local
rename/rmdir workload in a tmpfs share and an SMB rename request.
The 100 ms delay was only in the test kernel and is not in this patch.
The reproducer and full report are available on request.
Testing: git apply --check and an x86_64 KASAN build of
fs/smb/server/vfs.o on c710c654b8a3. Both this patch and the
maximal-access patch apply in either order. Checkpatch reports no
errors; its only warning is the missing Fixes commit in the local
shallow clone, whose subject and diff were checked upstream.
With the fix, the same 100 ms delay was placed after dget_parent()
and before the d_inode() check. On a 7e1392a42ea2 KASAN guest that
also included 0383a66dabd7 and the maximal-access fix, 80 SMB rename
requests each took about 100 ms and returned STATUS_OBJECT_NAME_INVALID.
There was no KASAN report and the guest stayed up. Those two extra
patches only keep the open path off the other parent-dentry bugs; this
fix does not depend on them. The race has not been tested without the
artificial delay.
fs/smb/server/vfs.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
index 7c3edbe6cb77..d99eb28c63e0 100644
--- a/fs/smb/server/vfs.c
+++ b/fs/smb/server/vfs.c
@@ -731,9 +731,16 @@
const struct path *old_path)
{
struct ksmbd_file *parent_fp;
+ struct dentry *parent;
int err = 0;
- parent_fp = ksmbd_lookup_fd_inode(old_path->dentry->d_parent);
+ parent = dget_parent(old_path->dentry);
+ if (!d_inode(parent)) {
+ dput(parent);
+ return 0;
+ }
+ parent_fp = ksmbd_lookup_fd_inode(parent);
+ dput(parent);
if (!parent_fp)
return 0;
base-commit: c710c654b8a3c92b34e38740dc17c29daf5b222e
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-16 16:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 16:19 [PATCH] ksmbd: pin parent dentry in rename share check Yuansheng Yang
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®