Message ID | 20230321133312.103789-3-linkinjeon@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | ksmbd: return unsupported error on smb1 mount | expand |
On (23/03/21 22:33), Namjae Jeon wrote: [..] > @@ -442,9 +442,26 @@ static int smb_handle_negotiate(struct ksmbd_work *work) > { > struct smb_negotiate_rsp *neg_rsp = work->response_buf; > > - ksmbd_debug(SMB, "Unsupported SMB protocol\n"); > - neg_rsp->hdr.Status.CifsError = STATUS_INVALID_LOGON_TYPE; > - return -EINVAL; > + ksmbd_debug(SMB, "Unsupported SMB1 protocol\n"); > + > + /* > + * Remove 4 byte direct TCP header, add 1 byte wc, 2 byte bcc > + * and 2 byte DialectIndex. > + */ > + *(__be32 *)work->response_buf = > + cpu_to_be32(sizeof(struct smb_hdr) - 4 + 2 + 2); In other words cpu_to_be32(sizeof(struct smb_hdr)). > + neg_rsp->hdr.Status.CifsError = STATUS_SUCCESS; > + > + neg_rsp->hdr.Command = SMB_COM_NEGOTIATE; > + *(__le32 *)neg_rsp->hdr.Protocol = SMB1_PROTO_NUMBER; I assume this should say cpu_to_le32(SMB1_PROTO_NUMBER).
2023-03-23 11:53 GMT+09:00, Sergey Senozhatsky <senozhatsky@chromium.org>: > On (23/03/21 22:33), Namjae Jeon wrote: > [..] >> @@ -442,9 +442,26 @@ static int smb_handle_negotiate(struct ksmbd_work >> *work) >> { >> struct smb_negotiate_rsp *neg_rsp = work->response_buf; >> >> - ksmbd_debug(SMB, "Unsupported SMB protocol\n"); >> - neg_rsp->hdr.Status.CifsError = STATUS_INVALID_LOGON_TYPE; >> - return -EINVAL; >> + ksmbd_debug(SMB, "Unsupported SMB1 protocol\n"); >> + >> + /* >> + * Remove 4 byte direct TCP header, add 1 byte wc, 2 byte bcc >> + * and 2 byte DialectIndex. >> + */ >> + *(__be32 *)work->response_buf = >> + cpu_to_be32(sizeof(struct smb_hdr) - 4 + 2 + 2); > > In other words cpu_to_be32(sizeof(struct smb_hdr)). Yes, that's possible too, but wouldn't this make the comments easier to understand..? > >> + neg_rsp->hdr.Status.CifsError = STATUS_SUCCESS; >> + >> + neg_rsp->hdr.Command = SMB_COM_NEGOTIATE; >> + *(__le32 *)neg_rsp->hdr.Protocol = SMB1_PROTO_NUMBER; > > I assume this should say cpu_to_le32(SMB1_PROTO_NUMBER). SMB1_PROTO_NUMBER is declared as: #define SMB1_PROTO_NUMBER cpu_to_le32(0x424d53ff) Thanks! >
On (23/03/23 13:10), Namjae Jeon wrote: [..] > >> + /* > >> + * Remove 4 byte direct TCP header, add 1 byte wc, 2 byte bcc > >> + * and 2 byte DialectIndex. > >> + */ > >> + *(__be32 *)work->response_buf = > >> + cpu_to_be32(sizeof(struct smb_hdr) - 4 + 2 + 2); > > > > In other words cpu_to_be32(sizeof(struct smb_hdr)). > Yes, that's possible too, but wouldn't this make the comments easier > to understand..? Maybe, but the comment says "-4 + 1 + 2 + 2", which doesn't match the code. > >> + *(__le32 *)neg_rsp->hdr.Protocol = SMB1_PROTO_NUMBER; > > > > I assume this should say cpu_to_le32(SMB1_PROTO_NUMBER). > SMB1_PROTO_NUMBER is declared as: > #define SMB1_PROTO_NUMBER cpu_to_le32(0x424d53ff) Oh, I see.
2023-03-23 14:00 GMT+09:00, Sergey Senozhatsky <senozhatsky@chromium.org>: > On (23/03/23 13:10), Namjae Jeon wrote: > [..] >> >> + /* >> >> + * Remove 4 byte direct TCP header, add 1 byte wc, 2 byte bcc >> >> + * and 2 byte DialectIndex. >> >> + */ >> >> + *(__be32 *)work->response_buf = >> >> + cpu_to_be32(sizeof(struct smb_hdr) - 4 + 2 + 2); >> > >> > In other words cpu_to_be32(sizeof(struct smb_hdr)). >> Yes, that's possible too, but wouldn't this make the comments easier >> to understand..? > > Maybe, but the comment says "-4 + 1 + 2 + 2", which doesn't match the code. wc is included in smb_hdr struct. Hm.. I will update the comment. > >> >> + *(__le32 *)neg_rsp->hdr.Protocol = SMB1_PROTO_NUMBER; >> > >> > I assume this should say cpu_to_le32(SMB1_PROTO_NUMBER). >> SMB1_PROTO_NUMBER is declared as: >> #define SMB1_PROTO_NUMBER cpu_to_le32(0x424d53ff) > > Oh, I see. >
diff --git a/fs/ksmbd/connection.c b/fs/ksmbd/connection.c index 5d914715605f..115a67d2cf78 100644 --- a/fs/ksmbd/connection.c +++ b/fs/ksmbd/connection.c @@ -319,13 +319,10 @@ int ksmbd_conn_handler_loop(void *p) } /* - * Check if pdu size is valid (min : smb header size, - * max : 0x00FFFFFF). + * Check maximum pdu size(0x00FFFFFF). */ - if (pdu_size < __SMB2_HEADER_STRUCTURE_SIZE || - pdu_size > MAX_STREAM_PROT_LEN) { + if (pdu_size > MAX_STREAM_PROT_LEN) break; - } /* 4 for rfc1002 length field */ size = pdu_size + 4; diff --git a/fs/ksmbd/smb_common.c b/fs/ksmbd/smb_common.c index 079c9e76818d..87fa578b141e 100644 --- a/fs/ksmbd/smb_common.c +++ b/fs/ksmbd/smb_common.c @@ -442,9 +442,26 @@ static int smb_handle_negotiate(struct ksmbd_work *work) { struct smb_negotiate_rsp *neg_rsp = work->response_buf; - ksmbd_debug(SMB, "Unsupported SMB protocol\n"); - neg_rsp->hdr.Status.CifsError = STATUS_INVALID_LOGON_TYPE; - return -EINVAL; + ksmbd_debug(SMB, "Unsupported SMB1 protocol\n"); + + /* + * Remove 4 byte direct TCP header, add 1 byte wc, 2 byte bcc + * and 2 byte DialectIndex. + */ + *(__be32 *)work->response_buf = + cpu_to_be32(sizeof(struct smb_hdr) - 4 + 2 + 2); + neg_rsp->hdr.Status.CifsError = STATUS_SUCCESS; + + neg_rsp->hdr.Command = SMB_COM_NEGOTIATE; + *(__le32 *)neg_rsp->hdr.Protocol = SMB1_PROTO_NUMBER; + neg_rsp->hdr.Flags = SMBFLG_RESPONSE; + neg_rsp->hdr.Flags2 = SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS | + SMBFLG2_EXT_SEC | SMBFLG2_IS_LONG_NAME; + + neg_rsp->hdr.WordCount = 1; + neg_rsp->DialectIndex = cpu_to_le16(work->conn->dialect); + neg_rsp->ByteCount = 0; + return 0; } int ksmbd_smb_negotiate_common(struct ksmbd_work *work, unsigned int command) diff --git a/fs/ksmbd/smb_common.h b/fs/ksmbd/smb_common.h index e663ab9ea759..d30ce4c1a151 100644 --- a/fs/ksmbd/smb_common.h +++ b/fs/ksmbd/smb_common.h @@ -158,8 +158,15 @@ #define SMB1_PROTO_NUMBER cpu_to_le32(0x424d53ff) #define SMB_COM_NEGOTIATE 0x72 - #define SMB1_CLIENT_GUID_SIZE (16) + +#define SMBFLG_RESPONSE 0x80 /* this PDU is a response from server */ + +#define SMBFLG2_IS_LONG_NAME cpu_to_le16(0x40) +#define SMBFLG2_EXT_SEC cpu_to_le16(0x800) +#define SMBFLG2_ERR_STATUS cpu_to_le16(0x4000) +#define SMBFLG2_UNICODE cpu_to_le16(0x8000) + struct smb_hdr { __be32 smb_buf_length; __u8 Protocol[4]; @@ -199,28 +206,7 @@ struct smb_negotiate_req { struct smb_negotiate_rsp { struct smb_hdr hdr; /* wct = 17 */ __le16 DialectIndex; /* 0xFFFF = no dialect acceptable */ - __u8 SecurityMode; - __le16 MaxMpxCount; - __le16 MaxNumberVcs; - __le32 MaxBufferSize; - __le32 MaxRawSize; - __le32 SessionKey; - __le32 Capabilities; /* see below */ - __le32 SystemTimeLow; - __le32 SystemTimeHigh; - __le16 ServerTimeZone; - __u8 EncryptionKeyLength; __le16 ByteCount; - union { - unsigned char EncryptionKey[8]; /* cap extended security off */ - /* followed by Domain name - if extended security is off */ - /* followed by 16 bytes of server GUID */ - /* then security blob if cap_extended_security negotiated */ - struct { - unsigned char GUID[SMB1_CLIENT_GUID_SIZE]; - unsigned char SecurityBlob[1]; - } __packed extended_response; - } __packed u; } __packed; struct filesystem_attribute_info {
ksmbd disconnect connection when mounting with vers=smb1. ksmbd should send smb1 negotiate response to client for correct unsupported error return. This patch add needed SMB1 macros and fill NegProt part of the response for smb1 negotiate response. Reported-by: Steve French <stfrench@microsoft.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org> --- fs/ksmbd/connection.c | 7 ++----- fs/ksmbd/smb_common.c | 23 ++++++++++++++++++++--- fs/ksmbd/smb_common.h | 30 ++++++++---------------------- 3 files changed, 30 insertions(+), 30 deletions(-)