FAILED: patch "[PATCH] ksmbd: validate mech token in session setup" failed to apply to 5.15-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 92e470163d96df8db6c4fa0f484e4a229edb903d
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2024012238-uptown-tinker-aaab@gregkh' --subject-prefix 'PATCH 5.15.y' HEAD^..
Possible dependencies:
92e470163d96 ("ksmbd: validate mech token in session setup")084ba46fc41c ("ksmbd: switch to use kmemdup_nul() helper")38c8a9a52082 ("smb: move client and server files to common directory fs/smb") abdb1742a312 ("cifs: get rid of mount options string parsing")9fd29a5bae6e ("cifs: use fs_context for automounts")5dd8ce24667a ("cifs: missing directory in MAINTAINERS file")332019e23a51 ("Merge tag '5.20-rc-smb3-client-fixes-part2' of git://git.samba.org/sfrench/cifs-2.6")
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 92e470163d96df8db6c4fa0f484e4a229edb903d Mon Sep 17 00:00:00 2001
From: Namjae Jeon <[email protected]>
Date: Sat, 13 Jan 2024 15:11:41 +0900
Subject: [PATCH] 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.
fs/smb/server/asn1.c +5 -0
@@ -214,10 +214,15 @@ static int ksmbd_neg_token_alloc(void *context, size_t hdrlen, {struct ksmbd_conn *conn = context; +if (!vlen) +return -EINVAL ; + conn->mechToken =kmemdup_nul (value, vlen,GFP_KERNEL );if (!conn->mechToken)return -ENOMEM ; + conn->mechTokenLen = (unsigned int )vlen; +return 0 ; }
fs/smb/server/connection.h +1 -0
@@ -88,6 +88,7 @@ struct ksmbd_conn {__u16 dialect;char *mechToken; +unsigned int mechTokenLen;struct ksmbd_conn_ops *conn_ops;
fs/smb/server/smb2pdu.c +17 -5
@@ -1414,7 +1414,10 @@ static struct ksmbd_user *session_user(struct ksmbd_conn *conn,char *name;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 )) {ksmbd_debug (SMB ,"blob len %d too small\n" , secbuf_len);return NULL ;
@@ -1505,7 +1508,10 @@ static int ntlm_authenticate(struct ksmbd_work *work,struct authenticate_message *authblob; 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);if (rc) {set_user_flag (sess->user,KSMBD_USER_FLAG_BAD_PASSWORD );
@@ -1778,8 +1784,7 @@ int smb2_sess_setup(struct ksmbd_work *work) negblob_off =le16_to_cpu (req->SecurityBufferOffset); negblob_len =le16_to_cpu (req->SecurityBufferLength); -if (negblob_off < offsetof(struct smb2_sess_setup_req , Buffer) || - negblob_len < offsetof(struct negotiate_message , NegotiateFlags)) { +if (negblob_off < offsetof(struct smb2_sess_setup_req , Buffer)) { rc = -EINVAL ; goto out_err; }
@@ -1788,8 +1793,15 @@ int smb2_sess_setup(struct ksmbd_work *work) negblob_off);if (decode_negotiation_token (conn, negblob, negblob_len) ==0 ) { -if (conn->mechToken) +if (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) {