mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xingyuan Mo <hdthky0@gmail.com>
To: Namjae Jeon <linkinjeon@kernel.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Tom Talpey <tom@talpey.com>,
	ChenXiaoSong <chenxiaosong@chenxiaosong.com>
Cc: "open list:KERNEL SMB3 SERVER (KSMBD)"
	<linux-cifs@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	Xingyuan Mo <hdthky0@gmail.com>
Subject: [PATCH] ksmbd: fix use-after-free of parent dentry in lease break notification
Date: Fri, 13 Nov 2026 12:11:41 +0800	[thread overview]
Message-ID: <20261113041112.3736417-1-hdthky0@gmail.com> (raw)

smb_send_parent_lease_break_noti() and smb_lazy_parent_lease_break_close()
pass the raw fp->filp->f_path.dentry->d_parent to
ksmbd_inode_lookup_lock() without holding a reference on the parent
dentry.  If the file is renamed out of its parent directory and the now
empty directory is removed concurrently, the parent dentry can be freed
before __ksmbd_inode_lookup() dereferences it, leading to a
use-after-free read of its d_inode field:

  BUG: KASAN: slab-use-after-free in __ksmbd_inode_lookup+0x21/0x100
  Read of size 8 at addr ffff88801aea06e8 by task kworker/0:7/332
  Workqueue: ksmbd-io handle_ksmbd_work
  Call Trace:
   __asan_load8+0x82/0xb0
   __ksmbd_inode_lookup+0x21/0x100
   ksmbd_inode_lookup_lock+0x25/0x50
   smb_send_parent_lease_break_noti+0x119/0x3a0
   smb2_open+0x5298/0x5df0
   handle_ksmbd_work+0x4f3/0xd30
  Allocated by task 11:
   __d_alloc+0x3a/0x410
   __d_alloc_parallel+0xd9/0xc00
   lookup_slow+0x49/0x70
  Freed by task 66:
   kmem_cache_free+0x22d/0x530
   __d_free+0x26/0x30
   dentry_free+0x8d/0x130
   dentry_kill+0x2e8/0x5a0
   dput+0x17/0x30
  The buggy address belongs to the object at ffff88801aea0680
  The buggy address is located 104 bytes inside of freed 352-byte region

The read at +104 is exactly the d_inode member of the parent dentry,
which was freed through dput() -> dentry_kill() -> dentry_free() after
the file had been renamed out of the directory and the directory was
removed.

Pin the parent with dget_parent() around the lookup in both functions so
that it stays alive until the lookup completes.

Fixes: d47d9886aeef7 ("ksmbd: send v2 lease break notification for directory")
Fixes: c2a721eead712 ("ksmbd: lazy v2 lease break on smb2_write()")
Signed-off-by: Xingyuan Mo <hdthky0@gmail.com>
---
 fs/smb/server/oplock.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/fs/smb/server/oplock.c b/fs/smb/server/oplock.c
index d479508c06c5f..c933d1e5f5458 100644
--- a/fs/smb/server/oplock.c
+++ b/fs/smb/server/oplock.c
@@ -1760,13 +1760,16 @@ void smb_send_parent_lease_break_noti(struct ksmbd_file *fp,
 				      struct lease_ctx_info *lctx)
 {
 	struct oplock_info *opinfo;
+	struct dentry *parent;
 	struct ksmbd_inode *p_ci = NULL;
 	LIST_HEAD(brk_list);
 
 	if (lctx && lctx->version != 2)
 		return;
 
-	p_ci = ksmbd_inode_lookup_lock(fp->filp->f_path.dentry->d_parent);
+	parent = dget_parent(fp->filp->f_path.dentry);
+	p_ci = ksmbd_inode_lookup_lock(parent);
+	dput(parent);
 	if (!p_ci)
 		return;
 
@@ -1797,6 +1800,7 @@ void smb_send_parent_lease_break_noti(struct ksmbd_file *fp,
 void smb_lazy_parent_lease_break_close(struct ksmbd_file *fp)
 {
 	struct oplock_info *opinfo;
+	struct dentry *parent;
 	struct ksmbd_inode *p_ci = NULL;
 	LIST_HEAD(brk_list);
 
@@ -1809,7 +1813,9 @@ void smb_lazy_parent_lease_break_close(struct ksmbd_file *fp)
 	}
 	rcu_read_unlock();
 
-	p_ci = ksmbd_inode_lookup_lock(fp->filp->f_path.dentry->d_parent);
+	parent = dget_parent(fp->filp->f_path.dentry);
+	p_ci = ksmbd_inode_lookup_lock(parent);
+	dput(parent);
 	if (!p_ci)
 		return;
 
-- 
2.43.0


                 reply	other threads:[~2026-11-13  4:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261113041112.3736417-1-hdthky0@gmail.com \
    --to=hdthky0@gmail.com \
    --cc=chenxiaosong@chenxiaosong.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=senozhatsky@chromium.org \
    --cc=tom@talpey.com \
    /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®