Re: [PATCH] ksmbd: pin parent dentry in maximal access check

From: Namjae Jeon

Date: Mon Nov 16 2026 - 17:11:05 EST


On Tue, Nov 17, 2026 at 12:04 AM Yuansheng Yang <0xbeac@xxxxxxxxx> wrote:
>
> ksmbd_vfs_query_maximal_access() reads dentry->d_parent without holding
> a reference to the parent. smb2_open() calls it after path lookup has
> returned without the parent inode lock. The AppInstanceId takeover
> path also calls it on the old handle's filp->f_path without holding
> that lock. A reference to the child dentry does not pin its old parent
> across a rename.
>
> A concurrent rename can therefore move the child to another directory
> and drop the last reference to the old parent. If the old parent is
> then removed and freed, d_inode(parent) reads the d_inode field of a
> freed dentry. If the sampled parent has become negative, passing its
> NULL inode to inode_permission() can also cause a NULL dereference.
>
> KASAN caught the following on an x86_64 QEMU guest with a test-only
> 100 ms delay between reading d_parent and d_inode:
>
> BUG: KASAN: slab-use-after-free in ksmbd_vfs_query_maximal_access+0x2ba/0x300
> Read of size 8 at addr ffff8881100f0830 by task kworker/2:1/81
> Workqueue: ksmbd-io handle_ksmbd_work
> Call Trace:
> ksmbd_vfs_query_maximal_access+0x2ba/0x300
> smb2_open+0x60d5/0xec30
> handle_ksmbd_work+0xad4/0x2110
> process_one_work+0x745/0x10f0
> worker_thread+0x511/0xc80
> kthread+0x330/0x410
> Allocated by task 319:
> __d_alloc+0x35/0x860
> d_alloc+0x46/0x1f0
> lookup_one_qstr_excl+0x171/0x250
> filename_mkdirat+0xba/0x4c0
> __x64_sys_mkdir+0x6a/0x90
> Freed by task 81:
> kmem_cache_free+0xb8/0x3b0
> rcu_core+0x549/0x17d0
>
> The read is 48 bytes into a freed 192-byte dentry, which is exactly the
> d_inode member.
>
> Commit 2e450920d58b ("ksmbd: move oplock handling after unlock parent
> dir") released the parent lock and reference before the final MXAC
> query in smb2_open(), leaving this helper's bare d_parent access
> unprotected. Commit 4e45cca31d4e ("smb/server: add
> ksmbd_vfs_kern_path()") later switched the earlier open path to an
> unlocked lookup, exposing the MAXIMUM_ALLOWED query as well.
>
> Commit 0383a66dabd7 ("ksmbd: pin parent dentries in SMB2 CREATE ACL
> path") fixed the same race class in smb2_open() and smb_inherit_dacl(),
> but did not cover this helper.
>
> Take a parent reference with dget_parent() and hold it across the
> permission check. If the parent has no inode, leave FILE_DELETE unset.
>
> OpenAI Codex assisted with reviewing the fix and revising the changelog.
>
> Fixes: 2e450920d58b ("ksmbd: move oplock handling after unlock parent dir")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Yuansheng Yang <0xbeac@xxxxxxxxx>
Applied it to #ksmbd-for-next.
Thanks!