Skip to content

Commit 98422bd

Browse files
namjaejeonSteve French
authored andcommitted
ksmbd: fix out of bounds read in smb2_sess_setup
ksmbd does not consider the case of that smb2 session setup is in compound request. If this is the second payload of the compound, OOB read issue occurs while processing the first payload in the smb2_sess_setup(). Cc: [email protected] Reported-by: [email protected] # ZDI-CAN-21355 Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent f65fadb commit 98422bd

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

fs/smb/server/smb2pdu.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,9 +1322,8 @@ static int decode_negotiation_token(struct ksmbd_conn *conn,
13221322

13231323
static int ntlm_negotiate(struct ksmbd_work *work,
13241324
struct negotiate_message *negblob,
1325-
size_t negblob_len)
1325+
size_t negblob_len, struct smb2_sess_setup_rsp *rsp)
13261326
{
1327-
struct smb2_sess_setup_rsp *rsp = smb2_get_msg(work->response_buf);
13281327
struct challenge_message *chgblob;
13291328
unsigned char *spnego_blob = NULL;
13301329
u16 spnego_blob_len;
@@ -1429,10 +1428,10 @@ static struct ksmbd_user *session_user(struct ksmbd_conn *conn,
14291428
return user;
14301429
}
14311430

1432-
static int ntlm_authenticate(struct ksmbd_work *work)
1431+
static int ntlm_authenticate(struct ksmbd_work *work,
1432+
struct smb2_sess_setup_req *req,
1433+
struct smb2_sess_setup_rsp *rsp)
14331434
{
1434-
struct smb2_sess_setup_req *req = smb2_get_msg(work->request_buf);
1435-
struct smb2_sess_setup_rsp *rsp = smb2_get_msg(work->response_buf);
14361435
struct ksmbd_conn *conn = work->conn;
14371436
struct ksmbd_session *sess = work->sess;
14381437
struct channel *chann = NULL;
@@ -1566,10 +1565,10 @@ static int ntlm_authenticate(struct ksmbd_work *work)
15661565
}
15671566

15681567
#ifdef CONFIG_SMB_SERVER_KERBEROS5
1569-
static int krb5_authenticate(struct ksmbd_work *work)
1568+
static int krb5_authenticate(struct ksmbd_work *work,
1569+
struct smb2_sess_setup_req *req,
1570+
struct smb2_sess_setup_rsp *rsp)
15701571
{
1571-
struct smb2_sess_setup_req *req = smb2_get_msg(work->request_buf);
1572-
struct smb2_sess_setup_rsp *rsp = smb2_get_msg(work->response_buf);
15731572
struct ksmbd_conn *conn = work->conn;
15741573
struct ksmbd_session *sess = work->sess;
15751574
char *in_blob, *out_blob;
@@ -1647,7 +1646,9 @@ static int krb5_authenticate(struct ksmbd_work *work)
16471646
return 0;
16481647
}
16491648
#else
1650-
static int krb5_authenticate(struct ksmbd_work *work)
1649+
static int krb5_authenticate(struct ksmbd_work *work,
1650+
struct smb2_sess_setup_req *req,
1651+
struct smb2_sess_setup_rsp *rsp)
16511652
{
16521653
return -EOPNOTSUPP;
16531654
}
@@ -1656,15 +1657,17 @@ static int krb5_authenticate(struct ksmbd_work *work)
16561657
int smb2_sess_setup(struct ksmbd_work *work)
16571658
{
16581659
struct ksmbd_conn *conn = work->conn;
1659-
struct smb2_sess_setup_req *req = smb2_get_msg(work->request_buf);
1660-
struct smb2_sess_setup_rsp *rsp = smb2_get_msg(work->response_buf);
1660+
struct smb2_sess_setup_req *req;
1661+
struct smb2_sess_setup_rsp *rsp;
16611662
struct ksmbd_session *sess;
16621663
struct negotiate_message *negblob;
16631664
unsigned int negblob_len, negblob_off;
16641665
int rc = 0;
16651666

16661667
ksmbd_debug(SMB, "Received request for session setup\n");
16671668

1669+
WORK_BUFFERS(work, req, rsp);
1670+
16681671
rsp->StructureSize = cpu_to_le16(9);
16691672
rsp->SessionFlags = 0;
16701673
rsp->SecurityBufferOffset = cpu_to_le16(72);
@@ -1786,7 +1789,7 @@ int smb2_sess_setup(struct ksmbd_work *work)
17861789

17871790
if (conn->preferred_auth_mech &
17881791
(KSMBD_AUTH_KRB5 | KSMBD_AUTH_MSKRB5)) {
1789-
rc = krb5_authenticate(work);
1792+
rc = krb5_authenticate(work, req, rsp);
17901793
if (rc) {
17911794
rc = -EINVAL;
17921795
goto out_err;
@@ -1800,7 +1803,7 @@ int smb2_sess_setup(struct ksmbd_work *work)
18001803
sess->Preauth_HashValue = NULL;
18011804
} else if (conn->preferred_auth_mech == KSMBD_AUTH_NTLMSSP) {
18021805
if (negblob->MessageType == NtLmNegotiate) {
1803-
rc = ntlm_negotiate(work, negblob, negblob_len);
1806+
rc = ntlm_negotiate(work, negblob, negblob_len, rsp);
18041807
if (rc)
18051808
goto out_err;
18061809
rsp->hdr.Status =
@@ -1813,7 +1816,7 @@ int smb2_sess_setup(struct ksmbd_work *work)
18131816
le16_to_cpu(rsp->SecurityBufferLength) - 1);
18141817

18151818
} else if (negblob->MessageType == NtLmAuthenticate) {
1816-
rc = ntlm_authenticate(work);
1819+
rc = ntlm_authenticate(work, req, rsp);
18171820
if (rc)
18181821
goto out_err;
18191822

0 commit comments

Comments
 (0)