Skip to content

Commit 4bc5947

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: limit read/write/trans buffer size not to exceed 8MB
ksmbd limit read/write/trans buffer size not to exceed maximum 8MB. And set the minimum value of max response buffer size to 64KB. Windows client doesn't send session setup request if ksmbd set max trans/read/write size lower than 64KB in smb2 negotiate. It means windows allow at least 64 KB or more about this value. Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent dbad630 commit 4bc5947

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

fs/ksmbd/smb2ops.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ int init_smb3_11_server(struct ksmbd_conn *conn)
284284

285285
void init_smb2_max_read_size(unsigned int sz)
286286
{
287+
sz = clamp_val(sz, SMB3_MIN_IOSIZE, SMB3_MAX_IOSIZE);
287288
smb21_server_values.max_read_size = sz;
288289
smb30_server_values.max_read_size = sz;
289290
smb302_server_values.max_read_size = sz;
@@ -292,6 +293,7 @@ void init_smb2_max_read_size(unsigned int sz)
292293

293294
void init_smb2_max_write_size(unsigned int sz)
294295
{
296+
sz = clamp_val(sz, SMB3_MIN_IOSIZE, SMB3_MAX_IOSIZE);
295297
smb21_server_values.max_write_size = sz;
296298
smb30_server_values.max_write_size = sz;
297299
smb302_server_values.max_write_size = sz;
@@ -300,6 +302,7 @@ void init_smb2_max_write_size(unsigned int sz)
300302

301303
void init_smb2_max_trans_size(unsigned int sz)
302304
{
305+
sz = clamp_val(sz, SMB3_MIN_IOSIZE, SMB3_MAX_IOSIZE);
303306
smb21_server_values.max_trans_size = sz;
304307
smb30_server_values.max_trans_size = sz;
305308
smb302_server_values.max_trans_size = sz;

fs/ksmbd/smb2pdu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ int smb2_allocate_rsp_buf(struct ksmbd_work *work)
524524
{
525525
struct smb2_hdr *hdr = work->request_buf;
526526
size_t small_sz = MAX_CIFS_SMALL_BUFFER_SIZE;
527-
size_t large_sz = work->conn->vals->max_trans_size + MAX_SMB2_HDR_SIZE;
527+
size_t large_sz = small_sz + work->conn->vals->max_trans_size;
528528
size_t sz = small_sz;
529529
int cmd = le16_to_cpu(hdr->Command);
530530

fs/ksmbd/smb2pdu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@
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)
116118

117119
/*
118120
* SMB2 Header Definition

0 commit comments

Comments
 (0)