Skip to content

Commit fa0ee90

Browse files
committed
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. Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
1 parent ca2cf78 commit fa0ee90

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

connection.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ int ksmbd_conn_handler_loop(void *p)
300300
{
301301
struct ksmbd_conn *conn = (struct ksmbd_conn *)p;
302302
struct ksmbd_transport *t = conn->transport;
303-
unsigned int pdu_size;
303+
unsigned int pdu_size, max_allowed_pdu_size;
304304
char hdr_buf[4] = {0,};
305305
int size;
306306

@@ -329,11 +329,24 @@ int ksmbd_conn_handler_loop(void *p)
329329
if (!ksmbd_pdu_size_has_room(pdu_size)) {
330330
ksmbd_debug(CONN, "SMB request too short (%u bytes)\n",
331331
pdu_size);
332-
continue;
332+
break;
333+
}
334+
335+
if (conn->status == KSMBD_SESS_GOOD)
336+
max_allowed_pdu_size =
337+
SMB3_MAX_MSGSIZE + conn->vals->max_write_size;
338+
else
339+
max_allowed_pdu_size = SMB3_MAX_MSGSIZE;
340+
341+
if (pdu_size > max_allowed_pdu_size) {
342+
pr_err_ratelimited("PDU length(%u) excceed maximum allowed pdu size(%u) on connection(%d)\n",
343+
pdu_size, max_allowed_pdu_size,
344+
conn->status);
345+
break;
333346
}
334347

335348
if (pdu_size > MAX_STREAM_PROT_LEN)
336-
continue;
349+
break;
337350

338351
/* 4 for rfc1002 length field */
339352
size = pdu_size + 4;

smb2pdu.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@
113113
#define SMB21_DEFAULT_IOSIZE (1024 * 1024)
114114
#define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)
115115
#define SMB3_DEFAULT_TRANS_SIZE (1024 * 1024)
116-
#define SMB3_MIN_IOSIZE (64 * 1024)
117-
#define SMB3_MAX_IOSIZE (8 * 1024 * 1024)
116+
#define SMB3_MIN_IOSIZE (64 * 1024)
117+
#define SMB3_MAX_IOSIZE (8 * 1024 * 1024)
118+
#define SMB3_MAX_MSGSIZE (4 * 4096)
118119

119120
/*
120121
* SMB2 Header Definition

0 commit comments

Comments
 (0)