Skip to contentSkip to conversation

Change in openvpn[master]: Fix "uninitialized pointer read" in openvpn_decrypt_aead

Openvpn-devel In review flichtenheld (Code Review) 2 participants 6 messages Jan 13, 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): gerrit.1736765057000.I0391f30a1e962ee242e9bcdec4f605bf7e831cca@...2715...

#1 lore raw

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/+/858?usp=email

to review the following change.

Change subject: Fix "uninitialized pointer read" in openvpn_decrypt_aead
......................................................................

Fix "uninitialized pointer read" in openvpn_decrypt_aead

Coverity complains that if we error out in the first error condition we try to free gc without initializing it.

While here move the declaration of outlen to the first usage.

Change-Id I0391f30a1e962ee242e9bcdec4f605bf7e831cca

---
M src/openvpn/crypto.c

1 file changed, 5 insertions(+), 5 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/58/858/1

src/openvpn/crypto.c +5 -5
index 84ec436..dbd95a8 100644
@@ -406,17 +406,15 @@
     static const char error_prefix[] = "AEAD Decrypt error";
     struct packet_id_net pin = { 0 };
     struct key_ctx *ctx = &opt->key_ctx_bi.decrypt;
+    struct gc_arena gc;
+
+    gc_init(&gc);
 
     if (cipher_decrypt_verify_fail_exceeded(ctx))
     {
         CRYPT_DROP("Decryption failed verification limit reached.");
     }
 
-    int outlen;
-    struct gc_arena gc;
-
-    gc_init(&gc);
-
     ASSERT(opt);
     ASSERT(frame);
     ASSERT(buf->len > 0);
@@ -506,6 +504,8 @@
     dmsg(D_PACKET_CONTENT, "DECRYPT AD: %s",
          format_hex(ad_start, ad_size, 0, &gc));
 
+    int outlen;
+
     /* Decrypt and authenticate packet */
     if (!cipher_ctx_update(ctx->cipher, BPTR(&work), &outlen, BPTR(buf),
                            data_len))

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/858?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I0391f30a1e962ee242e9bcdec4f605bf7e831cca
Gerrit-Change-Number: 858
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/858?usp=email )

Change subject: Fix "uninitialized pointer read" in openvpn_decrypt_aead
......................................................................

Patch Set 1: Code-Review+2

(1 comment)

Patchset:

PS1:
and Coverity is indeed right. I thought compilers should catch this too...Probably sparse would.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/858?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I0391f30a1e962ee242e9bcdec4f605bf7e831cca
Gerrit-Change-Number: 858
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 13 Jan 2025 10:51:05 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#3 lore raw

PATCH 1/1 Fix "uninitialized pointer read" in openvpn_decrypt_aead

In reply to a message not in the archive

From: Frank Lichtenheld <[email protected]...>

Coverity complains that if we error out in the first error condition we try to free gc without initializing it.

While here move the declaration of outlen to the first usage.

Change-Id I0391f30a1e962ee242e9bcdec4f605bf7e831cca

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/858
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Antonio Quartulli <[email protected]...>

src/openvpn/crypto.c +5 -5
index 84ec436..dbd95a8 100644
@@ -406,17 +406,15 @@
     static const char error_prefix[] = "AEAD Decrypt error";
     struct packet_id_net pin = { 0 };
     struct key_ctx *ctx = &opt->key_ctx_bi.decrypt;
+    struct gc_arena gc;
+
+    gc_init(&gc);
 
     if (cipher_decrypt_verify_fail_exceeded(ctx))
     {
         CRYPT_DROP("Decryption failed verification limit reached.");
     }
 
-    int outlen;
-    struct gc_arena gc;
-
-    gc_init(&gc);
-
     ASSERT(opt);
     ASSERT(frame);
     ASSERT(buf->len > 0);
@@ -506,6 +504,8 @@
     dmsg(D_PACKET_CONTENT, "DECRYPT AD: %s",
          format_hex(ad_start, ad_size, 0, &gc));
 
+    int outlen;
+
     /* Decrypt and authenticate packet */
     if (!cipher_ctx_update(ctx->cipher, BPTR(&work), &outlen, BPTR(buf),
                            data_len))
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: Fix 'uninitialized pointer read' in openvpn_decrypt_aead

"Obviously correct" :-) - not tested further (Coverity found this and will tell us if it considers the code fixed now).

Note that this has a very limited impact - only if running very recent master, and only if receiving more than 2^36 packets that can not be decrypted - then we might crash due to free()ing an uninitialized pointer.

Your patch has been applied to the master branch.

commit 5e086c08f2ce4428fd014b74441f0197a71d6da8

Author: Frank Lichtenheld
Date:   Mon Jan 13 12:22:26 2025 +0100
     Fix 'uninitialized pointer read' in openvpn_decrypt_aead

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Antonio Quartulli <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg30421.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#5 lore raw

[Openvpn-devel] [S] Change in openvpn[master]: Fix 'uninitialized pointer read' in openvpn_decrypt_aead

In reply to a message not in the archive

cron2 has uploaded a new patch set (#2) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/858?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by ordex

Change subject: Fix 'uninitialized pointer read' in openvpn_decrypt_aead
......................................................................

Fix 'uninitialized pointer read' in openvpn_decrypt_aead

Coverity complains that if we error out in the first error condition we try to free gc without initializing it.

While here move the declaration of outlen to the first usage.

Change-Id I0391f30a1e962ee242e9bcdec4f605bf7e831cca

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30421.html

---
M src/openvpn/crypto.c

1 file changed, 5 insertions(+), 5 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/58/858/2

src/openvpn/crypto.c +5 -5
index 84ec436..dbd95a8 100644
@@ -406,17 +406,15 @@
     static const char error_prefix[] = "AEAD Decrypt error";
     struct packet_id_net pin = { 0 };
     struct key_ctx *ctx = &opt->key_ctx_bi.decrypt;
+    struct gc_arena gc;
+
+    gc_init(&gc);
 
     if (cipher_decrypt_verify_fail_exceeded(ctx))
     {
         CRYPT_DROP("Decryption failed verification limit reached.");
     }
 
-    int outlen;
-    struct gc_arena gc;
-
-    gc_init(&gc);
-
     ASSERT(opt);
     ASSERT(frame);
     ASSERT(buf->len > 0);
@@ -506,6 +504,8 @@
     dmsg(D_PACKET_CONTENT, "DECRYPT AD: %s",
          format_hex(ad_start, ad_size, 0, &gc));
 
+    int outlen;
+
     /* Decrypt and authenticate packet */
     if (!cipher_ctx_update(ctx->cipher, BPTR(&work), &outlen, BPTR(buf),
                            data_len))

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/858?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I0391f30a1e962ee242e9bcdec4f605bf7e831cca
Gerrit-Change-Number: 858
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset

#6 lore raw

[Openvpn-devel] [S] Change in openvpn[master]: Fix 'uninitialized pointer read' in openvpn_decrypt_aead

In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/858?usp=email )

Change subject: Fix 'uninitialized pointer read' in openvpn_decrypt_aead
......................................................................

Fix 'uninitialized pointer read' in openvpn_decrypt_aead

Coverity complains that if we error out in the first error condition we try to free gc without initializing it.

While here move the declaration of outlen to the first usage.

Change-Id I0391f30a1e962ee242e9bcdec4f605bf7e831cca

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30421.html

---
M src/openvpn/crypto.c

1 file changed, 5 insertions(+), 5 deletions(-)
src/openvpn/crypto.c +5 -5
index 84ec436..dbd95a8 100644
@@ -406,17 +406,15 @@
     static const char error_prefix[] = "AEAD Decrypt error";
     struct packet_id_net pin = { 0 };
     struct key_ctx *ctx = &opt->key_ctx_bi.decrypt;
+    struct gc_arena gc;
+
+    gc_init(&gc);
 
     if (cipher_decrypt_verify_fail_exceeded(ctx))
     {
         CRYPT_DROP("Decryption failed verification limit reached.");
     }
 
-    int outlen;
-    struct gc_arena gc;
-
-    gc_init(&gc);
-
     ASSERT(opt);
     ASSERT(frame);
     ASSERT(buf->len > 0);
@@ -506,6 +504,8 @@
     dmsg(D_PACKET_CONTENT, "DECRYPT AD: %s",
          format_hex(ad_start, ad_size, 0, &gc));
 
+    int outlen;
+
     /* Decrypt and authenticate packet */
     if (!cipher_ctx_update(ctx->cipher, BPTR(&work), &outlen, BPTR(buf),
                            data_len))

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/858?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I0391f30a1e962ee242e9bcdec4f605bf7e831cca
Gerrit-Change-Number: 858
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged