From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796130863; b=MmTscJ5xeqVwjH4wN9q5j7PLMzYx2udd6jm9LwG1C66c82m+U3IKKiReu+vm3Xi6lFmf 0eUvoRl74IDdniRGk5s4wQGHSGbX+9T2zCT8akKH9UGJNPS6jLC8IFChrCWb3bDtQMDLz RUUHT1ocE4ZN7BYj1JZ34LLSxAPVXSyDcrot0qtaHtoZCrDAy/1LQfGhnU8c0ofkFH4UT f2IcQu0kw+HsaDMl19+jEORgMUwuNqZ40sHgwNlsJprS/gBzum9aVEhu/crU4FpActY2I QhTr6OdrxQcvFyHvvNntF1GyA6dIyDi49Gl+PKWg4SvKyHpNxBkNjh8OItIQ5ZIPR2Q== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796130863; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=0oW6F0e1flNpon3v4IKhE/ScG3dz00IaOe4/cEHsNSI=; b=1B7hqxNb5SqpVxx+hy3tXEryhCj/+QGm7M2STx+8dJMTB5uSSg5hv2QFsZnvuakS5nem QTgTlIVQPutlvFb//UeLvSym+OVn4mIvZg5dW9XzOxaqFMqR4ZUbHTJr/deFaV7yCjzkM KW+dfJy+25AWTifnYwncAC6pjy72o1pvNc4rxggcbkHhK9qOS1M1dCiay+pU9KyPGtg+3 oAxvlXqBCQ+XLZpU1iX7m4v4F16Hbjcsq/WvPZqEnvZTVBDD99GNLoRDtzEfORiDr3uBD phDLtUEPo+HaYmhKUHyar584qJn8PRNQEiE4mTAx7W68D/o7uzdCQWzIBY1UHPOE0wQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jR3jmC3j; arc=pass header.oldest-pass=0 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 636CF606A31A; Tue, 1 Dec 2026 13:14:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jR3jmC3j Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796130863; b=dhkHT6Ze4LsZLPF9695d0BlD8JD8xIM1lZqqpDvS/YEQFj9kPRzyEga9SGUt3tN+RITX Q22MOsBUMKU+G9xkAFuuWq8e4jNn9cZtR+BUVgB0f7VdogYxe6d8iqb5huuzvyfyUsS3n gg6LNn/ETJoGGI6nr40cQEuFEx2/86kyvt7PV6Bdow1b7swelrrRuouqE9Qf1lodEc8l2 XGw89pFdZwL0YJvvDp8/9lpNlvpsHx8XziWyMTi7CP8wAAKd6IPluEyS+SvjkXou29sa5 jfiZUHcP0I8P7e67taBqcFk2QJwUlGgxhid15+YKgZ1ea73pPzWdPBy5xlD3cb2t0bA== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796130863; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=0oW6F0e1flNpon3v4IKhE/ScG3dz00IaOe4/cEHsNSI=; b=gEwg/hGO+/hQLa1PcoYf9q8djjobrItNvyKO2JlgVhVuW0TjwfcELJe2WoaO+wDT41YK Ju7boLS0j8xwjuzyNEV07k1cZTBv4BjrrN/yi+NWCjvMs46Y3U4MnDI2ksfr9XJd39on3 AKVoP++Ij+aCXCWewthblKDDfBVAqw8ktAnjgvoJST1fktH5dsHvJBdwrNSJjbvkGYxFv skuOrABK36d4kdacbIdmOP3+64rskkZT1fTTvzazfrrrYsTH+9C9UG6MLBXNRS1c4HX3W UsVEYq0bMkW7itXl5eCQ6MCQ0f2VqlR7yAhc+l+2o/Gkc2byieTnELU7Ii4HipBkwAw== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (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.kernel.org (Postfix) with ESMTPS id 08E0E1F00893; Tue, 1 Dec 2026 13:14:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796130863; bh=0oW6F0e1flNpon3v4IKhE/ScG3dz00IaOe4/cEHsNSI=; h=From:Date:Subject:To:Cc:Reply-To; b=jR3jmC3jcdMT8DZYMMQTHL6PJ4gKtb8AGoNlF3ingnKLnfyc9WrociygMaVr9vxx0 qr/O70zIWu0UgxbL+ER/BEzpzaxfRXLf49FNoKfipxCHLQ3ycOUrrlau4b12jnU+fD 3umxgBBMJvqU6f0vek15rghBFXvao2hRh3Yb5dSX1GjADKriBG3xyEkwAoyXxhpnJw uxFE9oPhW8CXjyUPkIU4NVVwjK7Ka7/5hMRHIFkRKDZD22FYLcHu3iSTILNb5DUzjc tc8TTkb1QpVnzuodI8YbgFxXKBnqLXjWT48uYkE9gt0DIrkbn3q0BL+lIC5ULRt20c j1ijtxiANF65Q== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 5C51E4EDC5; Tue, 1 Dec 2026 13:14:20 +0000 (UTC) From: Andreas Claesson via B4 Relay Date: Tue, 01 Dec 2026 13:14:19 +0000 Subject: [PATCH] ksmbd: refuse to write to a handle that is not open for writing 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-Type: text/plain; charset="utf-8" Message-Id: <20261201-ksmbd-write-fmode-v1-1-2848c4e5b36b@aclaesson.com> X-B4-Tracking: v=1; b=H4sIACvIDmsC/yXMPQ6DMAxA4asgz7WUZKCEq6AOhJhiUAKK+ZMQd 2/ajt/w3gVCiUmgLi5ItLPwHDP0o4BuaOObkH02GGVKbZTGSYLzeCReCfswe8KqavXTWeWtsZC 7JVHP5+/ZvP6WzY3Urd8R3PcHOxybMnUAAAA= X-Change-ID: 20261201-ksmbd-write-fmode-88a17b90d929 To: Namjae Jeon Cc: Sergey Senozhatsky , Tom Talpey , ChenXiaoSong , linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796130859; l=2835; i=andreas@aclaesson.com; s=20261109; h=from:subject:message-id; bh=vcAlWtzrEiL36yYSNM8HQbZOblWoIQTgeCTZkMrYlxg=; b=PBcVRCX+D4xbl7xQe0LVa1TGo+NX9xGKkVlO+p6T8H4Pck0QuyPUGsX30ABZ3F1PnyV3umJzq ee9uljGBzGICFYytA419E4XczrgtiSFgZiGsTA25tQDB4mlCkACc+aS X-Developer-Key: i=andreas@aclaesson.com; a=ed25519; pk=oC+38UX0rqcrEjNMgnKAF1zmrTUMbQ2aH/P5Z4TZOIQ= X-Endpoint-Received: by B4 Relay for andreas@aclaesson.com/20261109 with auth_id=1465 X-Original-From: Andreas Claesson Reply-To: andreas@aclaesson.com Content-Transfer-Encoding: 7bit From: Andreas Claesson smb2_create_open_flags() opens block and character device nodes with O_PATH, whatever access the client asks for, but the open still grants the requested access. A client that opens a device node in a share with FILE_WRITE_DATA and then sends a WRITE passes the access check in ksmbd_vfs_write(), and kernel_write() is called on a file without FMODE_WRITE: WARNING: fs/read_write.c:608 at __kernel_write_iter+0x7ad/0x9a0 Workqueue: ksmbd-io handle_ksmbd_work Call Trace: kernel_write+0x1f4/0x680 ksmbd_vfs_write+0x30c/0xcc0 smb2_write+0x1000/0x2050 handle_ksmbd_work+0xff6/0x2a30 __kernel_write_iter() returns -EBADF after the warning, so nothing is written, but any client with write access to a share that contains a device node can trigger the warning. Check the file mode before the write and return -EACCES, as ksmbd_vfs_read() does since commit 2fd145f8865b ("ksmbd: refuse to read a handle that is not open for reading"). Fixes: 8e2f6a0e2dc9 ("ksmbd: fix open failure from block and char device file") Assisted-by: Claude:claude-mythos-5-2 Signed-off-by: Andreas Claesson --- Found with syzkaller, using local descriptions for ksmbd. Tested on ksmbd-for-next (87ff512becd4) in QEMU with KASAN. The reproducer opens a character device node in a share with FILE_WRITE_DATA and sends a WRITE; a second one does the same with a block device node. Without the patch both give the warning above and the WRITE fails with STATUS_INVALID_HANDLE. With the patch there is no warning and the WRITE fails with STATUS_ACCESS_DENIED. A WRITE to a FIFO, which is not opened with O_PATH, succeeds as before. I also sent FSCTL_SET_ZERO_DATA, FSCTL_SET_SPARSE, FSCTL_COPYCHUNK_WRITE and FLUSH on a device node handle. None of them reaches kernel_write() and none gives a warning, with or without the patch, so WRITE is the only path I found. I did not add a stable tag. The warning is the only effect, as nothing is written. Please add one if you think it is worth it. --- fs/smb/server/vfs.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c index 35d449ee3dae3..7340691609f9e 100644 --- a/fs/smb/server/vfs.c +++ b/fs/smb/server/vfs.c @@ -564,6 +564,12 @@ int ksmbd_vfs_write(struct ksmbd_work *work, struct ksmbd_file *fp, goto out; } + /* A device node is opened with O_PATH, whatever access was granted */ + if (!(filp->f_mode & FMODE_WRITE)) { + err = -EACCES; + goto out; + } + if (!fp->is_posix_ctxt) { err = check_lock_range(filp, *pos, *pos + count - 1, WRITE); if (err) { --- base-commit: 87ff512becd45a08c44fd47a9f03e607af9ef6bd change-id: 20261201-ksmbd-write-fmode-88a17b90d929 Best regards, -- Andreas Claesson