@@ -351,6 +351,7 @@ int ksmbd_smb2_check_message(struct ksmbd_work *work)
351
351
int command ;
352
352
__u32 clc_len ; /* calculated length */
353
353
__u32 len = get_rfc1002_len (work -> request_buf );
354
+ __u32 req_struct_size ;
354
355
355
356
if (le32_to_cpu (hdr -> NextCommand ) > 0 )
356
357
len = le32_to_cpu (hdr -> NextCommand );
@@ -373,17 +374,9 @@ int ksmbd_smb2_check_message(struct ksmbd_work *work)
373
374
}
374
375
375
376
if (smb2_req_struct_sizes [command ] != pdu -> StructureSize2 ) {
376
- if (command != SMB2_OPLOCK_BREAK_HE &&
377
- (hdr -> Status == 0 || pdu -> StructureSize2 != SMB2_ERROR_STRUCTURE_SIZE2_LE )) {
378
- /* error packets have 9 byte structure size */
379
- ksmbd_debug (SMB ,
380
- "Illegal request size %u for command %d\n" ,
381
- le16_to_cpu (pdu -> StructureSize2 ), command );
382
- return 1 ;
383
- } else if (command == SMB2_OPLOCK_BREAK_HE &&
384
- hdr -> Status == 0 &&
385
- le16_to_cpu (pdu -> StructureSize2 ) != OP_BREAK_STRUCT_SIZE_20 &&
386
- le16_to_cpu (pdu -> StructureSize2 ) != OP_BREAK_STRUCT_SIZE_21 ) {
377
+ if (command == SMB2_OPLOCK_BREAK_HE &&
378
+ le16_to_cpu (pdu -> StructureSize2 ) != OP_BREAK_STRUCT_SIZE_20 &&
379
+ le16_to_cpu (pdu -> StructureSize2 ) != OP_BREAK_STRUCT_SIZE_21 ) {
387
380
/* special case for SMB2.1 lease break message */
388
381
ksmbd_debug (SMB ,
389
382
"Illegal request size %d for oplock break\n" ,
@@ -392,6 +385,14 @@ int ksmbd_smb2_check_message(struct ksmbd_work *work)
392
385
}
393
386
}
394
387
388
+ req_struct_size = le16_to_cpu (pdu -> StructureSize2 ) +
389
+ __SMB2_HEADER_STRUCTURE_SIZE ;
390
+ if (command == SMB2_LOCK_HE )
391
+ req_struct_size -= sizeof (struct smb2_lock_element );
392
+
393
+ if (req_struct_size > len + 1 )
394
+ return 1 ;
395
+
395
396
if (smb2_calc_size (hdr , & clc_len ))
396
397
return 1 ;
397
398
0 commit comments