smb: fix minimum PDU size
Subsystems (2)
v3 cover smb: fix minimum PDU size
From: ChenXiaoSong <[email protected]>
If my understanding is incorrect, please let me know.
v1: https://lore.kernel.org/all/[email protected]/v1->v3:
- Create patch #0001 #0003
- Patch #0002: update value of SMB2_MIN_SUPPORTED_PDU_SIZE
v2: https://lore.kernel.org/linux-cifs/[email protected]/v2->v3:
- Patch #0002: fix typo in commit message (smb_pdu -> smb2_pdu)
ChenXiaoSong (3):
smb/server: fix minimum SMB1 PDU size smb/server: fix minimum SMB2 PDU size
smb: use sizeof() to get __SMB2_HEADER_STRUCTURE_SIZE
fs/smb/common/smb1pdu.h | 5 +++++ fs/smb/common/smb2pdu.h | 8 ++++---- fs/smb/server/connection.c | 8 ++++---- 3 files changed, 13 insertions(+), 8 deletions(-)
Signature · 1 line
2.43.0
RFC PATCH v3 1/3 smb/server: fix minimum SMB1 PDU size
From: ChenXiaoSong <[email protected]>
Since the RFC1002 header has been removed from struct smb_hdr, the minimum SMB1 PDU size should be updated as well.
--- fs/smb/common/smb1pdu.h | 5 +++++ fs/smb/server/connection.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-)
fs/smb/common/smb1pdu.h +5 -0
@@ -53,4 +53,9 @@ typedef struct smb_negotiate_req { unsigned char DialectsArray[]; }__packed SMB_NEGOTIATE_REQ ; +struct smb_pdu { +struct smb_hdr ; +__le16 ByteCount; +} __packed; +#endif /* _COMMON_SMB1_PDU_H */
fs/smb/server/connection.c +2 -2
@@ -295,7 +295,7 @@ bool ksmbd_conn_alive(struct ksmbd_conn *conn)return true; } -#define SMB1_MIN_SUPPORTED_HEADER_SIZE (sizeof(struct smb_hdr)) +#define SMB1_MIN_SUPPORTED_PDU_SIZE (sizeof(struct smb_pdu))#define SMB2_MIN_SUPPORTED_HEADER_SIZE (sizeof(struct smb2_hdr) + 4)/**
@@ -363,7 +363,7 @@ int ksmbd_conn_handler_loop(void *p)if (pdu_size >MAX_STREAM_PROT_LEN )break ; -if (pdu_size <SMB1_MIN_SUPPORTED_HEADER_SIZE ) +if (pdu_size <SMB1_MIN_SUPPORTED_PDU_SIZE )break ;/* 4 for rfc1002 length field */
Signature · 1 line
2.43.0
Namjae Jeon
maintainerRe: [PATCH RFC v3 1/3] smb/server: fix minimum SMB1 PDU size
Quoted 20 lines · On Sat, Dec 20, 2025 at 8:55 AM <[email protected]> wrote:
From: ChenXiaoSong <[email protected]>
Since the RFC1002 header has been removed from
struct smb_hdr, the minimum SMB1 PDU size should be updated as well.Fixes 83bfbd0bb902 ("cifs: Remove the RFC1002 header from smb_hdr")Suggested-by David Howells <[email protected]>Suggested-by Namjae Jeon <[email protected]>Signed-off-by ChenXiaoSong <[email protected]>--- fs/smb/common/smb1pdu.h | 5 +++++ fs/smb/server/connection.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-)fs/smb/common/smb1pdu.h +0
-0
fs/smb/common/smb1pdu.h typedef struct smb_negotiate_req { · line 59
Quoted 7 lines
fs/smb/common/smb1pdu.h +4
-0@@ -53,4 +53,9 @@ typedef struct smb_negotiate_req {unsigned char DialectsArray[]; }__packed SMB_NEGOTIATE_REQ ; +struct smb_pdu { +struct smb_hdr ; +__le16 ByteCount; +} __packed;
I don't prefer adding unused structure for size. Please use + 2 and add a comment to clarify why it's there.
Quoted 27 lines
fs/smb/common/smb1pdu.h +1
-0+#endif /* _COMMON_SMB1_PDU_H */ fs/smb/server/connection.c +2
-3@@ -295,7 +295,7 @@ bool ksmbd_conn_alive(struct ksmbd_conn *conn)return true; } -#define SMB1_MIN_SUPPORTED_HEADER_SIZE (sizeof(struct smb_hdr)) +#define SMB1_MIN_SUPPORTED_PDU_SIZE (sizeof(struct smb_pdu))#define SMB2_MIN_SUPPORTED_HEADER_SIZE (sizeof(struct smb2_hdr) + 4)/** @@ -363,7 +363,7 @@ int ksmbd_conn_handler_loop(void *p)if (pdu_size >MAX_STREAM_PROT_LEN )break ; -if (pdu_size <SMB1_MIN_SUPPORTED_HEADER_SIZE ) +if (pdu_size <SMB1_MIN_SUPPORTED_PDU_SIZE )break ;/* 4 for rfc1002 length field */ --2.43.0
RFC PATCH v3 2/3 smb/server: fix minimum SMB2 PDU size
In reply to [email protected]From: ChenXiaoSong <[email protected]>
The minimum SMB2 PDU size should be updated to the size of struct smb2_pdu.
--- fs/smb/server/connection.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/smb/server/connection.c +2 -2
@@ -296,7 +296,7 @@ bool ksmbd_conn_alive(struct ksmbd_conn *conn) }#define SMB1_MIN_SUPPORTED_PDU_SIZE (sizeof(struct smb_pdu)) -#define SMB2_MIN_SUPPORTED_HEADER_SIZE (sizeof(struct smb2_hdr) + 4) +#define SMB2_MIN_SUPPORTED_PDU_SIZE (sizeof(struct smb2_pdu))/** * ksmbd_conn_handler_loop() - session thread to listen on new smb requests
@@ -396,7 +396,7 @@ int ksmbd_conn_handler_loop(void *p)if (((struct smb2_hdr *)smb2_get_msg (conn->request_buf))->ProtocolId ==SMB2_PROTO_NUMBER ) { -if (pdu_size <SMB2_MIN_SUPPORTED_HEADER_SIZE ) +if (pdu_size <SMB2_MIN_SUPPORTED_PDU_SIZE )break ; }
Signature · 1 line
2.43.0
Re: [PATCH RFC v3 2/3] smb/server: fix minimum SMB2 PDU size
Hi Namjae,
Thank you for reviewing patch 01 and 03. I will update the patches according to your suggestions.
Do you have any suggestions for this patch 02?
Thanks,
ChenXiaoSong.
Quoted 34 lines · On 12/20/25 7:54 AM, [email protected] wrote:
From: ChenXiaoSong <[email protected]>
The minimum SMB2 PDU size should be updated to the size of
struct smb2_pdu.Suggested-by David Howells <[email protected]>Suggested-by Namjae Jeon <[email protected]>Signed-off-by ChenXiaoSong <[email protected]>--- fs/smb/server/connection.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/smb/server/connection.c +2
-2@@ -296,7 +296,7 @@ bool ksmbd_conn_alive(struct ksmbd_conn *conn) }#define SMB1_MIN_SUPPORTED_PDU_SIZE (sizeof(struct smb_pdu)) -#define SMB2_MIN_SUPPORTED_HEADER_SIZE (sizeof(struct smb2_hdr) + 4) +#define SMB2_MIN_SUPPORTED_PDU_SIZE (sizeof(struct smb2_pdu))/** * ksmbd_conn_handler_loop() - session thread to listen on new smb requests @@ -396,7 +396,7 @@ int ksmbd_conn_handler_loop(void *p)if (((struct smb2_hdr *)smb2_get_msg (conn->request_buf))->ProtocolId ==SMB2_PROTO_NUMBER ) { -if (pdu_size <SMB2_MIN_SUPPORTED_HEADER_SIZE ) +if (pdu_size <SMB2_MIN_SUPPORTED_PDU_SIZE )break ; }
RFC PATCH v3 3/3 smb: use sizeof() to get __SMB2_HEADER_STRUCTURE_SIZE
In reply to [email protected]From: ChenXiaoSong <[email protected]>
I have checked the size of the structure using GDB:
gdb ./build/fs/smb/server/ksmbd.ko
(gdb) p sizeof(struct smb2_hdr)
$1 = 64
gdb ./build/fs/smb/client/cifs.ko
(gdb) p sizeof(struct smb2_hdr)
$1 = 64
--- fs/smb/common/smb2pdu.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/smb/common/smb2pdu.h +4 -4
@@ -107,10 +107,6 @@* */ -#define __SMB2_HEADER_STRUCTURE_SIZE 64 -#define SMB2_HEADER_STRUCTURE_SIZE \ - cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE) -#define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)#define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)#define SMB2_COMPRESSION_TRANSFORM_ID cpu_to_le32(0x424d53fc)
@@ -157,6 +153,10 @@ struct smb2_hdr {__u8 Signature[16 ]; } __packed; +#define __SMB2_HEADER_STRUCTURE_SIZE (sizeof(struct smb2_hdr)) +#define SMB2_HEADER_STRUCTURE_SIZE \ + cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE) +struct smb3_hdr_req {__le32 ProtocolId;/* 0xFE 'S' 'M' 'B' */ __le16 StructureSize;/* 64 */
Signature · 1 line
2.43.0
Namjae Jeon
maintainerRe: [PATCH RFC v3 3/3] smb: use sizeof() to get __SMB2_HEADER_STRUCTURE_SIZE
Quoted 9 lines · On Sat, Dec 20, 2025 at 8:55 AM <[email protected]> wrote:
From: ChenXiaoSong <[email protected]>
I have checked the size of the structure using GDB:
gdb
./build/fs/smb/server/ksmbd.ko
(gdb) psizeof(struct smb2_hdr)
$1 = 64
Quoted 5 lines
gdb
./build/fs/smb/client/cifs.ko
(gdb) psizeof(struct smb2_hdr)
$1 = 64Signed-off-by ChenXiaoSong <[email protected]>
When reading the patch description, I don't know why this change is needed. You don't need to include this patch on the v3 patch-set. Thanks!
Quoted 33 lines
--- fs/smb/common/smb2pdu.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)fs/smb/common/smb2pdu.h +4
-5@@ -107,10 +107,6 @@* */ -#define __SMB2_HEADER_STRUCTURE_SIZE 64 -#define SMB2_HEADER_STRUCTURE_SIZE \ - cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE) -#define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)#define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)#define SMB2_COMPRESSION_TRANSFORM_ID cpu_to_le32(0x424d53fc)@@ -157,6 +153,10 @@ struct smb2_hdr {__u8 Signature[16 ]; } __packed; +#define __SMB2_HEADER_STRUCTURE_SIZE (sizeof(struct smb2_hdr)) +#define SMB2_HEADER_STRUCTURE_SIZE \ + cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE) +struct smb3_hdr_req {__le32 ProtocolId;/* 0xFE 'S' 'M' 'B' */ __le16 StructureSize;/* 64 */ --2.43.0
Re: [PATCH RFC v3 3/3] smb: use sizeof() to get __SMB2_HEADER_STRUCTURE_SIZE
Quoted 4 lines · Namjae Jeon
fs/smb/common/smb2pdu.h struct smb2_hdr { · line 159
Quoted 4 lines
fs/smb/common/smb2pdu.h +4
-0+#define __SMB2_HEADER_STRUCTURE_SIZE (sizeof(struct smb2_hdr)) +#define SMB2_HEADER_STRUCTURE_SIZE \ + cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE) +
You don't want to use this SMB2_HEADER_STRUCTURE_SIZE for your comparison as it's little-endian if that's your intent.
David
Re: [PATCH RFC v3 3/3] smb: use sizeof() to get __SMB2_HEADER_STRUCTURE_SIZE
This was just an incidental change and is unrelated to the issue we are fixing.
I will drop this patch in the next version.
Thanks,
ChenXiaoSong.
Quoted 2 lines · David Howells
You don't want to use this
SMB2_HEADER_STRUCTURE_SIZEfor your comparison as it's little-endian if that's your intent.