Skip to contentSkip to conversation

Fix logic error in checking early negotiation support check

PATCH In review Arne Schwabe 3 participants 5 messages Nov 15, 2022 – Nov 16, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix logic error in checking early negotiation support check

We want to check if EARLY_NEG_START is set and reserve the other bits for future expansions. Right now we also check if all reserved bits are zero. oops.

---
 src/openvpn/mudp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/mudp.c +1 -1
index 7c6fc816e..bdf35a8ba 100644
@@ -92,7 +92,7 @@ do_pre_decrypt_check(struct multi_context *m,
         ASSERT(packet_id_read(&pin, &tmp, true));
 
         /* The most significant byte is 0x0f if early negotiation is supported */
-        bool early_neg_support = (pin.id & EARLY_NEG_MASK) == EARLY_NEG_START;
+        bool early_neg_support = ((pin.id & EARLY_NEG_MASK) & EARLY_NEG_START) == EARLY_NEG_START;
 
         /* All clients that support early negotiation and tls-crypt are assumed
          * to also support resending the WKc in the 2nd packet */
Signature · 1 line
2.37.0 (Apple Git-136)
#1 lore raw

Hi,

Quoted 14 lines · Arne Schwabe

We want to check if EARLY_NEG_START is set and reserve the other bits for future expansions. Right now we also check if all reserved bits are zero. oops.

---
  src/openvpn/mudp.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/mudp.c +0 -0
index 7c6fc816e..bdf35a8ba 100644

src/openvpn/mudp.c do_pre_decrypt_check(struct multi_context *m, · line 95

Quoted 5 lines
src/openvpn/mudp.c +1 -1
@@ -92,7 +92,7 @@ do_pre_decrypt_check(struct multi_context *m,
          ASSERT(packet_id_read(&pin, &tmp, true));
 
          /* The most significant byte is 0x0f if early negotiation is supported */
-        bool early_neg_support = (pin.id & EARLY_NEG_MASK) == EARLY_NEG_START;
+        bool early_neg_support = ((pin.id & EARLY_NEG_MASK) & EARLY_NEG_START) == EARLY_NEG_START;

The "== EARLY_NEG_START" is not needed.

On top of that, my brain parses the expression easier without that part, because the question is "after filtering using the mask, is EARLY_NEG_START set?". The "==" imho adds logic which is not needed (both at the code and at the brain level).

Cheers,

Quoted 3 lines
src/openvpn/mudp.c +0 -0
          /* All clients that support early negotiation and tls-crypt are assumed
           * to also support resending the WKc in the 2nd packet */
Signature · 1 line
Antonio Quartulli
#2 lore raw

Am 15.11.2022 um 13:36 schrieb Antonio Quartulli:

Quoted 28 lines

Hi,

Quoted 14 lines · Arne Schwabe

We want to check if EARLY_NEG_START is set and reserve the other bits for future expansions. Right now we also check if all reserved bits are zero. oops.

---
  src/openvpn/mudp.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/mudp.c +0 -0
index 7c6fc816e..bdf35a8ba 100644

src/openvpn/mudp.c do_pre_decrypt_check(struct multi_context *m, · line 96

Quoted 6 lines
src/openvpn/mudp.c +1 -1
@@ -92,7 +92,7 @@ do_pre_decrypt_check(struct multi_context *m,
           ASSERT(packet_id_read(&pin, &tmp, true));
             /* The most significant byte is 0x0f if early negotiation is supported */
-        bool early_neg_support = (pin.id & EARLY_NEG_MASK) == 
 EARLY_NEG_START;
+        bool early_neg_support = ((pin.id & EARLY_NEG_MASK) & 
 EARLY_NEG_START) == EARLY_NEG_START;

The "== EARLY_NEG_START" is not needed.

Quoted 2 lines

On top of that, my brain parses the expression easier without that part, because the question is "after filtering using the mask, is EARLY_NEG_START set?". The "==" imho adds logic which is not needed (both at the code and at the brain level).

Without the == it is enough if any of the bits EARLY_NEG_START is set (0xf00000), we want them all to be set. If EARLY_NEG_START were a flag/single bit, you would be right.

Arne

Acked-by on v1 1/1
#4 lore raw
In reply to Arne Schwabe

The discussion in the mail thread and on IRC explains why we need to check the full EARLY_NEG_START value (because it's "0x0f" in the topmost byte, not "just one bit set"). This is because it was done that way initially, and now it is what it is... so what this patch adds is "ignore the uppermost 4 bits in comparison, should we want to use these 4 bits for protocol extention in the future".

Arguably one could just do "(pin.id & EARLY_NEG_START) == EARLY_NEG_START" here, but maybe this way it's clear what is being looked at.

Only compile tested.

Your patch has been applied to the master branch.

commit 543f709f13bca9887cabd4545554539f18346e3c

Author: Arne Schwabe
Date:   Tue Nov 15 13:29:40 2022 +0100
     Fix logic error in checking early negotiation support check

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg25519.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#3 lore raw
In reply to Arne Schwabe

Hi,

Quoted 1 line · Arne Schwabe

Without the == it is enough if any of the bits EARLY_NEG_START is set (0xf00000), we want them all to be set. If EARLY_NEG_START were a flag/single bit, you would be right.

Ouch, I indeed assumed it was 1 bit only..

Cheers,

Signature · 1 line
Antonio Quartulli