Skip to content

Commit d72a9c1

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: fix invalid request buffer access in compound
Ronnie reported invalid request buffer access in chained command when inserting garbage value to NextCommand of compound request. This patch add validation check to avoid this issue. Cc: Tom Talpey <[email protected]> Cc: Ronnie Sahlberg <[email protected]> Cc: Ralph Böhme <[email protected]> Tested-by: Steve French <[email protected]> Reviewed-by: Steve French <[email protected]> Acked-by: Hyunchul Lee <[email protected]> Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 18d4676 commit d72a9c1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

fs/ksmbd/smb2pdu.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,22 @@ static void init_chained_smb2_rsp(struct ksmbd_work *work)
459459
bool is_chained_smb2_message(struct ksmbd_work *work)
460460
{
461461
struct smb2_hdr *hdr = work->request_buf;
462-
unsigned int len;
462+
unsigned int len, next_cmd;
463463

464464
if (hdr->ProtocolId != SMB2_PROTO_NUMBER)
465465
return false;
466466

467467
hdr = ksmbd_req_buf_next(work);
468-
if (le32_to_cpu(hdr->NextCommand) > 0) {
468+
next_cmd = le32_to_cpu(hdr->NextCommand);
469+
if (next_cmd > 0) {
470+
if ((u64)work->next_smb2_rcv_hdr_off + next_cmd +
471+
__SMB2_HEADER_STRUCTURE_SIZE >
472+
get_rfc1002_len(work->request_buf)) {
473+
pr_err("next command(%u) offset exceeds smb msg size\n",
474+
next_cmd);
475+
return false;
476+
}
477+
469478
ksmbd_debug(SMB, "got SMB2 chained command\n");
470479
init_chained_smb2_rsp(work);
471480
return true;

0 commit comments

Comments
 (0)