Skip to content

Commit 94d95ac

Browse files
author
Marios Makassikis
committed
ksmbd: smb1: add buffer validation
Many functions assume the client sends well formed packets, or are optimistic about the buffer length (using PATH_MAX or a fixed '256' value) instead of the actual length. The pattern followed to fix this boils down to extracting the total buffer length and calculate how much data has been consumed. Signed-off-by: Marios Makassikis <[email protected]>
1 parent 9df0f70 commit 94d95ac

File tree

3 files changed

+398
-187
lines changed

3 files changed

+398
-187
lines changed

auth.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,16 +330,23 @@ static int calc_ntlmv2_hash(struct ksmbd_session *sess, char *ntlmv2_hash,
330330
* ksmbd_auth_ntlm() - NTLM authentication handler
331331
* @sess: session of connection
332332
* @pw_buf: NTLM challenge response
333-
* @passkey: user password
333+
* @pw_len: buffer length
334+
* @cryptkey: buffer length
334335
*
335336
* Return: 0 on success, error number on error
336337
*/
337-
int ksmbd_auth_ntlm(struct ksmbd_session *sess, char *pw_buf, char *cryptkey)
338+
int ksmbd_auth_ntlm(struct ksmbd_session *sess, char *pw_buf, size_t pw_len,
339+
char *cryptkey)
338340
{
339341
int rc;
340342
unsigned char p21[21];
341343
char key[CIFS_AUTH_RESP_SIZE];
342344

345+
if (pw_len < CIFS_AUTH_RESP_SIZE) {
346+
ksmbd_debug(AUTH, "short response\n");
347+
return -EINVAL;
348+
}
349+
343350
memset(p21, '\0', 21);
344351
memcpy(p21, user_passkey(sess->user), CIFS_NTHASH_SIZE);
345352
rc = ksmbd_enc_p24(p21, cryptkey, key);
@@ -601,7 +608,7 @@ int ksmbd_decode_ntlmssp_auth_blob(struct authenticate_message *authblob,
601608
conn->ntlmssp.cryptkey);
602609
else
603610
return ksmbd_auth_ntlm(sess, (char *)authblob +
604-
nt_off, conn->ntlmssp.cryptkey);
611+
nt_off, nt_len, conn->ntlmssp.cryptkey);
605612
}
606613
#endif
607614

auth.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ struct kvec;
3838
int ksmbd_crypt_message(struct ksmbd_conn *conn, struct kvec *iov,
3939
unsigned int nvec, int enc);
4040
void ksmbd_copy_gss_neg_header(void *buf);
41-
int ksmbd_auth_ntlm(struct ksmbd_session *sess, char *pw_buf, char *cryptkey);
41+
int ksmbd_auth_ntlm(struct ksmbd_session *sess, char *pw_buf, size_t pw_len,
42+
char *cryptkey);
4243
int ksmbd_auth_ntlmv2(struct ksmbd_session *sess, struct ntlmv2_resp *ntlmv2,
4344
int blen, char *domain_name, char *cryptkey);
4445
int ksmbd_decode_ntlmssp_auth_blob(struct authenticate_message *authblob,

0 commit comments

Comments
 (0)