Skip to content

Commit

Permalink
ksmbd: limit pdu length size according to connection status
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
namjaejeon committed Jan 30, 2023
1 parent 9b7ecb8 commit 468d55b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
19 changes: 16 additions & 3 deletions connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ int ksmbd_conn_handler_loop(void *p)
{
struct ksmbd_conn *conn = (struct ksmbd_conn *)p;
struct ksmbd_transport *t = conn->transport;
unsigned int pdu_size;
unsigned int pdu_size, max_allowed_pdu_size;
char hdr_buf[4] = {0,};
int size;

Expand Down Expand Up @@ -329,11 +329,24 @@ int ksmbd_conn_handler_loop(void *p)
if (!ksmbd_pdu_size_has_room(pdu_size)) {
ksmbd_debug(CONN, "SMB request too short (%u bytes)\n",
pdu_size);
continue;
break;
}

if (conn->status == KSMBD_SESS_GOOD)
max_allowed_pdu_size =
SMB3_MAX_MSGSIZE + conn->vals->max_write_size;
else
max_allowed_pdu_size = SMB3_MAX_MSGSIZE;

if (pdu_size > max_allowed_pdu_size) {
pr_err_ratelimited("PDU length(%u) excceed maximum allowed pdu size(%u) on connection(%d)\n",
pdu_size, max_allowed_pdu_size,
conn->status);
break;
}

if (pdu_size > MAX_STREAM_PROT_LEN)
continue;
break;

/* 4 for rfc1002 length field */
size = pdu_size + 4;
Expand Down
5 changes: 3 additions & 2 deletions smb2pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@
#define SMB21_DEFAULT_IOSIZE (1024 * 1024)
#define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)
#define SMB3_DEFAULT_TRANS_SIZE (1024 * 1024)
#define SMB3_MIN_IOSIZE (64 * 1024)
#define SMB3_MAX_IOSIZE (8 * 1024 * 1024)
#define SMB3_MIN_IOSIZE (64 * 1024)
#define SMB3_MAX_IOSIZE (8 * 1024 * 1024)
#define SMB3_MAX_MSGSIZE (4 * 4096)

/*
* SMB2 Header Definition
Expand Down

0 comments on commit 468d55b

Please sign in to comment.