Skip to contentSkip to conversation

Question for the devs - Found something interesting in the OpenVPN source code that I change in my modified version...

Openvpn-devel Jon Chiappetta 2 participants 4 messages Nov 2, 2025 – Nov 12, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]...

#1 lore raw

Hi Gert and devs!

While I was working on the modified version of OpenVPN and tracing through the SSL library, I found what I think is a potential invalid memory index access. I wanted to verify with you all if this could be correct.

https://github.com/OpenVPN/openvpn/blob/master/src/openvpn/ssl.c#L3682
https://github.com/OpenVPN/openvpn/blob/master/src/openvpn/ssl_common.h#L712

In this file and that line number there is an integer i that is outside the for loop so that it can look for the matching session key index number. However, there is an if statement after the loop which checks for the following conditions:

if (i == TM_SIZE && is_hard_reset_method2(op))

If the key is not found, i will equal TM_SIZE but if the second condition is false for whatever reason, the code will enter the else block and during my debugging, it entered into an invalid index of the array!

struct tls_session *session = &multi->session[i]; (-> multi->session[TM_SIZE] !)

And as you can see, the session array is only sized for this amount:

struct tls_session session[TM_SIZE];

In my modified version I wasn't sure of when this hard reset check condition would be true but to prevent an invalid memory access I changed my code to be this instead:

if (i == TM_SIZE || is_hard_reset_method2(op))

That way it helps to protect the else block and from potentially going into an invalid index number in the worst case.

Does this seem correct to anyone else or am I missing something else here?

Thanks again,
Jon C

#2 lore raw

Hi,

Quoted 6 lines · Jon Chiappetta via Openvpn-devel

In this file and that line number there is an integer i that is outside the for loop so that it can look for the matching session key index number. However, there is an if statement after the loop which checks for the following conditions:

if (i == TM_SIZE && is_hard_reset_method2(op))

This is interesting because we have received another report about this a few days ago (from the ZeroPath AI), and it definitely looks like a bug from here. This is Arne's code so I leave it to him to confirm.

Quoted 5 lines

In my modified version I wasn't sure of when this hard reset check condition would be true but to prevent an invalid memory access I changed my code to be this instead:

if (i == TM_SIZE || is_hard_reset_method2(op))

#3 lore raw

Hi,

Quoted 9 lines · Gert Doering
Quoted 5 lines

In my modified version I wasn't sure of when this hard reset check condition would be true but to prevent an invalid memory access I changed my code to be this instead:

if (i == TM_SIZE || is_hard_reset_method2(op))

From my understanding of this code, this is the correct fix.

Good find!

As a followup to this - it's not the right fix, and my understanding was not sufficient.

Arne understands the code better and has just moved the possibly-invalid pointer initialization a few lines down (to be committed in the next few minutes), after the check on "i" and error-exit.

Thanks for your report!

(There is another one which I'll look into "really soon now" :-) )

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#4 lore raw

Yeah, looks pretty good, thanks for taking time to look it over! That if statement should be able to catch the invalid index and goto error which will then also help to protect and bypass the variable list index access further down below on line number 3814 which was an additional access also!

Thanks again all,
Jon C

Quoted 38 lines · Gert Doering

Hi,

Quoted 2 lines · Gert Doering
Quoted 2 lines

In my modified version I wasn't sure of when this hard reset check condition would be true but to prevent an invalid memory access I

changed

Quoted 7 lines
Quoted 3 lines

my code to be this instead:

if (i == TM_SIZE || is_hard_reset_method2(op))

From my understanding of this code, this is the correct fix.

Good find!

As a followup to this - it's not the right fix, and my understanding was not sufficient.

Arne understands the code better and has just moved the possibly-invalid pointer initialization a few lines down (to be committed in the next few minutes), after the check on "i" and error-exit.

Thanks for your report!

(There is another one which I'll look into "really soon now" :-) )

gert

--
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never
doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh
Mistress

Gert Doering - Munich, Germany
[email protected]...