Skip to contentSkip to conversation

ksmbd: reject unsigned non-exempt requests when session requires signing

PATCH New Michael Bommarito 1 participant 1 message May 20

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

PATCH 1/1 ksmbd: reject unsigned non-exempt requests when session requires signing

This is the ksmbd SMB2 sibling of Samba CVE-2023-3347 ("SMB2 packet signing not enforced"): when the server-side policy requires SMB2 signing, unsigned non-exempt requests must be rejected instead of processed. CVE-2016-2114 is the older Samba SMB1 analogue for mandatory server signing not being enforced.

When a ksmbd target is configured with "server signing = mandatory" and a client completes a signed SESSION_SETUP, an attacker on the network path of that connection can read the cleartext SessionId from the SMB2 header and inject unsigned TREE_CONNECT, CREATE, and WRITE requests on the victim's TCP flow. ksmbd processes the unsigned PDUs and commits attacker-supplied content to the share under the victim session's authority, without the attacker holding the victim's credentials.

In fs/smb/server/server.c, __process_request() verifies signatures only when conn->ops->is_sign_req() returns true. The predicate (smb2_is_sign_req() at fs/smb/server/smb2pdu.c:8936-8947) reads only the client-set SMB2_FLAGS_SIGNED and never work->sess->sign -- the per-session "signing required" state set during SESSION_SETUP at smb2pdu.c:1546 and :1645. MS-SMB2 3.3.5.2.4 requires the server to reject any unsigned non-exempt request when Session.SigningRequired is TRUE.

Reject directly in __process_request() when work->sess->sign is set and the inbound non-exempt request lacks SMB2_FLAGS_SIGNED, bypassing check_sign_req() to avoid emitting pr_err("bad smb2 signature") at KERN_ERR for each unsigned PDU. The set of commands exempt from signing (NEGOTIATE, SESSION_SETUP, OPLOCK_BREAK) is unchanged.

Fixes e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Assisted-by Claude:claude-opus-4-7

---

Reproduction
============

Tree: linux-mainline 2f448dd9ef4e, x86_64 QEMU+KVM, CONFIG_SMB_SERVER=y, CONFIG_KASAN=y. Target ksmbd.conf has "server signing = mandatory", "map to guest = Never", "valid users = alice"; SMB user alice was added via ksmbd.adduser.

Conditions: ksmbd configured with "server signing = mandatory" or a client requesting SMB2_NEGOTIATE_SIGNING_REQUIRED, so work->sess->sign is set to TRUE after SESSION_SETUP completes. Encryption MUST NOT be negotiated on the session (smb2_sess_setup clears sess->sign to FALSE at smb2pdu.c:1558/:1657 when smb3_encryption_negotiated() is TRUE). The PoCs force SMB 2.1 to keep the session in the signing-required state.

Harness: a wire-level Python client establishes a normal NTLMv2 SESSION_SETUP on a fresh TCP connection, then on the same connection issues TREE_CONNECT, CREATE, and WRITE with SMB2_FLAGS_SIGNED cleared and the Signature field zeroed. A companion transparent TCP MITM proxy demonstrates the same primitive without holding credentials: it observes SessionId from the cleartext SESSION_SETUP response and injects an unsigned TREE_CONNECT, CREATE, and WRITE into the victim's TCP flow using that SessionId; the victim's own SMB session continues normally and observes the attacker's file appear on the share.

Stock kernel: unsigned TREE_CONNECT returns STATUS_SUCCESS with a tree_id; CREATE returns STATUS_SUCCESS with a file id; WRITE returns STATUS_SUCCESS and the attacker payload lands on the share path. The response header carries SMB2_FLAGS_SIGNED with a non-zero MAC, confirming work->sess->sign was TRUE on this session.

Patched kernel: same harness, the dispatcher returns STATUS_ACCESS_DENIED on the first unsigned TREE_CONNECT and nothing reaches the share. dmesg shows zero
"bad smb2 signature" entries; the rejection bypasses check_sign_req() so the existing pr_err path is not exercised.
Regression: a legitimate smbclient session with --client-protection=sign continues to read and write to the share with no observable change.

Mitigations: until patched, deployments can leave "server signing = mandatory" disabled in ksmbd.conf (the bypass is meaningful only when the session sets work->sess->sign), or configure clients to negotiate SMB3 encryption (sess->enc=TRUE clears sess->sign and the session uses TRANSFORM_HEADER encryption for the data path).

Selftests: grep over tools/testing/selftests/ on the patched tree returns 0 references to ksmbd or smb2_is_sign_req; there is no in-tree selftest binary that exercises fs/smb/server/server.c's dispatch gate. The trigger Python client and the TCP MITM proxy are available off-list on request.

---
 fs/smb/server/server.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/smb/server/server.c +9 -0
index 58ef02c423fce..5755f907f29f4 100644
@@ -143,6 +143,15 @@ static int __process_request(struct ksmbd_work *work, struct ksmbd_conn *conn,
 			conn->ops->set_rsp_status(work, STATUS_ACCESS_DENIED);
 			return SERVER_HANDLER_ABORT;
 		}
+	} else if (work->sess && work->sess->sign &&
+		   command != SMB2_NEGOTIATE_HE &&
+		   command != SMB2_SESSION_SETUP_HE &&
+		   command != SMB2_OPLOCK_BREAK_HE) {
+		/* MS-SMB2 3.3.5.2.4: Session.SigningRequired==TRUE,
+		 * reject unsigned non-exempt request.
+		 */
+		conn->ops->set_rsp_status(work, STATUS_ACCESS_DENIED);
+		return SERVER_HANDLER_ABORT;
 	}
 
 	ret = cmds->proc(work);
Signature · 1 line
2.53.0