Skip to content

Commit 5fe7f7b

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: fix out-of-bound read in smb2_write
ksmbd_smb2_check_message doesn't validate hdr->NextCommand. If ->NextCommand is bigger than Offset + Length of smb2 write, It will allow oversized smb2 write length. It will cause OOB read in smb2_write. Cc: [email protected] Reported-by: [email protected] # ZDI-CAN-21164 Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 40b268d commit 5fe7f7b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

fs/smb/server/smb2misc.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,16 @@ int ksmbd_smb2_check_message(struct ksmbd_work *work)
351351
int command;
352352
__u32 clc_len; /* calculated length */
353353
__u32 len = get_rfc1002_len(work->request_buf);
354-
__u32 req_struct_size;
354+
__u32 req_struct_size, next_cmd = le32_to_cpu(hdr->NextCommand);
355355

356-
if (le32_to_cpu(hdr->NextCommand) > 0)
357-
len = le32_to_cpu(hdr->NextCommand);
356+
if ((u64)work->next_smb2_rcv_hdr_off + next_cmd > len) {
357+
pr_err("next command(%u) offset exceeds smb msg size\n",
358+
next_cmd);
359+
return 1;
360+
}
361+
362+
if (next_cmd > 0)
363+
len = next_cmd;
358364
else if (work->next_smb2_rcv_hdr_off)
359365
len -= work->next_smb2_rcv_hdr_off;
360366

0 commit comments

Comments
 (0)