tls-crypt-v2: bail out if the client key is too small
PATCH 1/1 tls-crypt-v2: bail out if the client key is too small
The tls-crypt-v2 key should be at least 2 bytes long in order to read the actual length.
Bail out if the key is too short.
Failing to do so will lead to a read out of the buffer boundary.
While at it improve the error message a bit.
--- src/openvpn/tls_crypt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
src/openvpn/tls_crypt.c +2 -1
@@ -557,7 +557,8 @@ tls_crypt_v2_extract_client_key(struct buffer *buf,if (BLEN (&wrapped_client_key) <sizeof (net_len)) { -msg (D_TLS_ERRORS ,"failed to read length" ); +msg (D_TLS_ERRORS ,"Can not read tls-crypt-v2 client key length" ); +return false; }memcpy (&net_len,BEND (&wrapped_client_key) -sizeof (net_len),sizeof (net_len));
Signature · 1 line
2.35.1
Am 28.06.22 um 11:41 schrieb Antonio Quartulli:
Quoted 5 lines
The tls-crypt-v2 key should be at least 2 bytes long in order to read the actual length.
Bail out if the key is too short.
Failing to do so will lead to a read out of the buffer boundary.
Actually not. We read from BEND(), so this is defined for TCP since the minimum length there is 3 bytes (pkt len + opcode). For UDP we might read past the beginning of the packet but since they are buffers coming from the packet stack we have the headroom/tailroom, so might read some random data (but not out of bound!).
So we copy some more or less random number into net_len/wkc_len but without actually reading from undefined memory.
The next line will then almost definitively fail
if (!buf_advance(&wrapped_client_key, BLEN(&wrapped_client_key) -wkc_len))
Since BLEN(wrapped_client_key) is 0 or 1 or wkc_len has to be 0 or 1 to not fail this check
and then in turn
tls_crypt_v2_unwrap_client_key
will fail at
if (BLEN(&wrapped_client_key) < sizeof(net_len))
Quoted 2 lines
While at it improve the error message a bit.
I have taken the "why is this not a problem?" text from Arne's ACK and included it into the commit message.
Your patch has been applied to the master and release/2.5 branch.
commit 462339a45089ef655faf02232d7d792def9b8afb (master) commit ce24bec7e2518d4ea7aa931021454d1191f4906b (release/2.5)
Author: Antonio Quartulli Date: Tue Jun 28 11:41:44 2022 +0200
tls-crypt-v2: bail out if the client key is too small
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg24580.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering