[Openvpn-devel,v2] multi: don't let compression corrupt queued broadcast packets

Message ID 20261201142809.30808-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v2] multi: don't let compression corrupt queued broadcast packets |

Commit Message

Gert Doering Dec. 1, 2026, 2:28 p.m. UTC
  From: Razvan Cojocaru <razvanc@mailbox.org>

A broadcast or multicast packet is queued once and shared by all
recipients. With compress, compress stub or compress lz4 the byte swap
framing rewrites the packet in place, so every recipient after the
first got it with its first byte replaced by 0xFB. In TAP mode this
broke ARP and DHCP broadcasts for all clients but one. In TUN mode the
client's kernel rejected the packet, logged as "write to TUN/TAP:
Invalid argument".

When the recipient uses the byte swap, copy a buffer that is still
queued for other recipients before handing it to encrypt_sign().

GitHub: closes OpenVPN/openvpn#461
Change-Id: I8d424804372707a23fdc6fe77163cffabf72ea00
Signed-off-by: Razvan Cojocaru <razvanc@mailbox.org>
Acked-by: Antonio Quartulli <antonio@mandelbit.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2377
---

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/+/2377
This mail reflects revision 2 of this Change.

Acked-by according to Gerrit (reflected above):
Antonio Quartulli <antonio@mandelbit.com>
  

Patch

diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c
index 900b5a3..a71a484 100644
--- a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c
@@ -3757,6 +3757,20 @@ 
     {
         unsigned int pip_flags = PIPV4_PASSTOS | PIPV6_ICMP_NOHOST_SERVER;
 
+#ifdef USE_COMP
+        /* the compression byte swap changes the packet in place, so
+         * don't let it touch a buffer that other recipients still have
+         * queued */
+        const struct compress_context *comp = item.instance->context.c2.comp_context;
+        if (item.buffer->refcount > 1 && comp && (comp->flags & COMP_F_SWAP))
+        {
+            struct mbuf_buffer *mb = mbuf_alloc_buf(&item.buffer->buf);
+            mb->flags = item.buffer->flags;
+            mbuf_free_buf(item.buffer);
+            item.buffer = mb;
+        }
+#endif
+
         set_prefix(item.instance);
         item.instance->context.c2.buf = item.buffer->buf;
         if (item.buffer->flags