提交 e70a9e24 编写于 作者: N Namjae Jeon 提交者: Zhong Jinghua

ksmbd: limit read/write/trans buffer size not to exceed 8MB

mainline inclusion
from mainline-5.15-rc7
commit 4bc59477
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I60T7G
CVE: NA

Reference: https://git.kernel.org/torvalds/linux/c/4bc59477c329

-------------------------------

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: NNamjae Jeon <linkinjeon@kernel.org>
Signed-off-by: NSteve French <stfrench@microsoft.com>
Signed-off-by: NJason Yan <yanaijie@huawei.com>
Signed-off-by: NZhong Jinghua <zhongjinghua@huawei.com>
上级 5ebef4b0
...@@ -284,6 +284,7 @@ int init_smb3_11_server(struct ksmbd_conn *conn) ...@@ -284,6 +284,7 @@ int init_smb3_11_server(struct ksmbd_conn *conn)
void init_smb2_max_read_size(unsigned int sz) void init_smb2_max_read_size(unsigned int sz)
{ {
sz = clamp_val(sz, SMB3_MIN_IOSIZE, SMB3_MAX_IOSIZE);
smb21_server_values.max_read_size = sz; smb21_server_values.max_read_size = sz;
smb30_server_values.max_read_size = sz; smb30_server_values.max_read_size = sz;
smb302_server_values.max_read_size = sz; smb302_server_values.max_read_size = sz;
...@@ -292,6 +293,7 @@ void init_smb2_max_read_size(unsigned int sz) ...@@ -292,6 +293,7 @@ void init_smb2_max_read_size(unsigned int sz)
void init_smb2_max_write_size(unsigned int sz) void init_smb2_max_write_size(unsigned int sz)
{ {
sz = clamp_val(sz, SMB3_MIN_IOSIZE, SMB3_MAX_IOSIZE);
smb21_server_values.max_write_size = sz; smb21_server_values.max_write_size = sz;
smb30_server_values.max_write_size = sz; smb30_server_values.max_write_size = sz;
smb302_server_values.max_write_size = sz; smb302_server_values.max_write_size = sz;
...@@ -300,6 +302,7 @@ void init_smb2_max_write_size(unsigned int sz) ...@@ -300,6 +302,7 @@ void init_smb2_max_write_size(unsigned int sz)
void init_smb2_max_trans_size(unsigned int sz) void init_smb2_max_trans_size(unsigned int sz)
{ {
sz = clamp_val(sz, SMB3_MIN_IOSIZE, SMB3_MAX_IOSIZE);
smb21_server_values.max_trans_size = sz; smb21_server_values.max_trans_size = sz;
smb30_server_values.max_trans_size = sz; smb30_server_values.max_trans_size = sz;
smb302_server_values.max_trans_size = sz; smb302_server_values.max_trans_size = sz;
......
...@@ -524,7 +524,7 @@ int smb2_allocate_rsp_buf(struct ksmbd_work *work) ...@@ -524,7 +524,7 @@ int smb2_allocate_rsp_buf(struct ksmbd_work *work)
{ {
struct smb2_hdr *hdr = work->request_buf; struct smb2_hdr *hdr = work->request_buf;
size_t small_sz = MAX_CIFS_SMALL_BUFFER_SIZE; size_t small_sz = MAX_CIFS_SMALL_BUFFER_SIZE;
size_t large_sz = work->conn->vals->max_trans_size + MAX_SMB2_HDR_SIZE; size_t large_sz = small_sz + work->conn->vals->max_trans_size;
size_t sz = small_sz; size_t sz = small_sz;
int cmd = le16_to_cpu(hdr->Command); int cmd = le16_to_cpu(hdr->Command);
......
...@@ -113,6 +113,8 @@ ...@@ -113,6 +113,8 @@
#define SMB21_DEFAULT_IOSIZE (1024 * 1024) #define SMB21_DEFAULT_IOSIZE (1024 * 1024)
#define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024) #define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)
#define SMB3_DEFAULT_TRANS_SIZE (1024 * 1024) #define SMB3_DEFAULT_TRANS_SIZE (1024 * 1024)
#define SMB3_MIN_IOSIZE (64 * 1024)
#define SMB3_MAX_IOSIZE (8 * 1024 * 1024)
/* /*
* SMB2 Header Definition * SMB2 Header Definition
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册