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=1796096482; b=MfpE76rqJX4P5qi69Mam3JfFaEOjcwbzS90j9K3RNWiQ5FdbiKwWAYZjv1BDiSUlr/cS H1rFQCZAEt5CbjLKzObTL78pCp1o0I3elMXfS+mmyp3Vs6nnIXHqsRhOkUlgPTMvBArYS l3dDYv0jcQz7pkU/rg/GX9ryxGfOy8e/CSlpv3prb/cZfiv/zTClm6n40OA1eBl8eC9oP I/TKlOFMw7hADYcypDwMF2K4wxDaiBJIIjNwbMLXDCFP2e3l+Wa2gwrcw95SrZDIqxMME +x2ErKcC/nMb2bq73qIaqbPMVT9tADxIZEj+tW7alrbk5QxzFy66Y6OuAPYWMBsaiuQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796096482; 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:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; bh=Fvmp2ScpTyKF/lU2XlG2XIsL5ah6sZiIaiAr8m5vFxE=; b=GZFL3v40U+EqKV+ITNMfawzL9ii93C3Ojuc7n2O1IJpOcu24uanwKbxLY1ANlARsH5LQ ALAJh62khN6W5vc/R+62dZp74w3sSdTHX2nrP9T2j+d2ViA0ZD/zCZiCEZFFtJb4y9ac7 aHggTiyQqf0qns6I57pmfYd8vnY7eKTsRlvObc9/ZFV+nMVoCe4u8CvSwEHMQUGEUPB0N oOuUhWv6Z+i1rpXa7rqMH4CXSTBTxXltXKO0CYfYBI5eHIgN9xND43LaxFsdnJZT91PuP GMcPPq1x+BWEelKLIXN7pZBKaUp5NyM9iaczZktF9H4WIql1fTIodg9cXwYolZyLGUg== 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=I+kHiD8s; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=C5jAxyTi; 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 15E66606A31A for ; Tue, 1 Dec 2026 03:41:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 15E66606A31A 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=I+kHiD8s; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=C5jAxyTi Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id 32F39140091F for ; Mon, 30 Nov 2026 22:41:21 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Mon, 30 Nov 2026 22:41:21 -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:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1796096481; x= 1796182881; bh=Fvmp2ScpTyKF/lU2XlG2XIsL5ah6sZiIaiAr8m5vFxE=; b=I +kHiD8sZ7ZYag0BU+Cc0qt5noWwdgddaZPsPvsyaLfsu22D1lB3INTeGw7GdjbwG MOi3jigPvt5jzXuDDuSzB9WYJi6M+JMxGhUZx7zMFnV3eGv8jpHgVBmpplQ2JZmZ fO/YVhCy+8psxM12RNBYpjO7fvrwwioPONM5uZPn/qbff34ibwbV8aUbug4ufL2X CUQljGiPEWRKZ73m91lJOG33edj71+fcj5+L/OBxAMGNmedfodef/PQplC8F4O5t ElHHTtvNVuEoN2kPhaCfteanTrrYtBb9z1cnH5/lzDkcDo2wJ/YHsoFaX2Ctx78M /nbLAz/dhcxgnnB+t/xBw== 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:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1796096481; x=1796182881; bh=F vmp2ScpTyKF/lU2XlG2XIsL5ah6sZiIaiAr8m5vFxE=; b=C5jAxyTiMa1qqPaIQ ZRZ8V10ASnow74kVlMZxiR8vSFUjivynxMlt+w8KZor+zhpCgV1TKZKsUOadnuUj 4m5BZJXgJi+HvI1Z6YQF6x2HfPGFJD2fcgSx/GzbWDzbUVZPaw0vI+IHVKqsK5Ms 22AHs7dtjaOO3e21U0NBMOYRcj3hBJ6aExG8b2z/TUZ3cnfEpsfnlK1dT9RzlDP3 x+OfdQtvPvW70RkDJviQ4A5/tssy2zaG937wGHfFES0TR9c/+tmwCmCBgVf1st+A ZenxDJRvuzauoClRBbnC5HMPi9Dlgb19RodSMKlLW711YbBcVxSUqSoLFA1cVSPi TBKxA== 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=1796096481; d=fastmail.org; mf=PGljYkBmYXN0bWFpbC5vcmc+; rt=PGxpbnV4LWNpZnNAdmdlci5rZXJuZWwub3JnPg==; s=fm3:rsa-sha256:McRO3+aIR9SXukcjcYuF1EPC3+UyP/1pplkcYYSuJPPGnGw fdVOJlnpitAWbBLm/hYF5a8AjMzeVEdBtpygLZ8K+1kDoNKvK4XkAxtYpRZwcKO2 YFgrljFSiKQ4qmnIev2/IlBbH6IdV/pIY1RTybJOZI3gf9GvO743idEw6lrhmJKl 3+vUFeORlqB68WmRh8mMZjioeMl4knqdaqUrfFlTHYHeWko25hjb1voIU+t3RUvN zTUxKEMB5Fe5yIMMgXaJI2atiN6ierBQWJOBBsWNtya/DRzLILRtrmSpj24RjYfY K45WeJ5GA+hTNukTvOGY2e77fsQM9GrZvgLQEAg==; 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=11; hn=cc,content-transfer-encoding,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:v1UAp7Bwhvh1YhK9GpXDtmh5HXGeD4FytLKP83Pj54w=:Vu9Bau0K+R+Hym27y2mcdxjGLlXkzFA3pacBtjrJrzY=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTE5vRUmRVqt3sOoIAA1Zy0L64F6Cv5BAK2srAnfnaCEeq/8e+beponwNpp1UXP9Iz Oyz1JZjRujb+hIDV2YfGKSkhnS3NtGi4BmL6nZslVyeLBNJKmhmW1NdeC2DwPh5BAPZETn UAedHNNsGm5QQdzxsdISP2p1Wytpw826c/yOfb5pvmXdWC8YyQS7oWduZrse3exw2C0X9i E+RYi1Sx32+q76cq/HuPiHNVFvNUuPuCRZVoXLDycYjjXI/e50CRjql9xL+IfVNY37clGG IU3nuoFsFKMS3UoVLebox+3llKY3+TpqOEt8bPUKSpuKiKZ4/660Mmt9MElt60URJK3soG uFY1lb5lqTrpj6DX989xTNzd+dsyvsHlq5Yd/e8i275MK0WP7IotFNQLlvGRY/KYVvu5yf 8zUH2aAhaj6FuPwm8HgTV6zXiS5UlVuPfev2QMbIYrgydXT39a4kDoTdSzUp7aLF1SJbrH inGHcipB5UO+mM/3VuJsHnM+qz9eNuGHLFpTJMszVMhnSJSf8kg47HF9WERlzvo4aGSesy QvhHikO2yg+sUBeFcQvg9oyQ7hnKAe4ipRlgeSA4pMfFlZxC801XxoKeHBCWQOyDvKZkP0 HC9bsABex5B0bE2+rehcVN8/106feB+3o6uSpmxQUY8n7GJszn12Wqf9mi6Q X-ME-Proxy: Feedback-ID: ib53e4b78:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 30 Nov 2026 22:41:19 -0500 (EST) From: Ian Bridges To: linkinjeon@kernel.org Cc: senozhatsky@chromium.org, tom@talpey.com, chenxiaosong@chenxiaosong.com, linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, Ian Bridges Subject: [PATCH v2] ksmbd: fail FILE_CREATE of a named stream that exists Date: Mon, 30 Nov 2026 21:41:07 -0600 Message-ID: <20261201034107.2178270-1-icb@fastmail.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261201022248.2167102-1-icb@fastmail.org> References: <20261201022248.2167102-1-icb@fastmail.org> X-Mailing-List: linux-cifs@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 An open with FILE_CREATE of a named stream that already exists succeeds, and the client gets a handle to the existing stream. The stream lookup ignores case, so a name that differs only in case also opens the existing stream. A client that uses FILE_CREATE to make a new stream cannot tell that the stream existed, and its writes change the existing data. Fail an open with FILE_CREATE of an existing named stream with STATUS_OBJECT_NAME_COLLISION, as an open with FILE_CREATE of an existing file already fails. The handle gets its stream name before the stream is looked up, so a failed open of a stream is closed as a stream handle. When another handle of the file has delete-on-close on a stream, that close can remove the stream that the failed open named. The new failure would then delete the existing stream. Make the handle a stream handle only after the stream is opened. Suggested-by: ChenXiaoSong Signed-off-by: Ian Bridges --- v2: Make the handle a stream handle only after the stream is opened, as ChenXiaoSong suggested. Sashiko found that the failed FILE_CREATE could remove the existing stream when another handle of the file has delete-on-close on a stream. Tested on ksmbd-for-next 87ff512becd4, on x86_64 with KASAN. A script sent FILE_CREATE of an existing named stream in several forms, and the other dispositions, to the base and to the patched server. Each FILE_CREATE of an existing stream got STATUS_OBJECT_NAME_COLLISION and left the stream as it was. The others gave the same results as on the base. A second script held delete-on-close on one stream of a file and then sent a FILE_CREATE of another existing stream of the file. With v1 the existing stream was removed. With v2 the existing stream was kept. smbtorture gives the same results as on the base, and KASAN reported nothing. This patch was developed with LLM assistance. fs/smb/server/smb2pdu.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index 89aad1acb370..0e0946bd5684 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -3689,6 +3689,7 @@ static int smb2_set_ea(struct smb2_ea_info *eabuf, unsigned int buf_len, static noinline int smb2_set_stream_name_xattr(const struct path *path, struct ksmbd_file *fp, char *stream_name, int s_type, + struct stream *stream, bool *created) { const struct mnt_idmap *idmap = mnt_idmap(path->mnt); @@ -3703,8 +3704,8 @@ static noinline int smb2_set_stream_name_xattr(const struct path *path, if (rc) return rc; - fp->stream.name = xattr_stream_name; - fp->stream.size = xattr_stream_size; + stream->name = xattr_stream_name; + stream->size = xattr_stream_size; /* Keep the existing xattr's case for subsequent writes and removal. */ rc = ksmbd_vfs_casexattr_len(idmap, @@ -3712,7 +3713,7 @@ static noinline int smb2_set_stream_name_xattr(const struct path *path, xattr_stream_name, xattr_stream_size, xattr_stream_name); if (rc >= 0) - return 0; + return fp->cdoption == FILE_CREATE_LE ? -EEXIST : 0; if (rc != -ENOENT && rc != -ENODATA) return rc; @@ -5370,13 +5371,23 @@ int smb2_open(struct ksmbd_work *work) } if (stream_name) { + struct stream stream = {}; + rc = smb2_set_stream_name_xattr(&path, fp, stream_name, s_type, + &stream, &stream_created); - if (rc) + if (rc) { + kfree(stream.name); goto err_out; + } + /* + * Attach the stream only on success, so that a failed lookup + * or creation cannot delete a stream when fp is closed. + */ + fp->stream = stream; file_info = FILE_CREATED; } base-commit: 87ff512becd45a08c44fd47a9f03e607af9ef6bd -- 2.47.3