Skip to content

Commit

Permalink
ksmbd: fix out-of-bound read in smb2_write
Browse files Browse the repository at this point in the history
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: stable@vger.kernel.org
Reported-by: zdi-disclosures@trendmicro.com # ZDI-CAN-21164
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
  • Loading branch information
namjaejeon authored and Steve French committed Jun 17, 2023
1 parent 40b268d commit 5fe7f7b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions fs/smb/server/smb2misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,16 @@ int ksmbd_smb2_check_message(struct ksmbd_work *work)
int command;
__u32 clc_len; /* calculated length */
__u32 len = get_rfc1002_len(work->request_buf);
__u32 req_struct_size;
__u32 req_struct_size, next_cmd = le32_to_cpu(hdr->NextCommand);

if (le32_to_cpu(hdr->NextCommand) > 0)
len = le32_to_cpu(hdr->NextCommand);
if ((u64)work->next_smb2_rcv_hdr_off + next_cmd > len) {
pr_err("next command(%u) offset exceeds smb msg size\n",
next_cmd);
return 1;
}

if (next_cmd > 0)
len = next_cmd;
else if (work->next_smb2_rcv_hdr_off)
len -= work->next_smb2_rcv_hdr_off;

Expand Down

0 comments on commit 5fe7f7b

Please sign in to comment.