Skip to content

Commit 39b291b

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: return unsupported error on smb1 mount
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. Cc: [email protected] Reported-by: Steve French <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent b53e8cf commit 39b291b

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

fs/ksmbd/connection.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,10 @@ int ksmbd_conn_handler_loop(void *p)
319319
}
320320

321321
/*
322-
* Check if pdu size is valid (min : smb header size,
323-
* max : 0x00FFFFFF).
322+
* Check maximum pdu size(0x00FFFFFF).
324323
*/
325-
if (pdu_size < __SMB2_HEADER_STRUCTURE_SIZE ||
326-
pdu_size > MAX_STREAM_PROT_LEN) {
324+
if (pdu_size > MAX_STREAM_PROT_LEN)
327325
break;
328-
}
329326

330327
/* 4 for rfc1002 length field */
331328
size = pdu_size + 4;

fs/ksmbd/smb_common.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,26 @@ static int smb_handle_negotiate(struct ksmbd_work *work)
442442
{
443443
struct smb_negotiate_rsp *neg_rsp = work->response_buf;
444444

445-
ksmbd_debug(SMB, "Unsupported SMB protocol\n");
446-
neg_rsp->hdr.Status.CifsError = STATUS_INVALID_LOGON_TYPE;
447-
return -EINVAL;
445+
ksmbd_debug(SMB, "Unsupported SMB1 protocol\n");
446+
447+
/*
448+
* Remove 4 byte direct TCP header, add 2 byte bcc and
449+
* 2 byte DialectIndex.
450+
*/
451+
*(__be32 *)work->response_buf =
452+
cpu_to_be32(sizeof(struct smb_hdr) - 4 + 2 + 2);
453+
neg_rsp->hdr.Status.CifsError = STATUS_SUCCESS;
454+
455+
neg_rsp->hdr.Command = SMB_COM_NEGOTIATE;
456+
*(__le32 *)neg_rsp->hdr.Protocol = SMB1_PROTO_NUMBER;
457+
neg_rsp->hdr.Flags = SMBFLG_RESPONSE;
458+
neg_rsp->hdr.Flags2 = SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS |
459+
SMBFLG2_EXT_SEC | SMBFLG2_IS_LONG_NAME;
460+
461+
neg_rsp->hdr.WordCount = 1;
462+
neg_rsp->DialectIndex = cpu_to_le16(work->conn->dialect);
463+
neg_rsp->ByteCount = 0;
464+
return 0;
448465
}
449466

450467
int ksmbd_smb_negotiate_common(struct ksmbd_work *work, unsigned int command)

fs/ksmbd/smb_common.h

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,15 @@
158158

159159
#define SMB1_PROTO_NUMBER cpu_to_le32(0x424d53ff)
160160
#define SMB_COM_NEGOTIATE 0x72
161-
162161
#define SMB1_CLIENT_GUID_SIZE (16)
162+
163+
#define SMBFLG_RESPONSE 0x80 /* this PDU is a response from server */
164+
165+
#define SMBFLG2_IS_LONG_NAME cpu_to_le16(0x40)
166+
#define SMBFLG2_EXT_SEC cpu_to_le16(0x800)
167+
#define SMBFLG2_ERR_STATUS cpu_to_le16(0x4000)
168+
#define SMBFLG2_UNICODE cpu_to_le16(0x8000)
169+
163170
struct smb_hdr {
164171
__be32 smb_buf_length;
165172
__u8 Protocol[4];
@@ -199,28 +206,7 @@ struct smb_negotiate_req {
199206
struct smb_negotiate_rsp {
200207
struct smb_hdr hdr; /* wct = 17 */
201208
__le16 DialectIndex; /* 0xFFFF = no dialect acceptable */
202-
__u8 SecurityMode;
203-
__le16 MaxMpxCount;
204-
__le16 MaxNumberVcs;
205-
__le32 MaxBufferSize;
206-
__le32 MaxRawSize;
207-
__le32 SessionKey;
208-
__le32 Capabilities; /* see below */
209-
__le32 SystemTimeLow;
210-
__le32 SystemTimeHigh;
211-
__le16 ServerTimeZone;
212-
__u8 EncryptionKeyLength;
213209
__le16 ByteCount;
214-
union {
215-
unsigned char EncryptionKey[8]; /* cap extended security off */
216-
/* followed by Domain name - if extended security is off */
217-
/* followed by 16 bytes of server GUID */
218-
/* then security blob if cap_extended_security negotiated */
219-
struct {
220-
unsigned char GUID[SMB1_CLIENT_GUID_SIZE];
221-
unsigned char SecurityBlob[1];
222-
} __packed extended_response;
223-
} __packed u;
224210
} __packed;
225211

226212
struct filesystem_attribute_info {

0 commit comments

Comments
 (0)