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=1796096483; b=oU03JwijGuA17vHTnN/Jr95VOV3NmlktrS523lu1PwLfFxjcD/IKRF7l/1AQZ5VRntY8 iwuQ/ZHOl+qZjT80LzqUkSXKGTlsLKDHOm8bGhRnfZJ7RvMg5wQXgNc3GPMdY44MO2nPB XAHTrLxX/g1fndyhG0eS1oUs+a2TM64QwtjkA5FwLLEaHlc4xmsz31twBj8mJVYhoxhnJ sv4XBFzAtxC695HMHd8OPqsrcYSgFqb52LlOBnL/wk5GEPrXhCHm7D3bbdJrmDADJAoL8 RdZdFTxUM6Q12xnGOgftYMtx7z1QKzV37PJXsA2/MI72i/duLl+w34emQnUvC28lcyw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796096483; 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=jOWeeAz/BOllq+x8BhB5UT4icxqO9JrhrMkpCwFx3Kgg2U8TnydmgvrkjDL0cOlkgDt1 PBixtsaxjyWymkAga0wOrf7BGj/EetnGcstX6tnK6Be7uu6gO30SI1iT2h7JCzO1nKnen ZNSAEJP2cbVmdtdhYSH4Ub0o4KfZvDi/JGBcfMyWbfKCY9B86atcEDXT99aEwFKCyqjXA PAHSaUbVqAkaKD6FlYb+T4WP+vMFA56SCAk518v+6KokiohPm4pt/7ZNv4qTMtLzeC/DX lANlq225OJZr0iOOfTs2y6M1Kl//GLjMeSg7vyTvpLmFwgHWncIGIdlj5aZw8NC0DCQ== 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 15F51606A320 for ; Tue, 1 Dec 2026 03:41:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 15F51606A320 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 33D201400920 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=PGxpbnV4LWtlcm5lbEB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:UjgMeq8HluaYO68Igkj98PfJb+f3U8+iSuBBigoe5v9m/qu zwhlwHkrg1eZULOS9QMnAFoH4I3dPiDd9ixGB9laX/x1iAe+8b/bKhZ+fJAzS127 GN9ZPe/bGHLSmoaEn3ctEJrjSJH9+n4Ql0JhlcV2w+LXv289G8nBMl03Ja5VcaPI J671h1Qquuo/f/OK628FW+K3KWWOWnaQ+bOx9YHOX1TFR6O/QleqlGBisRGM1bpW Zgr4a+DNcWOuxiFt/P03ZgloJfQT5tXI/jhd1rmrMrG2+JUf49BJSQ/KC/a8GOvT dlDVNgsfRIW4K8aqZz2haX79GM4ji72zzC18Ehw==; 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-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 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