From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.157 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796098244; b=LB3bqR2qFl7A3EUvZRS7ficD0Q5L76afkhLfwvOPh3OkQ+dM/K/w7evPtRuopX1zYthE LZim3UNYB7/lbibkMF7TjVD6ln7bS/hKZOW10WjI3qrBLbrb4kgAAVh34Cr9bx5Aepygu 1GIkd35YwPw6zS9ta37qYuQ0cS/7JeMvmovNucbgICRXBYbZL0BC7tWPrYSITNtP2yPfy K0kYbogWaMnfivlhcwi/7IKs2Ho2ISOB9OKrbhFBfRlm4FpCeLcTbfGdtfHsVnOj1Aqyj Ma/AgfUaONjYcOPZeXMk3iqtKl3HS45/qDAetWRiTtCpD9NKRiGFjD13r9waBy/lyTQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796098244; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=xqjhfa5Evzvr8L3u8CUQRYC1LLWhYs3juX4/RkFT6wI=; b=LkcMkncl8nbN7fLyLTyBhl+930gUv9Pn3D0hXHMLjw2Q1dq9C+jGUOTwk92Q0ToSEH1s zW5UbSrfUqQ2QDCC0tDWtzNg8iVd0ojxu2jrghoPiscWdDx4uTaCYetncC6yoUWYYMOgg bLsqCFHijmoTBRcSOZp60hi+T0c9WGs58xQFkBwotI2wP5cHMTq6QrhzGseHBWepGb0D/ axqLXGYctSIzKaIww7h2D2G2XcWEjAyW7xJ/6hNSl3m5c9VL4i6kaVlsQtCcpmsvXCzpi lqAJLUKBlt/kfAYECOCo5OSogB9ztqG8kk5xpidsRLUFGhsTKZpDVZcSGqBOVdlCelA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=fastmail.org; spf=pass smtp.mailfrom=fastmail.org; dkim=pass header.d=fastmail.org header.i=@fastmail.org header.a=rsa-sha256 header.s=fm3 header.b=d5SZir3H; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=swzBnofG; arc=none smtp.remote-ip=103.168.172.157 Received: from fhigh-a6-smtp.messagingengine.com (fhigh-a6-smtp.messagingengine.com [103.168.172.157]) (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 2A03E606A31A for ; Tue, 1 Dec 2026 04:10:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2A03E606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=fastmail.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastmail.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=fastmail.org header.i=@fastmail.org header.a=rsa-sha256 header.s=fm3 header.b=d5SZir3H; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=swzBnofG Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id 32C611400915 for ; Mon, 30 Nov 2026 23:10:42 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Mon, 30 Nov 2026 23:10:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.org; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to; s=fm3; t=1796098242; x=1796184642; bh=xqjhfa5Evzvr8L3u8CUQR YC1LLWhYs3juX4/RkFT6wI=; b=d5SZir3HdRxHBeQZSXtZaz74Hun4n3uBjRntr vAHisrG4a//oxcHDEQYydXGHLB5giJvY41ALIw+oRZ6y+0Ok9jSDeuLJq7aEuFYQ sw+MAY7NQgKdRbvP56rV8SmA4Xxr8CpSvsJCKjuYedP9L7PULE2nxkRA7d5Tfwbm 6RRFGLXCN8//odB8iwB6HyQuWICMTxQKEjm6oOhpG4+SGj5VOR5+oNbNFrhDXQy7 xqqBV7ENP9eDvOEgA/MxTDMt6fh43+Y22a2gZfWo0CWsFhi1K6SMfmVSx/AxdZSK /iakQ3D1Pcpely2dAAQ2lqE+T8sKYCFWQIdW7eUaEJ556KPtA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1796098242; x=1796184642; bh=xqjhfa5Evzvr8L3u8CUQRYC1LLWhYs3juX4 /RkFT6wI=; b=swzBnofGz41fVPIPBAn6p3rxCQumgXtBUM8oQqWlWHBMyZrNYMg eEnmIb6ypAlE9lM9gGdq+wHMxX/yewLKQZt8Esg4uv4NkFdtrCpagSXvzRUqCoY+ t1ZfZmONAb5hbU3wFdd/u9PW0TpBNiKMSpGL03AH2rC7mYDi1Qv7Bc+YsItC0NIF v4XvP2Afw9I2kUwBLDMGBAOLBkzR+7LLRyBeFJjImm0FoMk6tV1HlobezlbEN7Qn KDrqWjn4EyZMJHqJw8y9tOfYe22is7jBG4kFhQErnJCz2YRdROt0321bASTbJsfG yC31NdmkR2BibC/2ekUbJ/lvayvKn/SNqUQ== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=fastmail.org a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796098242; d=fastmail.org; mf=PGljYkBmYXN0bWFpbC5vcmc+; rt=PGxpbnV4LWtlcm5lbEB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:Plxl7dv7jZEE9ux3ohvOyOzTwUcXRL8w/nGIc97nn3gygnI C3KeKx7I17dhSwUrmkTuEAp0+mpk305GjnVOYPz6taPzk4o4ZWDywB8w69ZasmxL gSfQjraCtv7gg9+ZdkzZkghKTef/C0oe0nieiVElv/4KHX2icAFCWqwCOzUd7iAF hT7uXqmvNPw/RJNDjF4pkreCS60tgdyRF6rXfl+F4RBt0+1bXj2QSgN//Zuimvea ASo/gPbjQN6pj7oP74++cthDk+JxoapQzbSb8X/dnC3FsQWbMmHOImy95Vmd3U18 DKb+JvGSs3aMEDGIHoGrHH8Jx1jioP2Mic+jyUQ==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=9; hn=cc,content-transfer-encoding,date,feedback-id,from, message-id,mime-version,subject,to; Message-Instance: m=1; h=sha256:OKvC4eB4IKEa3FiZxiJZAFmOsskz+oM2v1BXRslB2gs=:nQKKlRjX8a6Vei44krmQHdOaml2vTHCb+n3OiDL2vXY=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGbBgigbhNT0onm82nocu7gz+HE+VtNkvHi94NAL1fhW6LQakJulW1fuoyl0YZlX0 PFRw6F/dpcPJbkwZQuEj1yYULR3+u6DJ1vu6RfPkHbNEd5bg7Niy546iH6Gf4CBqyZa9yB r2LXGoub+utqgVqsiB9VKtbkPyTj+fG4eon1My9CuLPHIw6fpn1jrqdZVhJ/5eBC/QdwLC JCFPOLPApMUPT2UyIMf93AeLoDGgSKQ2KLnq0WaIfRGIKqtrN1wkxD4vOmauuQc7Wee6Z7 BEBwsdHHNXLoz4pRryH17iWUHlUoBKSg5TdAqnA+sQldROw7XUcXNCsgJMPv6HIQiJnTs/ JV8+ImCy1yiK5SKzMG25SiEXqb34G9vY1ziTlTj7Tgzs4jjdPaW5ltpuG+mxMI+gVVylvB /JimU+NYAoF9aTOoIGxJlhTNZNvxVKzjUdlHoryW3l+Ktv0Si0U1u3KshN1ldwC6kKnA4Z wUy4gs5QuCaItRY5J5Fv+2VurP5cEL5qUl0ki2lG9TwyJRdtuWzRggGlwHHMk4rrFGM/Rl W8q+lhXZc3suk5WB4PUZEYk1LLsUEAF9BfpQBjJsrBf3ntgisQ41EPoSpgFf0HLTvcquwl SQ+m9VoWW16yAyXOHc0zTl/LXSkp0xIcwimeWncYmAWPDoRQRYwKW0YT3STA X-ME-Proxy: Feedback-ID: ib53e4b78:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 30 Nov 2026 23:10:40 -0500 (EST) From: Ian Bridges To: linkinjeon@kernel.org Cc: senozhatsky@chromium.org, tom@talpey.com, chenxiaosong@chenxiaosong.com, gael.blivet@gmail.com, linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, Ian Bridges , stable@vger.kernel.org Subject: [PATCH] ksmbd: delete only the stream whose handle has delete-on-close Date: Mon, 30 Nov 2026 22:10:29 -0600 Message-ID: <20261201041029.2181504-1-icb@fastmail.org> X-Mailer: git-send-email 2.47.3 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A delete-on-close open of a named stream sets a flag on the inode instead of on the handle. The next stream handle of the file to close takes the flag and deletes its own stream. So when another stream handle of the file closes first, that other stream is deleted, and the stream that was opened with delete-on-close is kept. The stream is removed with the credentials of the closing handle. A user who cannot write the file can open one stream with delete-on-close and make another user's handle delete a different stream on close. Record delete-on-close on the stream handle, as FileDispositionInformation on a stream handle already does. Deleting a stream never removes the file, so delete-on-close of a stream no longer makes a new delete-on-close open close the disconnected durable handles of the file. Fixes: f44158485826 ("cifsd: add file operations") Cc: stable@vger.kernel.org Signed-off-by: Ian Bridges --- Tested on ksmbd-for-next 87ff512becd4, on x86_64 with KASAN. A script opened named streams of one file with and without delete-on-close, as the owner and as a user who cannot write the file, and closed the handles in different orders. On the base, the first stream handle to close deleted its own stream. With the patch, only the streams opened with delete-on-close were deleted, and FileDispositionInformation on a stream behaved as on the base. smbtorture gives the same results as on the base, and KASAN reported nothing. This patch was developed with LLM assistance. fs/smb/server/vfs_cache.c | 41 ++++++++++++++++++--------------------- fs/smb/server/vfs_cache.h | 1 + 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/fs/smb/server/vfs_cache.c b/fs/smb/server/vfs_cache.c index 7db0a52dd4ae..a71a5de17653 100644 --- a/fs/smb/server/vfs_cache.c +++ b/fs/smb/server/vfs_cache.c @@ -29,7 +29,6 @@ #define S_DEL_PENDING 1 #define S_DEL_ON_CLS 2 -#define S_DEL_ON_CLS_STREAM 8 static unsigned int inode_hash_mask __read_mostly; static unsigned int inode_hash_shift __read_mostly; @@ -463,11 +462,18 @@ void ksmbd_fd_set_delete_on_close(struct ksmbd_file *fp, { struct ksmbd_inode *ci = fp->f_ci; + if (ksmbd_stream_fd(fp)) { + /* + * Set only by the initial CREATE and read only at final close. + * The opener holds a reference, so the read cannot race with + * this write. + */ + fp->stream_del_on_close = true; + return; + } + down_write(&ci->m_lock); - if (ksmbd_stream_fd(fp)) - ci->m_flags |= S_DEL_ON_CLS_STREAM; - else - ci->m_flags |= S_DEL_ON_CLS; + ci->m_flags |= S_DEL_ON_CLS; up_write(&ci->m_lock); } @@ -478,10 +484,9 @@ void ksmbd_fd_set_delete_on_close(struct ksmbd_file *fp, * the entire file's data along with it. * * This is tracked on fp itself (stream_del_pending), not the shared - * ksmbd_inode: the inode-wide S_DEL_ON_CLS_STREAM flag used by - * ksmbd_fd_set_delete_on_close() can't record *which* stream should be - * deleted, so if a different stream handle on the same file closed - * first, it would delete the wrong stream. + * ksmbd_inode, so that closing fp deletes only the stream that fp has + * open. Delete-on-close of a stream is tracked the same way + * (stream_del_on_close). */ void ksmbd_fd_set_delete_pending(struct ksmbd_file *fp) { @@ -616,20 +621,12 @@ static void __ksmbd_inode_close(struct ksmbd_file *fp) filp = fp->filp; if (ksmbd_stream_fd(fp)) { - bool remove_stream_xattr = false; - - down_write(&ci->m_lock); - if (ci->m_flags & S_DEL_ON_CLS_STREAM) { - ci->m_flags &= ~S_DEL_ON_CLS_STREAM; - remove_stream_xattr = true; - } - up_write(&ci->m_lock); + bool remove_stream_xattr = fp->stream_del_on_close; /* - * Per-handle delete-pending from ksmbd_fd_set_delete_pending() - * (FileDispositionInformation on this stream) -- separate from - * the inode-wide flag above, which only ever meant "some - * stream on this file" with no way to say which one. + * Delete the stream of this handle if the handle was opened + * with delete-on-close or marked delete-pending through + * FileDispositionInformation. */ spin_lock(&fp->f_lock); if (fp->stream_del_pending) { @@ -997,7 +994,7 @@ bool ksmbd_close_disconnected_durable_delete_on_close(struct dentry *dentry) return false; down_write(&ci->m_lock); - if (ci->m_flags & (S_DEL_ON_CLS | S_DEL_ON_CLS_STREAM | S_DEL_PENDING)) { + if (ci->m_flags & (S_DEL_ON_CLS | S_DEL_PENDING)) { list_for_each_entry_safe(fp, tmp, &ci->m_fp_list, node) { if (fp->conn || !fp->is_durable || fp->f_state != FP_INITED) diff --git a/fs/smb/server/vfs_cache.h b/fs/smb/server/vfs_cache.h index bc1955b87855..7253b1296a67 100644 --- a/fs/smb/server/vfs_cache.h +++ b/fs/smb/server/vfs_cache.h @@ -150,6 +150,7 @@ struct ksmbd_file { * was actually marked for deletion. See ksmbd_fd_set_delete_pending(). */ bool stream_del_pending; + bool stream_del_on_close; unsigned int durable_timeout; unsigned int durable_scavenger_timeout; base-commit: 87ff512becd45a08c44fd47a9f03e607af9ef6bd -- 2.47.3