From: "flichtenheld (Code Review)" Date: Wed, 10 Jan 2024 14:57:05 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <24b0de3b3035d04c48fef070956d4e3bf7d03131-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="X+/xiouS7Gs="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[release/2.6]: NTLM: add length check to add_security_buffer List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --X+/xiouS7Gs= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. Hello plaisthos, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/493?usp=3Demail to review the following change. Change subject: NTLM: add length check to add_security_buffer ...................................................................... NTLM: add length check to add_security_buffer Especially ntlmv2_response can be very big, so make sure we not do exceed the size of the phase3 buffer. Change-Id: Icea931d29e3e504e23e045539b21013b42172664 Signed-off-by: Frank Lichtenheld --- M src/openvpn/ntlm.c 1 file changed, 10 insertions(+), 5 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/93/493/1 diff --git a/src/openvpn/ntlm.c b/src/openvpn/ntlm.c index 2e77214..2b735ec 100644 --- a/src/openvpn/ntlm.c +++ b/src/openvpn/ntlm.c @@ -167,8 +167,13 @@ static void add_security_buffer(int sb_offset, void *data, int length, - unsigned char *msg_buf, int *msg_bufpos) + unsigned char *msg_buf, int *msg_bufpos, size_t msg_bu= fsize) { + if (*msg_bufpos + length > msg_bufsize) + { + msg(M_WARN, "NTLM: security buffer too big for message buffer"); + return; + } /* Adds security buffer data to a message and sets security buffer's * offset and length */ msg_buf[sb_offset] =3D (unsigned char)length; @@ -396,20 +401,20 @@ if (ntlmv2_enabled) /* NTLMv2 response */ { add_security_buffer(0x14, ntlmv2_response, ntlmv2_blob_size + 16, - phase3, &phase3_bufpos); + phase3, &phase3_bufpos, sizeof(phase3)); } else /* NTLM response */ { - add_security_buffer(0x14, ntlm_response, 24, phase3, &phase3_bufpo= s); + add_security_buffer(0x14, ntlm_response, 24, phase3, &phase3_bufpo= s, sizeof(phase3)); } /* username in ascii */ add_security_buffer(0x24, username, strlen(username), phase3, - &phase3_bufpos); + &phase3_bufpos, sizeof(phase3)); /* Set domain. If is empty, default domain will be used * (i.e. proxy's domain) */ - add_security_buffer(0x1c, domain, strlen(domain), phase3, &phase3_bufp= os); + add_security_buffer(0x1c, domain, strlen(domain), phase3, &phase3_bufp= os, sizeof(phase3)); /* other security buffers will be empty */ phase3[0x10] =3D phase3_bufpos; /* lm not used */ -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/493?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: release/2.6 Gerrit-Change-Id: Icea931d29e3e504e23e045539b21013b42172664 Gerrit-Change-Number: 493 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-MessageType: newchange --X+/xiouS7Gs= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: plaisthos.

flichtenheld would like plaisthos to review this change.

Vi= ew Change

NTLM: add length check to add_security_buffer

Especial= ly ntlmv2_response can be very big, so make sure
we not do exceed the si= ze of the phase3 buffer.

Change-Id: Icea931d29e3e504e23e045539b21013= b42172664
Signed-off-by: Frank Lichtenheld <frank@...2641...>
-= --
M src/openvpn/ntlm.c
1 file changed, 10 insertions(+), 5 deletions= (-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/=
93/493/1
diff --git a/src/openvpn/ntlm.c b/src/openvpn/ntlm.c
index 2e77214..2b735ec 100644
--- a/src/openvpn/= ntlm.c
+++ b/src/openvpn/ntlm.c
@@ -167,8 += 167,13 @@

static void
a= dd_security_buffer(int sb_offset, void *data, int length,
- unsigned char *msg_= buf, int *msg_bufpos)
+ unsigned char *msg_buf, int *msg_bufpos, size_t msg_b= ufsize)
{
+ if (*msg_bufpos + length > msg_bufsize)
+ {
+ msg(M_WARN, "NTLM: security buffer too big= for message buffer");
+ return;
+ }
/* Adds security buffer data to a message an= d sets security buffer's
* offset and length */
msg_buf[sb_offset] =3D (unsigned char)length;@@ -396,20 +401,20 @@
if (ntlmv2_enabled) = /* NTLMv2 response */
{
add_s= ecurity_buffer(0x14, ntlmv2_response, ntlmv2_blob_size + 16,
- phase3, = &phase3_bufpos);

= + phase3, &phase3_bufpos, sizeof(phase3));
}
else /* NTLM response */
{
-= add_security_buffer(0x14, ntlm_response, 24, phase3, &phase3_bu= fpos);
+ add_s= ecurity_buffer(0x14, ntlm_response, 24, phase3, &phase3_bufpos, sizeof(= phase3));
}

/* = username in ascii */
add_security_buffer(0x24, usernam= e, strlen(username), phase3,
- &phase3_bufpos);
+ &phase3_bufpo= s, sizeof(phase3));

/* Set domain. I= f <domain> is empty, default domain will be used
= * (i.e. proxy's domain) */
- add_security_buffer(0x1c, domain, strlen(domain), phase3, &a= mp;phase3_bufpos);
+ = add_security_buffer(0x1c, domain, strlen(domain), phase3, &phase3_bu= fpos, sizeof(phase3));

/* other secu= rity buffers will be empty */
phase3[0x10] =3D phase3_= bufpos; /* lm not used */

To view, = visit cha= nge 493. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: Icea931d29e3e504e23e045539b2= 1013b42172664
Gerrit-Change-Number: 493
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-MessageType: newchange
--X+/xiouS7Gs=--