From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.150 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796096856; b=QKVsshooZlSEukeOBP4PyIGos+2eADs6J1q8vO+HLE1obyFlBaLh74fcx5SpffFWdpH2 Kouj4Oufcln4lUCMTq2c42dz4upt6zdcZEbLljCuL19mgwCvFI8Lrf9PFeu3P6TJEOjJn UAUTyOLckTWB8tFx1hwBfCRmnEmmrRn5SRytVRc9stSI2t5MVd80tDqKWrH7xrJUw0uhX 9XI4koYX+WVZ19OBPe5Pkubj8e7rqBFHbcZxUgVEHI4EAVR53TJRvNPjP9WxPWLiIxjoo LFhN9G8mQ5/E/YYfdldWUl5kd+gdOdwNGM8editNC4CTffUxYtOvgPM/yS+zCRFUVeA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796096856; 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=Fvmp2ScpTyKF/lU2XlG2XIsL5ah6sZiIaiAr8m5vFxE=; b=FcD1bxfkTwhUidsmihYvNX7Qd1poSAJ/kxfRssTFkMozed7Xo9yp/nVr170ke+qAF8Cq rv4M9DMGbLJFokXRy1XcELrwCSQGFO987lNO6n0rsBKsAxDcoT5MKK6Rab76b0KSnux74 JVtN4AjIGlDY7EWILIiqWzsjBOMnn19GjbZRNuKruavqQ2rCRFZMrQriq3XzhslpCuYMp AJSF9Ch13a4JZg7AjSQ5bl0GFoYIlwLvh4EwFHaT4PqgzEQ+tXx9sg1QYWagjZJr2Bf3m QyF+j/fr8qP1xkaqOhtEO0hi6yZvn/onl6/Ed4IG2cSGO0v8nySy6ffwYyC2U0XUrWg== 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=ElhTx4hP; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=hHhT9fWk; arc=none smtp.remote-ip=103.168.172.150 Received: from fout-a7-smtp.messagingengine.com (fout-a7-smtp.messagingengine.com [103.168.172.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 727E0606A33E for ; Tue, 1 Dec 2026 03:47:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 727E0606A33E 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=ElhTx4hP; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=hHhT9fWk Received: from phl-compute-11.internal (phl-compute-11.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id A15EBEC694E for ; Mon, 30 Nov 2026 22:47:35 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Mon, 30 Nov 2026 22:47:35 -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=1796096855; x=1796183255; bh=Fvmp2ScpTyKF/lU2XlG2X IsL5ah6sZiIaiAr8m5vFxE=; b=ElhTx4hP7jbtJWKdmwHxgYkwO/TfTU8cfc0Fo gmq2NC/vDjgUDqTDmEcxleGthFrajBiT+W9GsoG94sr4cJ5cAi+cMVfRkuo8az47 9l2Gpj0TMIxBPH73ccKzp5ld1N21vt91Jy17ZNSQsQjsddJW8DZzMCWujqGKyqqO JoWGu+PnTBjc6zwISEU2/qh1HoEHZqke15GugC54Llg7TOEwRl/ji4N8r6ODJAIH B6DBq3E7mQciyX6p5VBYNkIY4+jg1ziaDCi8JmG0SxZSaNsJlqu9knXZ3eG5iKn6 xN7c2EXA0w8JuLORcX7sDiuM+klaaouCOmqgLK2xIjLxzziaQ== 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= 1796096855; x=1796183255; bh=Fvmp2ScpTyKF/lU2XlG2XIsL5ah6sZiIaiA r8m5vFxE=; b=hHhT9fWkgD6UVjyjwLKXY8kZtvlNQMCmqPGQn27yhtSNNTvyhAU KHery/HMjh874g0dS70SLF6ddTmVR3QiLQQijreA1FuPFBvsYuSinjPkv/CA4E4t WqEzCBAxIV/+2qO9Ye0Y7G6bhNNR6s2EcUv6C2v0pUR6fpPEVh6o/ttxQCt9e1/m LkRxzBzm5lu0+K5Ee65a57LzNIyzUD2qYxUao0spc2KHRT4Yfu3H0q/EBROBAHGF DzChr/yi3jU81EwFa2Re/eqMy4RY1TutUck74f/lJO0yDkCkwabX5wKLbiJixsvd GmqFxgIzJZDastBnyqoo8fk/YRUr7FYMq+g== 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=1796096855; d=fastmail.org; mf=PGljYkBmYXN0bWFpbC5vcmc+; rt=PGxpbnV4LWNpZnNAdmdlci5rZXJuZWwub3JnPg==; s=fm3:rsa-sha256:HI0jG3LFP0k6EkNba10RPuDLd+SJTDtFB307ALN7oB7Dw+Q xYVgla+eOZxWVJu6hB9xlYfzf84uLHnTNOLdm2Mb4qhl/q20giw1aVUwbi7YA3ku NThjaMG+U8h0qXCU8q9pArCvyfkSRsXwvqtZS/Sr1CK9pnZQO/15KW6sLLd4OYK4 TrYn6XRuw+a97RHDIuq/iH0HiX6UUBhzlln6fvAjzrEFoqsLKojrZfrp1Ee/7U7W R896RMEPa8MJdiLCy4rIwBi2okVAqlJfqP2MCkxOk6g0pNgtVbgw3ArWNTJNXKzu ofGiY9Yje6qAnqeSVFoEQfJIXYbPh0j5lMxmIxA==; 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:ZGwOHfdCYhN30aj+IDDdR/4MbAj7heW9xZmHwkWlToE=:Vu9Bau0K+R+Hym27y2mcdxjGLlXkzFA3pacBtjrJrzY=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFl+vD2PlPsjAFeP+dYrWp1hta0T6TzxjsUdi4U790LhZYmVrmpKlG+NmzyinF9tf d/Av6xyePC536TncmxjCVb6D2/CMIWD+WwuZBq5VC4WFQGNuO7b0z4Tmf9Z+p+YwwzplC7 G5ARawrWvEKyGkblHXoZykaJ5KK+8fshhuf4xlyln2TyWnHrn374Rt5L/SS8xfB26j+CS9 Io+iCX5hm7Lh/gha9jkLVX4PgCRo+pa1PvQwyLoB3gF7qysZW9M+Dmk29T13qQ2FVkxT3W UAngcZ2O6gqKRqJ/MiQh1I3qmaSIXIgl7BAW2kwef6eRypAF59qNQoU0PDZ+VwiZb/QPYH w2gJj5p8smZsTNozFCUcaDJ6TyktfuxAJTOEKvbA1C7bBzQGuDy2qNHqMiIaiGxe4OtMMu b30UQbIbKw0YopDG4jD0DeQUFr/j9IiZ7O3YQnl5RwNeK39prf1CxgSP+6DshPyjKPYiJB pm7HW0qoGNK2AwGRlAbxwkyAer48635wNX7FX9TZ2Kdf+HKZjMYjPkiht9J0ahk1044nXW ZIQOkY5cP76UBaI7ijbn/6vD9aBKgdVPwl3K9bu1CRfPI91dp2vcZ/Jr5+VYiDygCwd9Js ibknVBz8Low0GVjZSQ+DW6vDtkMR/Uvv7pLGdvbzyKBvX+0U4udkFXXy8XTA X-ME-Proxy: Feedback-ID: ib53e4b78:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 30 Nov 2026 22:47:34 -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:47:20 -0600 Message-ID: <20261201034720.2178803-1-icb@fastmail.org> X-Mailer: git-send-email 2.47.3 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