Commit 92e47016 authored by Namjae Jeon's avatar Namjae Jeon Committed by Steve French

ksmbd: validate mech token in session setup

If client send invalid mech token in session setup request, ksmbd
validate and make the error if it is invalid.

Cc: stable@vger.kernel.org
Reported-by: zdi-disclosures@trendmicro.com # ZDI-CAN-22890
Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent fdfd6dde
...@@ -214,10 +214,15 @@ static int ksmbd_neg_token_alloc(void *context, size_t hdrlen, ...@@ -214,10 +214,15 @@ static int ksmbd_neg_token_alloc(void *context, size_t hdrlen,
{ {
struct ksmbd_conn *conn = context; struct ksmbd_conn *conn = context;
if (!vlen)
return -EINVAL;
conn->mechToken = kmemdup_nul(value, vlen, GFP_KERNEL); conn->mechToken = kmemdup_nul(value, vlen, GFP_KERNEL);
if (!conn->mechToken) if (!conn->mechToken)
return -ENOMEM; return -ENOMEM;
conn->mechTokenLen = (unsigned int)vlen;
return 0; return 0;
} }
......
...@@ -88,6 +88,7 @@ struct ksmbd_conn { ...@@ -88,6 +88,7 @@ struct ksmbd_conn {
__u16 dialect; __u16 dialect;
char *mechToken; char *mechToken;
unsigned int mechTokenLen;
struct ksmbd_conn_ops *conn_ops; struct ksmbd_conn_ops *conn_ops;
......
...@@ -1414,7 +1414,10 @@ static struct ksmbd_user *session_user(struct ksmbd_conn *conn, ...@@ -1414,7 +1414,10 @@ static struct ksmbd_user *session_user(struct ksmbd_conn *conn,
char *name; char *name;
unsigned int name_off, name_len, secbuf_len; unsigned int name_off, name_len, secbuf_len;
secbuf_len = le16_to_cpu(req->SecurityBufferLength); if (conn->use_spnego && conn->mechToken)
secbuf_len = conn->mechTokenLen;
else
secbuf_len = le16_to_cpu(req->SecurityBufferLength);
if (secbuf_len < sizeof(struct authenticate_message)) { if (secbuf_len < sizeof(struct authenticate_message)) {
ksmbd_debug(SMB, "blob len %d too small\n", secbuf_len); ksmbd_debug(SMB, "blob len %d too small\n", secbuf_len);
return NULL; return NULL;
...@@ -1505,7 +1508,10 @@ static int ntlm_authenticate(struct ksmbd_work *work, ...@@ -1505,7 +1508,10 @@ static int ntlm_authenticate(struct ksmbd_work *work,
struct authenticate_message *authblob; struct authenticate_message *authblob;
authblob = user_authblob(conn, req); authblob = user_authblob(conn, req);
sz = le16_to_cpu(req->SecurityBufferLength); if (conn->use_spnego && conn->mechToken)
sz = conn->mechTokenLen;
else
sz = le16_to_cpu(req->SecurityBufferLength);
rc = ksmbd_decode_ntlmssp_auth_blob(authblob, sz, conn, sess); rc = ksmbd_decode_ntlmssp_auth_blob(authblob, sz, conn, sess);
if (rc) { if (rc) {
set_user_flag(sess->user, KSMBD_USER_FLAG_BAD_PASSWORD); set_user_flag(sess->user, KSMBD_USER_FLAG_BAD_PASSWORD);
...@@ -1778,8 +1784,7 @@ int smb2_sess_setup(struct ksmbd_work *work) ...@@ -1778,8 +1784,7 @@ int smb2_sess_setup(struct ksmbd_work *work)
negblob_off = le16_to_cpu(req->SecurityBufferOffset); negblob_off = le16_to_cpu(req->SecurityBufferOffset);
negblob_len = le16_to_cpu(req->SecurityBufferLength); negblob_len = le16_to_cpu(req->SecurityBufferLength);
if (negblob_off < offsetof(struct smb2_sess_setup_req, Buffer) || if (negblob_off < offsetof(struct smb2_sess_setup_req, Buffer)) {
negblob_len < offsetof(struct negotiate_message, NegotiateFlags)) {
rc = -EINVAL; rc = -EINVAL;
goto out_err; goto out_err;
} }
...@@ -1788,8 +1793,15 @@ int smb2_sess_setup(struct ksmbd_work *work) ...@@ -1788,8 +1793,15 @@ int smb2_sess_setup(struct ksmbd_work *work)
negblob_off); negblob_off);
if (decode_negotiation_token(conn, negblob, negblob_len) == 0) { if (decode_negotiation_token(conn, negblob, negblob_len) == 0) {
if (conn->mechToken) if (conn->mechToken) {
negblob = (struct negotiate_message *)conn->mechToken; negblob = (struct negotiate_message *)conn->mechToken;
negblob_len = conn->mechTokenLen;
}
}
if (negblob_len < offsetof(struct negotiate_message, NegotiateFlags)) {
rc = -EINVAL;
goto out_err;
} }
if (server_conf.auth_mechs & conn->auth_mechs) { if (server_conf.auth_mechs & conn->auth_mechs) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment