Skip to content

Commit 7a33488

Browse files
slowfranklinsmfrench
authored andcommitted
ksmbd: validate credit charge after validating SMB2 PDU body size
smb2_validate_credit_charge() accesses fields in the SMB2 PDU body, but until smb2_calc_size() is called the PDU has not yet been verified to be large enough to access the PDU dynamic part length field. Acked-by: Namjae Jeon <[email protected]> Signed-off-by: Ralph Boehme <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 2ea086e commit 7a33488

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

fs/ksmbd/smb2misc.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,26 +400,20 @@ int ksmbd_smb2_check_message(struct ksmbd_work *work)
400400
}
401401
}
402402

403-
if ((work->conn->vals->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU) &&
404-
smb2_validate_credit_charge(work->conn, hdr)) {
405-
work->conn->ops->set_rsp_status(work, STATUS_INVALID_PARAMETER);
406-
return 1;
407-
}
408-
409403
if (smb2_calc_size(hdr, &clc_len))
410404
return 1;
411405

412406
if (len != clc_len) {
413407
/* client can return one byte more due to implied bcc[0] */
414408
if (clc_len == len + 1)
415-
return 0;
409+
goto validate_credit;
416410

417411
/*
418412
* Some windows servers (win2016) will pad also the final
419413
* PDU in a compound to 8 bytes.
420414
*/
421415
if (ALIGN(clc_len, 8) == len)
422-
return 0;
416+
goto validate_credit;
423417

424418
/*
425419
* windows client also pad up to 8 bytes when compounding.
@@ -432,7 +426,7 @@ int ksmbd_smb2_check_message(struct ksmbd_work *work)
432426
"cli req padded more than expected. Length %d not %d for cmd:%d mid:%llu\n",
433427
len, clc_len, command,
434428
le64_to_cpu(hdr->MessageId));
435-
return 0;
429+
goto validate_credit;
436430
}
437431

438432
ksmbd_debug(SMB,
@@ -443,6 +437,13 @@ int ksmbd_smb2_check_message(struct ksmbd_work *work)
443437
return 1;
444438
}
445439

440+
validate_credit:
441+
if ((work->conn->vals->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU) &&
442+
smb2_validate_credit_charge(work->conn, hdr)) {
443+
work->conn->ops->set_rsp_status(work, STATUS_INVALID_PARAMETER);
444+
return 1;
445+
}
446+
446447
return 0;
447448
}
448449

0 commit comments

Comments
 (0)