Skip to content

Commit 62c487b

Browse files
namjaejeonSteve French
authored andcommitted
ksmbd: limit pdu length size according to connection status
Stream protocol length will never be larger than 16KB until session setup. After session setup, the size of requests will not be larger than 16KB + SMB2 MAX WRITE size. This patch limits these invalidly oversized requests and closes the connection immediately. Fixes: 0626e66 ("cifsd: add server handler for central processing and tranport layers") Cc: [email protected] Reported-by: [email protected] # ZDI-CAN-18259 Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 5fde3c2 commit 62c487b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

fs/ksmbd/connection.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ int ksmbd_conn_handler_loop(void *p)
280280
{
281281
struct ksmbd_conn *conn = (struct ksmbd_conn *)p;
282282
struct ksmbd_transport *t = conn->transport;
283-
unsigned int pdu_size;
283+
unsigned int pdu_size, max_allowed_pdu_size;
284284
char hdr_buf[4] = {0,};
285285
int size;
286286

@@ -305,13 +305,26 @@ int ksmbd_conn_handler_loop(void *p)
305305
pdu_size = get_rfc1002_len(hdr_buf);
306306
ksmbd_debug(CONN, "RFC1002 header %u bytes\n", pdu_size);
307307

308+
if (conn->status == KSMBD_SESS_GOOD)
309+
max_allowed_pdu_size =
310+
SMB3_MAX_MSGSIZE + conn->vals->max_write_size;
311+
else
312+
max_allowed_pdu_size = SMB3_MAX_MSGSIZE;
313+
314+
if (pdu_size > max_allowed_pdu_size) {
315+
pr_err_ratelimited("PDU length(%u) excceed maximum allowed pdu size(%u) on connection(%d)\n",
316+
pdu_size, max_allowed_pdu_size,
317+
conn->status);
318+
break;
319+
}
320+
308321
/*
309322
* Check if pdu size is valid (min : smb header size,
310323
* max : 0x00FFFFFF).
311324
*/
312325
if (pdu_size < __SMB2_HEADER_STRUCTURE_SIZE ||
313326
pdu_size > MAX_STREAM_PROT_LEN) {
314-
continue;
327+
break;
315328
}
316329

317330
/* 4 for rfc1002 length field */

fs/ksmbd/smb2pdu.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424

2525
#define SMB21_DEFAULT_IOSIZE (1024 * 1024)
2626
#define SMB3_DEFAULT_TRANS_SIZE (1024 * 1024)
27-
#define SMB3_MIN_IOSIZE (64 * 1024)
28-
#define SMB3_MAX_IOSIZE (8 * 1024 * 1024)
27+
#define SMB3_MIN_IOSIZE (64 * 1024)
28+
#define SMB3_MAX_IOSIZE (8 * 1024 * 1024)
29+
#define SMB3_MAX_MSGSIZE (4 * 4096)
2930

3031
/*
3132
* Definitions for SMB2 Protocol Data Units (network frames)

0 commit comments

Comments
 (0)