From: "its_Giaan (Code Review)" Date: Tue, 4 Nov 2025 15:58:31 +0000 References: Reply-To: gianmarco@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="JsF5tvvXQiY="; charset=UTF-8 Subject: [Openvpn-devel] [XS] Change in openvpn[master]: mudp: fix unaligned 32-bit read when parsing peer ID List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --JsF5tvvXQiY= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1348?usp=3Demail to review the following change. Change subject: mudp: fix unaligned 32-bit read when parsing peer ID ...................................................................... mudp: fix unaligned 32-bit read when parsing peer ID The code previously read a 32-bit value from a uint8_t buffer using a direct cast and dereference. This can cause unaligned memory access and undefined behavior on architectures that do not support unaligned reads, potentially leading to a one-packet crash. This patch replaces the unsafe cast with a safe memcpy-based read. Reported-By: Joshua Rogers Found-By: ZeroPath (https://zeropath.com) Change-Id: Id0bb4c45d373437ab8dbaff7a311745f9b538cbf Signed-off-by: Gianmarco De Gregori --- M src/openvpn/mudp.c 1 file changed, 3 insertions(+), 1 deletion(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/48/1348/1 diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c index 31134be..0653b219 100644 --- a/src/openvpn/mudp.c +++ b/src/openvpn/mudp.c @@ -209,7 +209,9 @@ /* make sure buffer has enough length to read opcode (1 byte) and = peer-id (3 bytes) */ if (v2) { - uint32_t peer_id =3D ntohl(*(uint32_t *)ptr) & 0xFFFFFF; + uint32_t tmp; + memcpy(&tmp, ptr, sizeof(tmp)); + uint32_t peer_id =3D ntohl(tmp) & 0xFFFFFF; peer_id_disabled =3D (peer_id =3D=3D MAX_PEER_ID); if (!peer_id_disabled && (peer_id < m->max_clients) && (m->ins= tances[peer_id])) -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1348?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Id0bb4c45d373437ab8dbaff7a311745f9b538cbf Gerrit-Change-Number: 1348 Gerrit-PatchSet: 1 Gerrit-Owner: its_Giaan Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld --JsF5tvvXQiY= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: flichtenheld, plaisthos.

its_Giaan would like plaisthos and flichtenheld to review this change.

V= iew Change

mudp: fix unaligned 32-bit read when parsin=
g peer ID

The code previously read a 32-bit value from a uint8_t
= buffer using a direct cast and dereference.
This can cause unaligned mem= ory access and undefined
behavior on architectures that do not support u= naligned
reads, potentially leading to a one-packet crash.

This p= atch replaces the unsafe cast with a safe
memcpy-based read.

Repo= rted-By: Joshua Rogers <contact@...2949...>
Found-By: ZeroPath (ht= tps://zeropath.com)

Change-Id: Id0bb4c45d373437ab8dbaff7a311745f9b53= 8cbf
Signed-off-by: Gianmarco De Gregori <gianmarco@...2726...>---
M src/openvpn/mudp.c
1 file changed, 3 insertions(+), 1 deletion= (-)

git pull ssh://gerrit.openvpn.net:29418/open=
vpn refs/changes/48/1348/1
diff --git a/src/openvpn/mudp.c b/src/op=
envpn/mudp.c
index 31134be..0653b219 100644
--- a/src/openvpn/mudp.c
+++ b/src/openvpn/mudp.c@@ -209,7 +209,9 @@
/* make sure buffer ha= s enough length to read opcode (1 byte) and peer-id (3 bytes) */
= if (v2)
{
- uint32_t peer_id =3D ntohl(*(uint32= _t *)ptr) & 0xFFFFFF;
+ uint32_t tmp;
+ memcpy(&tmp, ptr, sizeof(tmp));
+ uint32_t peer_id =3D nt= ohl(tmp) & 0xFFFFFF;
peer_id_disabled =3D = (peer_id =3D=3D MAX_PEER_ID);

= if (!peer_id_disabled && (peer_id < m->max_clients) &&a= mp; (m->instances[peer_id]))

To view= , visit = change 1348. To unsubscribe, or for help writing mail filters, visit settings.

<= div itemscope itemtype=3D"http://schema.org/EmailMessage">
<= meta itemprop=3D"name" content=3D"View Change"/>
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id0bb4c45d373437ab8dbaff7a31= 1745f9b538cbf
Gerrit-Change-Number: 1348
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <gianmarco@...2786...= ..>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
= --JsF5tvvXQiY=--