Skip to content

Commit 4227f81

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: fix transform header validation
Validate that the transform and smb request headers are present before checking OriginalMessageSize and SessionId fields. Cc: Ronnie Sahlberg <[email protected]> Cc: Ralph Böhme <[email protected]> Cc: Sergey Senozhatsky <[email protected]> Reviewed-by: Tom Talpey <[email protected]> Acked-by: Hyunchul Lee <[email protected]> Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 8f77150 commit 4227f81

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

fs/ksmbd/smb2pdu.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8414,28 +8414,28 @@ int smb3_decrypt_req(struct ksmbd_work *work)
84148414
unsigned int buf_data_size = pdu_length + 4 -
84158415
sizeof(struct smb2_transform_hdr);
84168416
struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
8417-
unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
84188417
int rc = 0;
84198418

8420-
sess = ksmbd_session_lookup_all(conn, le64_to_cpu(tr_hdr->SessionId));
8421-
if (!sess) {
8422-
pr_err("invalid session id(%llx) in transform header\n",
8423-
le64_to_cpu(tr_hdr->SessionId));
8424-
return -ECONNABORTED;
8425-
}
8426-
84278419
if (pdu_length + 4 <
84288420
sizeof(struct smb2_transform_hdr) + sizeof(struct smb2_hdr)) {
84298421
pr_err("Transform message is too small (%u)\n",
84308422
pdu_length);
84318423
return -ECONNABORTED;
84328424
}
84338425

8434-
if (pdu_length + 4 < orig_len + sizeof(struct smb2_transform_hdr)) {
8426+
if (pdu_length + 4 <
8427+
le32_to_cpu(tr_hdr->OriginalMessageSize) + sizeof(struct smb2_transform_hdr)) {
84358428
pr_err("Transform message is broken\n");
84368429
return -ECONNABORTED;
84378430
}
84388431

8432+
sess = ksmbd_session_lookup_all(conn, le64_to_cpu(tr_hdr->SessionId));
8433+
if (!sess) {
8434+
pr_err("invalid session id(%llx) in transform header\n",
8435+
le64_to_cpu(tr_hdr->SessionId));
8436+
return -ECONNABORTED;
8437+
}
8438+
84398439
iov[0].iov_base = buf;
84408440
iov[0].iov_len = sizeof(struct smb2_transform_hdr);
84418441
iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);

0 commit comments

Comments
 (0)