smb: fix minimum PDU size
Subsystems (2)
v2 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->v2:
- Create patch #0001 #0003
- Patch #0002: update value of SMB2_MIN_SUPPORTED_PDU_SIZE
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 v2 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
RFC PATCH v2 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 smb_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
RFC PATCH v2 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