Skip to content

Commit 18a015b

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: check protocol id in ksmbd_verify_smb_message()
When second smb2 pdu has invalid protocol id, ksmbd doesn't detect it and allow to process smb2 request. This patch add the check it in ksmbd_verify_smb_message() and don't use protocol id of smb2 request as protocol id of response. Reviewed-by: Ronnie Sahlberg <[email protected]> Reviewed-by: Ralph Böhme <[email protected]> Reported-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 9f63233 commit 18a015b

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

fs/ksmbd/smb2pdu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ static void init_chained_smb2_rsp(struct ksmbd_work *work)
433433
work->compound_pfid = KSMBD_NO_FID;
434434
}
435435
memset((char *)rsp_hdr + 4, 0, sizeof(struct smb2_hdr) + 2);
436-
rsp_hdr->ProtocolId = rcv_hdr->ProtocolId;
436+
rsp_hdr->ProtocolId = SMB2_PROTO_NUMBER;
437437
rsp_hdr->StructureSize = SMB2_HEADER_STRUCTURE_SIZE;
438438
rsp_hdr->Command = rcv_hdr->Command;
439439

fs/ksmbd/smb_common.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,22 @@ int ksmbd_lookup_protocol_idx(char *str)
129129
*
130130
* check for valid smb signature and packet direction(request/response)
131131
*
132-
* Return: 0 on success, otherwise 1
132+
* Return: 0 on success, otherwise -EINVAL
133133
*/
134134
int ksmbd_verify_smb_message(struct ksmbd_work *work)
135135
{
136-
struct smb2_hdr *smb2_hdr = work->request_buf;
136+
struct smb2_hdr *smb2_hdr = work->request_buf + work->next_smb2_rcv_hdr_off;
137+
struct smb_hdr *hdr;
137138

138139
if (smb2_hdr->ProtocolId == SMB2_PROTO_NUMBER)
139140
return ksmbd_smb2_check_message(work);
140141

141-
return 0;
142+
hdr = work->request_buf;
143+
if (*(__le32 *)hdr->Protocol == SMB1_PROTO_NUMBER &&
144+
hdr->Command == SMB_COM_NEGOTIATE)
145+
return 0;
146+
147+
return -EINVAL;
142148
}
143149

144150
/**
@@ -265,7 +271,6 @@ static int ksmbd_negotiate_smb_dialect(void *buf)
265271
return BAD_PROT_ID;
266272
}
267273

268-
#define SMB_COM_NEGOTIATE 0x72
269274
int ksmbd_init_smb_server(struct ksmbd_work *work)
270275
{
271276
struct ksmbd_conn *conn = work->conn;

fs/ksmbd/smb_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@
210210
FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES)
211211

212212
#define SMB1_PROTO_NUMBER cpu_to_le32(0x424d53ff)
213+
#define SMB_COM_NEGOTIATE 0x72
213214

214215
#define SMB1_CLIENT_GUID_SIZE (16)
215216
struct smb_hdr {

0 commit comments

Comments
 (0)