Skip to contentSkip to conversation

ksmbd: Windows 11 SMB 3.1.1 interoperability fixes

PATCH Superseded Omkar Chandorkar 2 participants 5 messages Sep 19 – Sep 20

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ksmbd: Windows 11 SMB 3.1.1 interoperability fixes

This patch series resolves three separate protocol interoperability defects in ksmbd that affect Windows 11 clients:

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 compound CREATE and CHANGE_NOTIFY response handling Windows Explorer opens directories using compound requests chaining SMB2_CREATE with SMB2_CHANGE_NOTIFY under SMB2_FLAGS_RELATED_OPERATIONS. smb2_notify() checked for all-ones sentinel FileIds before resolving compound handles, misclassifying the request as a macOS Time Machine sentinel and dropping the preceding CREATE response buffer when setting send_no_response = 1. This left Explorer hanging for 60 seconds. Fix by resolving compound handles first and immediately dispatching the completed prefix CREATE response before deferring CHANGE_NOTIFY.

Patch 3: 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. Because FSCTL_PIPE_TRANSCEIVE was omitted from the no_fileid_ioctl check, smb2_ioctl() failed the file lookup with -ENOENT and returned STATUS_OBJECT_NAME_NOT_FOUND (0xc0000034), causing Windows to report RPC_S_CALL_FAILED (error 1726).
Fix by validating the RPC handle under rpc_lock and bypassing the regular file lookup for pipe shares.

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

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

 fs/smb/common/compress/compress.c |  17 +++-
 fs/smb/server/smb2pdu.c           | 150 +++++++++++++++++++++++++++++-
 2 files changed, 158 insertions(+), 9 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/3 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 | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
fs/smb/common/compress/compress.c +12 -5
index a4123c8f1..434743005 100644
@@ -130,12 +130,19 @@ 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.
+		 * The first payload header MUST specify SMB2_COMPRESSION_FLAG_CHAINED.
+		 * Subsequent payload headers in a conforming chain should carry
+		 * SMB2_COMPRESSION_FLAG_NONE, but clients (such as Windows) may omit
+		 * zeroing the flags field for trailing segments. Do not reject
+		 * valid payloads as long as they do not initiate an unhandled 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 2/3 ksmbd: fix compound CREATE and CHANGE_NOTIFY response handling

In reply to Omkar Chandorkar

When Windows 11 Explorer opens a directory on an SMB share, it emits a compounded request chaining SMB2_CREATE with SMB2_CHANGE_NOTIFY under SMB2_FLAGS_RELATED_OPERATIONS. The secondary CHANGE_NOTIFY command sets VolatileFileId to SMB2_NO_FID (0xFFFFFFFFFFFFFFFF), expecting the server to inherit the handle opened by the preceding CREATE command.

smb2_notify() currently checks:

    if (req->VolatileFileId == SMB2_NO_FID &&
        req->PersistentFileId == SMB2_NO_FID)

before resolving compound handles. Consequently, it misidentifies Windows Explorer's compound directory open as a standalone macOS Time Machine share-root sentinel.

Additionally, smb2_send_interim_resp() lacked compound prefix response dispatching. When smb2_notify() transitions to an asynchronous state and sets work->send_no_response = 1, the server drops the entire compound response without transmitting the completed CREATE response to the client. Windows Explorer is left blocked waiting for the directory open reply until the 60-second SMB timeout expires.

Fix this by:
1. Resolving work->compound_fid and work->compound_pfid in smb2_notify() when SMB2_FLAGS_RELATED_OPERATIONS is set.
2. Restricting the macOS share-root sentinel check to standalone requests.
3. Backporting smb2_send_interim_compound_prefix() from mainline to immediately transmit the completed compound prefix responses (including the CREATE response) before dispatching the asynchronous interim response for CHANGE_NOTIFY.

Assisted-by OpenCode:gpt-6-astra
---
 fs/smb/server/smb2pdu.c | 128 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 124 insertions(+), 4 deletions(-)
fs/smb/server/smb2pdu.c +124 -4
index 4cf7083f3..619ef0e11 100644
@@ -1095,6 +1095,107 @@ void release_async_work(struct ksmbd_work *work)
 	}
 }
 
+static int smb2_send_interim_work(struct ksmbd_work *in_work,
+				  struct ksmbd_work *work, bool eor)
+{
+	int err = 0;
+
+	in_work->encrypted = work->encrypted;
+	if (work->encrypted && work->sess && work->sess->enc &&
+	    work->conn->ops->encrypt_resp) {
+		in_work->sess = work->sess;
+		err = work->conn->ops->encrypt_resp(in_work);
+		in_work->sess = NULL;
+	}
+	if (err)
+		return err;
+
+	return ksmbd_conn_write(in_work);
+}
+
+static int smb2_send_interim_prefix_work(struct ksmbd_work *work)
+{
+	struct ksmbd_work *in_work;
+	unsigned int len, copied = 0;
+	char *dst;
+	int err = -ENOMEM;
+	int i;
+
+	len = get_rfc1002_len(work->iov[0].iov_base);
+	in_work = ksmbd_alloc_work_struct();
+	if (!in_work)
+		return err;
+
+	in_work->response_buf = kvzalloc(len + 4, KSMBD_DEFAULT_GFP);
+	if (!in_work->response_buf)
+		goto out;
+	in_work->response_sz = len + 4;
+	in_work->conn = work->conn;
+	dst = in_work->response_buf + 4;
+	for (i = 1; i <= work->iov_idx; i++) {
+		if (work->iov[i].iov_len > len - copied) {
+			err = -EINVAL;
+			goto out;
+		}
+		memcpy(dst + copied, work->iov[i].iov_base,
+		       work->iov[i].iov_len);
+		copied += work->iov[i].iov_len;
+	}
+	if (copied != len) {
+		err = -EINVAL;
+		goto out;
+	}
+
+	err = ksmbd_iov_pin_rsp(in_work, dst, len);
+	if (!err)
+		err = smb2_send_interim_work(in_work, work, true);
+out:
+	ksmbd_free_work_struct(in_work);
+	return err;
+}
+
+static void smb2_send_interim_compound_prefix(struct ksmbd_work *work)
+{
+	struct smb2_hdr *req_hdr;
+	struct smb2_hdr *rsp_hdr;
+	int err;
+
+	if (!work->next_smb2_rcv_hdr_off ||
+	    !work->next_smb2_rsp_hdr_off ||
+	    work->curr_smb2_rsp_hdr_off == work->next_smb2_rsp_hdr_off ||
+	    !work->iov_idx)
+		return;
+
+	req_hdr = ksmbd_req_buf_next(work);
+	/* Detach only the final async command from the completed prefix. */
+	if (req_hdr->NextCommand)
+		return;
+
+	/*
+	 * The responses before the async command are sent as a standalone
+	 * compound response. The last response in this prefix must terminate
+	 * the chain.
+	 */
+	rsp_hdr = ksmbd_resp_buf_curr(work);
+	rsp_hdr->NextCommand = 0;
+	if ((rsp_hdr->Flags & SMB2_FLAGS_SIGNED) && work->sess &&
+	    work->conn->ops->set_sign_rsp)
+		work->conn->ops->set_sign_rsp(work);
+
+	err = smb2_send_interim_prefix_work(work);
+	if (err)
+		ksmbd_debug(SMB, "failed to send compound interim prefix: %d\n",
+			    err);
+
+	work->iov_idx = 0;
+	work->iov_cnt = 0;
+	work->curr_smb2_rsp_hdr_off = work->next_smb2_rsp_hdr_off;
+	*(__be32 *)work->response_buf = 0;
+
+	rsp_hdr = ksmbd_resp_buf_next(work);
+	rsp_hdr->Flags &= ~SMB2_FLAGS_RELATED_OPERATIONS;
+}
+
 void smb2_send_interim_resp(struct ksmbd_work *work, __le32 status)
 {
 	struct smb2_hdr *rsp_hdr;
@@ -1109,6 +1210,9 @@ void smb2_send_interim_resp(struct ksmbd_work *work, __le32 status)
 		return;
 	}
 
+	if (status == STATUS_PENDING)
+		smb2_send_interim_compound_prefix(work);
+
 	in_work->conn = work->conn;
 	memcpy(smb_get_msg(in_work->response_buf), ksmbd_resp_buf_next(work),
 	       __SMB2_HEADER_STRUCTURE_SIZE);
@@ -1119,7 +1223,8 @@ void smb2_send_interim_resp(struct ksmbd_work *work, __le32 status)
 	smb2_set_err_rsp(in_work);
 	rsp_hdr->Status = status;
 
-	ksmbd_conn_write(in_work);
+	if (smb2_send_interim_work(in_work, work, true))
+		ksmbd_debug(SMB, "failed to send interim response\n");
 	ksmbd_free_work_struct(in_work);
 }
 
@@ -10405,6 +10510,7 @@ int smb2_notify(struct ksmbd_work *work)
 	struct ksmbd_work *in_work;
 	struct smb2_hdr *in_hdr;
 	struct ksmbd_file *fp;
+	u64 id, pid;
 
 	ksmbd_debug(SMB, "Received smb2 notify\n");
 
@@ -10419,14 +10525,28 @@ int smb2_notify(struct ksmbd_work *work)
 		return -EIO;
 	}
 
+	id = req->VolatileFileId;
+	pid = req->PersistentFileId;
+	if (work->next_smb2_rcv_hdr_off &&
+	    (req->hdr.Flags & SMB2_FLAGS_RELATED_OPERATIONS)) {
+		if (!has_file_id(work->compound_fid)) {
+			rsp->hdr.Status = STATUS_INVALID_HANDLE;
+			smb2_set_err_rsp(work);
+			return 0;
+		}
+		id = work->compound_fid;
+		pid = work->compound_pfid;
+	}
+
 	/*
 	 * macOS backupd sends CHANGE_NOTIFY with FileId=FFFF...FFFF (share-root
 	 * sentinel) to watch for changes on the share root without holding an
 	 * open handle. Respond STATUS_PENDING + STATUS_NOTIFY_CLEANUP immediately;
 	 * without this, backupd aborts Time Machine setup on STATUS_FILE_CLOSED.
 	 */
-	if (req->VolatileFileId == SMB2_NO_FID &&
-	    req->PersistentFileId == SMB2_NO_FID) {
+	if (!work->next_smb2_rcv_hdr_off && !req->hdr.NextCommand &&
+	    !(req->hdr.Flags & SMB2_FLAGS_RELATED_OPERATIONS) &&
+	    id == SMB2_NO_FID && pid == SMB2_NO_FID) {
 		in_work = ksmbd_alloc_work_struct();
 		if (!in_work || allocate_interim_rsp_buf(in_work)) {
 			if (in_work)
@@ -10470,7 +10590,7 @@ int smb2_notify(struct ksmbd_work *work)
 	 * STATUS_NOT_IMPLEMENTED here (like stock ksmbd) makes macOS smbfs
 	 * hard-freeze on unmount, so this must stay deferred.
 	 */
-	fp = ksmbd_lookup_fd_slow(work, req->VolatileFileId, req->PersistentFileId);
+	fp = ksmbd_lookup_fd_slow(work, id, pid);
 	if (!fp) {
 		rsp->hdr.Status = STATUS_FILE_CLOSED;
 		smb2_set_err_rsp(work);
Signature · 1 line
2.55.0
#3 lore raw

PATCH 3/3 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 the response file IDs before dispatching the transceive request.

Assisted-by OpenCode:gpt-6-astra
---
 fs/smb/server/smb2pdu.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
fs/smb/server/smb2pdu.c +22 -0
index 619ef0e11..76f98ab4f 100644
@@ -9662,6 +9662,26 @@ int smb2_ioctl(struct ksmbd_work *work)
 	case FSCTL_PIPE_WAIT:
 		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;
 	}
@@ -9790,6 +9810,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
#4 lore raw
In reply to Omkar Chandorkar
Quoted 41 lines · Omkar Chandorkar

This patch series resolves three separate protocol interoperability defects in ksmbd that affect Windows 11 clients:

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 compound CREATE and CHANGE_NOTIFY response handling Windows Explorer opens directories using compound requests chaining SMB2_CREATE with SMB2_CHANGE_NOTIFY under SMB2_FLAGS_RELATED_OPERATIONS. smb2_notify() checked for all-ones sentinel FileIds before resolving compound handles, misclassifying the request as a macOS Time Machine sentinel and dropping the preceding CREATE response buffer when setting send_no_response = 1. This left Explorer hanging for 60 seconds. Fix by resolving compound handles first and immediately dispatching the completed prefix CREATE response before deferring CHANGE_NOTIFY.

Patch 3: 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. Because FSCTL_PIPE_TRANSCEIVE was omitted from the no_fileid_ioctl check, smb2_ioctl() failed the file lookup with -ENOENT and returned STATUS_OBJECT_NAME_NOT_FOUND (0xc0000034), causing Windows to report RPC_S_CALL_FAILED (error 1726).
Fix by validating the RPC handle under rpc_lock and bypassing the regular file lookup for pipe shares.

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

Quoted 4 lines

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

Could you please prepare and send this as a patch series based on the latest #ksmbd-for-next ?
Thanks!