Skip to content

Commit d738950

Browse files
HexRabbitSteve French
authored andcommitted
ksmbd: fix slab-out-of-bounds read in smb2_handle_negotiate
Check request_buf length first to avoid out-of-bounds read by req->DialectCount. [ 3350.990282] BUG: KASAN: slab-out-of-bounds in smb2_handle_negotiate+0x35d7/0x3e60 [ 3350.990282] Read of size 2 at addr ffff88810ad61346 by task kworker/5:0/276 [ 3351.000406] Workqueue: ksmbd-io handle_ksmbd_work [ 3351.003499] Call Trace: [ 3351.006473] <TASK> [ 3351.006473] dump_stack_lvl+0x8d/0xe0 [ 3351.006473] print_report+0xcc/0x620 [ 3351.006473] kasan_report+0x92/0xc0 [ 3351.006473] smb2_handle_negotiate+0x35d7/0x3e60 [ 3351.014760] ksmbd_smb_negotiate_common+0x7a7/0xf00 [ 3351.014760] handle_ksmbd_work+0x3f7/0x12d0 [ 3351.014760] process_one_work+0xa85/0x1780 Cc: stable@vger.kernel.org Signed-off-by: Kuan-Ting Chen <h3xrabbit@gmail.com> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 84c5aa4 commit d738950

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

fs/smb/server/smb2pdu.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,16 +1053,16 @@ int smb2_handle_negotiate(struct ksmbd_work *work)
10531053
return rc;
10541054
}
10551055

1056-
if (req->DialectCount == 0) {
1057-
pr_err("malformed packet\n");
1056+
smb2_buf_len = get_rfc1002_len(work->request_buf);
1057+
smb2_neg_size = offsetof(struct smb2_negotiate_req, Dialects);
1058+
if (smb2_neg_size > smb2_buf_len) {
10581059
rsp->hdr.Status = STATUS_INVALID_PARAMETER;
10591060
rc = -EINVAL;
10601061
goto err_out;
10611062
}
10621063

1063-
smb2_buf_len = get_rfc1002_len(work->request_buf);
1064-
smb2_neg_size = offsetof(struct smb2_negotiate_req, Dialects);
1065-
if (smb2_neg_size > smb2_buf_len) {
1064+
if (req->DialectCount == 0) {
1065+
pr_err("malformed packet\n");
10661066
rsp->hdr.Status = STATUS_INVALID_PARAMETER;
10671067
rc = -EINVAL;
10681068
goto err_out;

0 commit comments

Comments
 (0)