diff mbox series

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

Message ID 20211007223103.5340-1-linkinjeon@kernel.org (mailing list archive)
State New, archived
Headers show
Series ksmbd: limit read/write/trans buffer size not to exceed 8MB | expand

Commit Message

Namjae Jeon Oct. 7, 2021, 10:31 p.m. UTC
ksmbd limit read/write/trans buffer size not to exceed 8MB like samba.

Cc: Tom Talpey <tom@talpey.com>
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Cc: Ralph Böhme <slow@samba.org>
Cc: Hyunchul Lee <hyc.lee@gmail.com>
Cc: Steve French <smfrench@gmail.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: Colin Ian King <colin.king@canonical.com>

Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
---
 fs/ksmbd/smb2ops.c | 3 +++
 fs/ksmbd/smb2pdu.h | 1 +
 2 files changed, 4 insertions(+)

Comments

Sergey Senozhatsky Oct. 12, 2021, 1:01 a.m. UTC | #1
On Fri, Oct 8, 2021 at 7:31 AM Namjae Jeon <linkinjeon@kernel.org> wrote:
>
> ksmbd limit read/write/trans buffer size not to exceed 8MB like samba.
>

[..]

> @@ -284,6 +284,7 @@ int init_smb3_11_server(struct ksmbd_conn *conn)
>
>  void init_smb2_max_read_size(unsigned int sz)
>  {
> +       sz = min_t(u32, sz, SMB_MAX_IOSIZE);
>         smb21_server_values.max_read_size = sz;
>         smb30_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)
>
>  void init_smb2_max_write_size(unsigned int sz)
>  {
> +       sz = min_t(u32, sz, SMB_MAX_IOSIZE);
>         smb21_server_values.max_write_size = sz;
>         smb30_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)
>
>  void init_smb2_max_trans_size(unsigned int sz)
>  {
> +       sz = min_t(u32, sz, SMB_MAX_IOSIZE);
>         smb21_server_values.max_trans_size = sz;
>         smb30_server_values.max_trans_size = sz;
>         smb302_server_values.max_trans_size = sz;

Does SMB2 support max request size of 8MB or does it support requests
of only up to 64k in size?
Namjae Jeon Oct. 12, 2021, 1:29 a.m. UTC | #2
2021-10-12 10:01 GMT+09:00, Sergey Senozhatsky <senozhatsky@chromium.org>:
> On Fri, Oct 8, 2021 at 7:31 AM Namjae Jeon <linkinjeon@kernel.org> wrote:
>>
>> ksmbd limit read/write/trans buffer size not to exceed 8MB like samba.
>>
>
> [..]
>
>> @@ -284,6 +284,7 @@ int init_smb3_11_server(struct ksmbd_conn *conn)
>>
>>  void init_smb2_max_read_size(unsigned int sz)
>>  {
>> +       sz = min_t(u32, sz, SMB_MAX_IOSIZE);
>>         smb21_server_values.max_read_size = sz;
>>         smb30_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)
>>
>>  void init_smb2_max_write_size(unsigned int sz)
>>  {
>> +       sz = min_t(u32, sz, SMB_MAX_IOSIZE);
>>         smb21_server_values.max_write_size = sz;
>>         smb30_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)
>>
>>  void init_smb2_max_trans_size(unsigned int sz)
>>  {
>> +       sz = min_t(u32, sz, SMB_MAX_IOSIZE);
>>         smb21_server_values.max_trans_size = sz;
>>         smb30_server_values.max_trans_size = sz;
>>         smb302_server_values.max_trans_size = sz;
>
> Does SMB2 support max request size of 8MB or does it support requests
> of only up to 64k in size?
I have sent v3 patch to the list now. Please check it.
This value should be greater than or equal to 65536 and smaller than
max rfc1002 length.

Thanks!
>
diff mbox series

Patch

diff --git a/fs/ksmbd/smb2ops.c b/fs/ksmbd/smb2ops.c
index b06456eb587b..97027c0962d3 100644
--- a/fs/ksmbd/smb2ops.c
+++ b/fs/ksmbd/smb2ops.c
@@ -284,6 +284,7 @@  int init_smb3_11_server(struct ksmbd_conn *conn)
 
 void init_smb2_max_read_size(unsigned int sz)
 {
+	sz = min_t(u32, sz, SMB_MAX_IOSIZE);
 	smb21_server_values.max_read_size = sz;
 	smb30_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)
 
 void init_smb2_max_write_size(unsigned int sz)
 {
+	sz = min_t(u32, sz, SMB_MAX_IOSIZE);
 	smb21_server_values.max_write_size = sz;
 	smb30_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)
 
 void init_smb2_max_trans_size(unsigned int sz)
 {
+	sz = min_t(u32, sz, SMB_MAX_IOSIZE);
 	smb21_server_values.max_trans_size = sz;
 	smb30_server_values.max_trans_size = sz;
 	smb302_server_values.max_trans_size = sz;
diff --git a/fs/ksmbd/smb2pdu.h b/fs/ksmbd/smb2pdu.h
index a6dec5ec6a54..b66c562e90e3 100644
--- a/fs/ksmbd/smb2pdu.h
+++ b/fs/ksmbd/smb2pdu.h
@@ -113,6 +113,7 @@ 
 #define SMB21_DEFAULT_IOSIZE	(1024 * 1024)
 #define SMB3_DEFAULT_IOSIZE	(4 * 1024 * 1024)
 #define SMB3_DEFAULT_TRANS_SIZE	(1024 * 1024)
+#define SMB_MAX_IOSIZE	(8 * 1024 * 1024)
 
 /*
  * SMB2 Header Definition