Re: [PATCH] ksmbd: pin parent dentry in rename share check
From: Namjae Jeon
Date: Mon Nov 16 2026 - 17:11:13 EST
On Tue, Nov 17, 2026 at 1:19 AM Yuansheng Yang <0xbeac@xxxxxxxxx> wrote:
>
> 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@xxxxxxxxxxxxxxx
> Signed-off-by: Yuansheng Yang <0xbeac@xxxxxxxxx>
Applied it to #ksmbd-for-next.
Thanks!