Skip to content

Commit 40fb3f3

Browse files
committed
ksmbd: validate smb request protocol id
This patch add the validation for smb request protocol id. If it is not one of the four ids(SMB1_PROTO_NUMBER, SMB2_PROTO_NUMBER, SMB2_TRANSFORM_PROTO_NUM, SMB2_COMPRESSION_TRANSFORM_ID), don't allow processing the request. And this will fix the following KASAN warning also. [ 13.905265] BUG: KASAN: slab-out-of-bounds in init_smb2_rsp_hdr+0x1b9/0x1f0 [ 13.905900] Read of size 16 at addr ffff888005fd2f34 by task kworker/0:2/44 ... [ 13.908553] Call Trace: [ 13.908793] <TASK> [ 13.908995] dump_stack_lvl+0x33/0x50 [ 13.909369] print_report+0xcc/0x620 [ 13.910870] kasan_report+0xae/0xe0 [ 13.911519] kasan_check_range+0x35/0x1b0 [ 13.911796] init_smb2_rsp_hdr+0x1b9/0x1f0 [ 13.912492] handle_ksmbd_work+0xe5/0x820 Reported-by: Chih-Yen Chang <[email protected]> Signed-off-by: Namjae Jeon <[email protected]>
1 parent 5217bd5 commit 40fb3f3

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

connection.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,6 @@ int ksmbd_conn_handler_loop(void *p)
382382
break;
383383

384384
memcpy(conn->request_buf, hdr_buf, sizeof(hdr_buf));
385-
if (!ksmbd_smb_request(conn))
386-
break;
387385

388386
/*
389387
* We already read 4 bytes to find out PDU size, now
@@ -401,6 +399,9 @@ int ksmbd_conn_handler_loop(void *p)
401399
continue;
402400
}
403401

402+
if (!ksmbd_smb_request(conn))
403+
break;
404+
404405
if (((struct smb2_hdr *)smb2_get_msg(conn->request_buf))->ProtocolId ==
405406
SMB2_PROTO_NUMBER) {
406407
if (pdu_size < SMB2_MIN_SUPPORTED_HEADER_SIZE)

smb2pdu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109

110110
#define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe) /* 'B''M''S' */
111111
#define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
112+
#define SMB2_COMPRESSION_TRANSFORM_ID cpu_to_le32(0x424d53fc)
112113

113114
#define SMB21_DEFAULT_IOSIZE (1024 * 1024)
114115
#define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)

smb_common.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,19 @@ int ksmbd_verify_smb_message(struct ksmbd_work *work)
194194
*/
195195
bool ksmbd_smb_request(struct ksmbd_conn *conn)
196196
{
197-
return conn->request_buf[0] == 0;
197+
__le32 *proto = (__le32 *)smb2_get_msg(conn->request_buf);
198+
199+
if (*proto == SMB2_COMPRESSION_TRANSFORM_ID) {
200+
pr_err_ratelimited("smb2 compression not support yet");
201+
return false;
202+
}
203+
204+
if (*proto != SMB1_PROTO_NUMBER &&
205+
*proto != SMB2_PROTO_NUMBER &&
206+
*proto != SMB2_TRANSFORM_PROTO_NUM)
207+
return false;
208+
209+
return true;
198210
}
199211

200212
static bool supported_protocol(int idx)

0 commit comments

Comments
 (0)