Skip to contentSkip to conversation

ksmbd: Windows 11 SMB 3.1.1 interoperability fixes

PATCH Applied Omkar Chandorkar 2 participants 4 messages Sep 20 – Sep 22

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover ksmbd: Windows 11 SMB 3.1.1 interoperability fixes

This patch series resolves SMB 3.1.1 protocol interoperability defects in ksmbd affecting Windows 11 clients, rebased on top of the latest ksmbd-for-next tree.

Patch 1: smb: compress: relax trailing flags in chained decompression Windows 11 leaves residual uninitialized bits in trailing compression chunk headers during chained writes (e.g. copying .vhdx files). smb_decompress_chained() previously rejected any trailing header whose flags did not equal 0x0000, causing connection drops (ECONNRESET) and Windows error 0x8007003B. Relax this check to accept non-chained trailing payloads while preserving validation on segment lengths and bounds.

Patch 2: ksmbd: fix FSCTL_PIPE_TRANSCEIVE file lookup and response handling When querying the share list (e.g. browsing \\server or running 'net view \\server'), Windows 11 issues NetrShareEnum over \PIPE\srvsvc using SMB2_IOCTL with FSCTL_PIPE_TRANSCEIVE. Named pipe handles exist in sess->rpc_handle_list rather than the regular file table. While commit a3bcea7c819a ("ksmbd: exempt FSCTL_PIPE_TRANSCEIVE from the generic file-id lookup") exempted FSCTL_PIPE_TRANSCEIVE from the generic file ID lookup, the response PersistentFileId and VolatileFileId were left unpopulated (violating MS-SMB2 section 2.2.32), and invalid RPC handles were not rejected under rpc_lock.
Fix this by validating the RPC handle under rpc_lock and populating the resolved response file IDs before dispatching the transceive request.

Changes in v2:
- Rebased series onto git.kernel.org linkinjeon/smb.git #ksmbd-for-next at commit 4bb07a7d5852 ("smb/server: rename smb2_file_alt_name_info to smb2_file_name_info").
- Dropped the compound CREATE + CHANGE_NOTIFY response handling patch from v1 because upstream already merged compound prefix response dispatching in commit 906a62216339 ("smb/server: send compound prefix before async pending response") and compound FID resolution in commit 524efc568ea5 ("smb/server: support compound fid in notify requests").
- Refined the FSCTL_PIPE_TRANSCEIVE patch to populate response FileId fields per MS-SMB2 section 2.2.32 and validate RPC pipe handles under rpc_lock.

Tooling and AI disclosure:
AI tooling (OpenCode:gpt-6-astra) was utilized to assist in protocol trace analysis, specification cross-referencing ([MS-SMB2], [MS-SRVS]), and drafting. All changes were manually audited, static-checked, compiled, and verified against live Windows 11 clients.

Omkar Chandorkar (2):
smb: compress: relax trailing flags in chained decompression
ksmbd: fix FSCTL_PIPE_TRANSCEIVE file lookup and response handling

 fs/smb/common/compress/compress.c | 16 +++++++++++-----
 fs/smb/server/smb2pdu.c           | 23 ++++++++++++++++++++++-
 2 files changed, 33 insertions(+), 6 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH v2 1/2 smb: compress: relax trailing flags in chained decompression

In SMB 3.1.1, clients such as Windows 11 send chained compressed write requests containing multiple payload segments (for example, None + Pattern_V1) when transferring zero-heavy or compressible files.

According to MS-SMB2 section 2.2.42.2.1, the first payload header in a chained compression transform MUST have SMB2_COMPRESSION_FLAG_CHAINED (0x0001) set. Trailing payload headers in the chain correspond to subsequent payloads, where the specification defines SMB2_COMPRESSION_FLAG_NONE (0x0000).

However, Windows clients do not always explicitly zero the 16-bit Flags field on subsequent payload headers during chunk construction (as described in MS-SMB2 section 3.1.4.4 step 2), leaving residual bits in the Flags field.

smb_decompress_chained() currently enforces:

    (!first && flags != cpu_to_le16(SMB2_COMPRESSION_FLAG_NONE))

returning -EINVAL if any trailing payload has non-zero flags. When this occurs during large file writes (such as copying VHDX files), ksmbd breaks the connection receive loop and abruptly terminates the TCP connection with ECONNRESET (-104), causing Windows clients to fail with error 0x8007003B (ERROR_UNEXP_NET_ERR).

Fix this by relaxing the flags requirement on trailing payloads in smb_decompress_chained(). Conforming chains still strictly require SMB2_COMPRESSION_FLAG_CHAINED on the first payload header, but for subsequent payloads, only reject headers that attempt to initiate an invalid nested chain (SMB2_COMPRESSION_FLAG_CHAINED). All payload lengths, decompression algorithms, and total uncompressed output sizes continue to be strictly validated against the transform's OriginalCompressedSegmentSize.

Assisted-by OpenCode:gpt-6-astra
---
 fs/smb/common/compress/compress.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
fs/smb/common/compress/compress.c +11 -5
index a4123c8f1c0a..4e5164b6dc33 100644
@@ -130,12 +130,18 @@ static int smb_decompress_chained(__le16 alg, bool allow_chained,
 		len = le32_to_cpu(payload->Length);
 
 		/*
-		 * CHAINED marks only the first payload. Requiring NONE on every
-		 * later payload rejects ambiguous or independently chained data.
+		 * Conforming chains must set CHAINED on the first payload.
+		 * Windows 11 clients leave uninitialized residual bits in
+		 * Flags on subsequent payload headers. Only reject trailing
+		 * payloads that attempt to initiate an invalid nested chain.
 		 */
-		if ((first && flags != cpu_to_le16(SMB2_COMPRESSION_FLAG_CHAINED)) ||
-		    (!first && flags != cpu_to_le16(SMB2_COMPRESSION_FLAG_NONE)))
-			return -EINVAL;
+		if (first) {
+			if (flags != cpu_to_le16(SMB2_COMPRESSION_FLAG_CHAINED))
+				return -EINVAL;
+		} else {
+			if (flags == cpu_to_le16(SMB2_COMPRESSION_FLAG_CHAINED))
+				return -EINVAL;
+		}
 
 		src += SMB2_COMPRESSION_PAYLOAD_BASE_LEN;
 		remaining -= SMB2_COMPRESSION_PAYLOAD_BASE_LEN;
Signature · 1 line
2.55.0
#2 lore raw

PATCH v2 2/2 ksmbd: fix FSCTL_PIPE_TRANSCEIVE file lookup and response handling

In reply to Omkar Chandorkar

Named pipe handles are tracked in sess->rpc_handle_list rather than sess->file_table.idr. The generic IOCTL file lookup therefore returns -ENOENT and STATUS_OBJECT_NAME_NOT_FOUND for valid Windows 11 FSCTL_PIPE_TRANSCEIVE requests.

Validate the RPC handle under rpc_lock and bypass the regular file lookup only when the handle exists. Return STATUS_FILE_CLOSED for invalid handles. Populate response file IDs before dispatching the transceive request.

Assisted-by OpenCode:gpt-6-astra
---
 fs/smb/server/smb2pdu.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +22 -1
index 15e2801a8ce1..7accc4af44e1 100644
@@ -10922,9 +10922,28 @@ int smb2_ioctl(struct ksmbd_work *work)
 	case FSCTL_QUERY_NETWORK_INTERFACE_INFO:
 	case FSCTL_VALIDATE_NEGOTIATE_INFO:
 	case FSCTL_PIPE_WAIT:
-	case FSCTL_PIPE_TRANSCEIVE:
 		no_fileid_ioctl = true;
 		break;
+	case FSCTL_PIPE_TRANSCEIVE:
+		if (!test_share_config_flag(work->tcon->share_conf,
+					    KSMBD_SHARE_FLAG_PIPE)) {
+			ret = -EOPNOTSUPP;
+			goto out;
+		}
+
+		/* RPC pipe handles are not in the regular file table. */
+		if (has_file_id(id) && !pid) {
+			down_read(&work->sess->rpc_lock);
+			no_fileid_ioctl =
+				ksmbd_session_rpc_method(work->sess, id) != 0;
+			up_read(&work->sess->rpc_lock);
+		}
+		if (!no_fileid_ioctl) {
+			ret = -EBADF;
+			rsp->hdr.Status = STATUS_FILE_CLOSED;
+			goto out2;
+		}
+		break;
 	default:
 		break;
 	}
@@ -11083,6 +11102,8 @@ int smb2_ioctl(struct ksmbd_work *work)
 		break;
 	}
 	case FSCTL_PIPE_TRANSCEIVE:
+		rsp->PersistentFileId = pid;
+		rsp->VolatileFileId = id;
 		out_buf_len = min_t(u32, KSMBD_IPC_MAX_PAYLOAD, out_buf_len);
 		nbytes = fsctl_pipe_transceive(work, id, out_buf_len, req, rsp);
 		break;
Signature · 1 line
2.55.0
maintainer Applied
#3 lore raw
In reply to Omkar Chandorkar
Quoted 45 lines · Omkar Chandorkar

This patch series resolves SMB 3.1.1 protocol interoperability defects in ksmbd affecting Windows 11 clients, rebased on top of the latest ksmbd-for-next tree.

Patch 1: smb: compress: relax trailing flags in chained decompression Windows 11 leaves residual uninitialized bits in trailing compression chunk headers during chained writes (e.g. copying .vhdx files). smb_decompress_chained() previously rejected any trailing header whose flags did not equal 0x0000, causing connection drops (ECONNRESET) and Windows error 0x8007003B. Relax this check to accept non-chained trailing payloads while preserving validation on segment lengths and bounds.

Patch 2: ksmbd: fix FSCTL_PIPE_TRANSCEIVE file lookup and response handling When querying the share list (e.g. browsing \\server or running 'net view \\server'), Windows 11 issues NetrShareEnum over \PIPE\srvsvc using SMB2_IOCTL with FSCTL_PIPE_TRANSCEIVE. Named pipe handles exist in sess->rpc_handle_list rather than the regular file table. While commit a3bcea7c819a ("ksmbd: exempt FSCTL_PIPE_TRANSCEIVE from the generic file-id lookup") exempted FSCTL_PIPE_TRANSCEIVE from the generic file ID lookup, the response PersistentFileId and VolatileFileId were left unpopulated (violating MS-SMB2 section 2.2.32), and invalid RPC handles were not rejected under rpc_lock.
Fix this by validating the RPC handle under rpc_lock and populating the resolved response file IDs before dispatching the transceive request.

Changes in v2:
- Rebased series onto git.kernel.org linkinjeon/smb.git #ksmbd-for-next at commit 4bb07a7d5852 ("smb/server: rename smb2_file_alt_name_info to smb2_file_name_info").
- Dropped the compound CREATE + CHANGE_NOTIFY response handling patch from v1 because upstream already merged compound prefix response dispatching in commit 906a62216339 ("smb/server: send compound prefix before async pending response") and compound FID resolution in commit 524efc568ea5 ("smb/server: support compound fid in notify requests").
- Refined the FSCTL_PIPE_TRANSCEIVE patch to populate response FileId fields per MS-SMB2 section 2.2.32 and validate RPC pipe handles under rpc_lock.

Tooling and AI disclosure:
AI tooling (OpenCode:gpt-6-astra) was utilized to assist in protocol trace analysis, specification cross-referencing ([MS-SMB2], [MS-SRVS]), and drafting. All changes were manually audited, static-checked, compiled, and verified against live Windows 11 clients.

Quoted 3 lines

Omkar Chandorkar (2):
smb: compress: relax trailing flags in chained decompression
ksmbd: fix FSCTL_PIPE_TRANSCEIVE file lookup and response handling

Applied them to #ksmbd-for-next.
Thanks!