From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796388691; b=tQNyLFS1ZKLQY6rb/cpsB9NXBK+BYsl89PZV3HnqyB2YMreyxc6SZjfnOx/2MwJMawI1 qoNtxZ3xKXfLn8KZQtdt7/WdDhxPFklPnWMTsb3UBuuMX1B+/O62cdDjAEPmaHKqSWgyG fNIx4XFLIUa1PJAplelQSCrvf8D2Zx1VtR8Yz2K10vV9TL2fP8nXMvE6FDN1R6vKCzV3Z 9TvhfC863RcPAk69NONNrBlazUffamaHePzL52N6OOSRvx1DrhcuaigOAuHoDOLsPm0aV 93a21zuoEv29eMH/tl/2IxuByIlTTlOxTiprddUhCgusOLnw3yZMbRNuem9tgXsMmKw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388691; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=j8EdaX18HTWMxDK/BQ9zBhKhs3v0hxtW8vMIThvZOys=; b=HPrbYnK+cA7uOthc46m9FYzsgsvo3ObJtZJa7reU3ralIKafJw3GVDz8xydmioI2Z7VP faG57+4z2xMxvmZBSrOJk3/zPHFU8Be5JAhw49fVavWOc4sl0Db86TTU/+EQ6mnccXaaK klfB8wb6p0MrMu3OtIv1sxuha5mTpZnLWhiDpgf8XY5pFomwK8whWSJXuNTc0jHMEkPxO 3RiAgOIutpXAJm/SlWbHqQWpvHmUOzFPgGopoMzqZaAfMsiQS/9VrG14mfhw1vl1Ugs3E 1jbLO2sXSg+j4t6saogeoBTHwzywWrPNh3jg+/KlJG/Akh9OqGUtEs6Ea4/aKtGg9ew== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=rDypcw11; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24077606A33A; Fri, 4 Dec 2026 12:51:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=rDypcw11 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DAA61F00933; Fri, 4 Dec 2026 12:51:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388690; bh=j8EdaX18HTWMxDK/BQ9zBhKhs3v0hxtW8vMIThvZOys=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rDypcw11xqHz5hf7F498SEGDTuX2y9okYzpm+Kt2pfvmVBYgwI3XzIkX+tdVLjHNj TpEOKcAJTc/uwP5FwaOtX1NQPyQ1hZGBoGr/XP5OkM7/5EKD2c5NZALmExXfSyg3jZ HlNJResP05nhlZIEc0Xm1Z0H8y659UCDPm59+dRQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable@kernel.org, Jiwoo Kim , Namjae Jeon , Sasha Levin Subject: [PATCH 6.1 0676/1059] ksmbd: pin parent dentries in SMB2 CREATE ACL path Date: Fri, 4 Dec 2026 19:03:27 +0900 Message-ID: <20261204100701.527841708@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiwoo Kim [ Upstream commit 0383a66dabd7aa06237b9b24713c03656abeffe4 ] smb2_open() and smb_inherit_dacl() read a child's d_parent without a dentry reference. A concurrent SMB request can move the child and remove the parent while CREATE uses its inode for permission, status, and ACL inheritance work. A remote SMB race with concurrent opener and mover connections on a writable KSMBD acl_xattr share triggered an 8-byte slab-use-after-free read in get_cached_acl on tmpfs and ext4 KASAN guests. With oops=panic, it also caused an Oops and kernel panic on an ext4 guest. Take a parent dentry reference around each parent inode or ACL access in these paths and release it when the operation completes. Treat a negative parent dentry as -ENOENT for the affected operation. On a tmpfs KASAN QEMU guest, two 3,000-round reproducer instances completed without a KASAN report or Oops; SMB remained reachable. On an ext4 non-KASAN QEMU guest with oops=panic, a 2,000-operation no-race control and two 5,000-round reproducer instances completed without an Oops or panic. An SMB health probe still succeeded. OpenAI Codex assisted with finding the bug, generating the SMB race reproducer, drafting this fix and changelog, and running the tests. Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3") Cc: stable@kernel.org Signed-off-by: Jiwoo Kim Signed-off-by: Namjae Jeon [ sashal: Replaced idmap with user_ns throughout and dropped the include, since this tree's smbacl.c has no KUnit hooks and the smbacl.c context lines differ. ] Signed-off-by: Sasha Levin --- fs/smb/server/smb2pdu.c | 39 +++++++++++++++++++++++++++++++-------- fs/smb/server/smbacl.c | 9 ++++++++- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index 70150e016e6f7..cd01774de5f0c 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -3188,16 +3188,32 @@ int smb2_open(struct ksmbd_work *work) if ((daccess & FILE_DELETE_LE) || (req->CreateOptions & FILE_DELETE_ON_CLOSE_LE)) { - rc = inode_permission(user_ns, - d_inode(path.dentry->d_parent), - MAY_EXEC | MAY_WRITE); + struct dentry *parent = dget_parent(path.dentry); + struct inode *parent_inode = d_inode(parent); + + if (parent_inode) + rc = inode_permission(user_ns, parent_inode, + MAY_EXEC | MAY_WRITE); + else + rc = -ENOENT; + dput(parent); if (rc) goto err_out; } } } - rc = ksmbd_query_inode_status(path.dentry->d_parent); + { + struct dentry *parent = dget_parent(path.dentry); + + if (!d_inode(parent)) { + dput(parent); + rc = -ENOENT; + goto err_out; + } + rc = ksmbd_query_inode_status(parent); + dput(parent); + } if (rc == KSMBD_INODE_STATUS_PENDING_DELETE) { rc = -EBUSY; goto err_out; @@ -3251,10 +3267,17 @@ int smb2_open(struct ksmbd_work *work) if (created) { int posix_acl_rc; struct inode *inode = d_inode(path.dentry); - - posix_acl_rc = ksmbd_vfs_inherit_posix_acl(user_ns, - &path, - d_inode(path.dentry->d_parent)); + struct inode *parent_inode; + struct dentry *parent; + + parent = dget_parent(path.dentry); + parent_inode = d_inode(parent); + if (parent_inode) + posix_acl_rc = ksmbd_vfs_inherit_posix_acl(user_ns, &path, + parent_inode); + else + posix_acl_rc = -ENOENT; + dput(parent); if (posix_acl_rc) ksmbd_debug(SMB, "inherit posix acl failed : %d\n", posix_acl_rc); diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c index cb434c7539e02..e021c6bf79682 100644 --- a/fs/smb/server/smbacl.c +++ b/fs/smb/server/smbacl.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -1184,7 +1185,7 @@ int smb_inherit_dacl(struct ksmbd_conn *conn, struct smb_acl *parent_pdacl; struct smb_ntsd *parent_pntsd = NULL; struct smb_sid owner_sid, group_sid; - struct dentry *parent = path->dentry->d_parent; + struct dentry *parent; struct user_namespace *user_ns = mnt_user_ns(path->mnt); int inherited_flags = 0, flags = 0, i, ace_cnt = 0, nt_size = 0, pdacl_size; int rc = 0, num_aces, pntsd_type, ppntsd_size, acl_len, aces_size; @@ -1193,8 +1194,14 @@ int smb_inherit_dacl(struct ksmbd_conn *conn, char *aces_base; bool is_dir = S_ISDIR(d_inode(path->dentry)->i_mode); + parent = dget_parent(path->dentry); + if (!d_inode(parent)) { + dput(parent); + return -ENOENT; + } ppntsd_size = ksmbd_vfs_get_sd_xattr(conn, user_ns, parent, &parent_pntsd); + dput(parent); if (ppntsd_size <= 0) return -ENOENT; -- 2.53.0