From: "flichtenheld (Code Review)" Date: Tue, 10 Dec 2024 11:44:34 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="dYMm88Tb4F0="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: forward: Fix potential unaligned access in drop_if_recursive_routing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --dYMm88Tb4F0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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/+/827?usp=3Demail to review the following change. Change subject: forward: Fix potential unaligned access in drop_if_recursiv= e_routing ...................................................................... forward: Fix potential unaligned access in drop_if_recursive_routing ASAN error: forward.c:1433:13: runtime error: member access within misaligned address 0x51e00002f52e for type 'const struct in6_addr', which requires 4 byte alignment Change-Id: I74a9eec4954f3f9d208792b6b34357571f76ae4c Signed-off-by: Frank Lichtenheld --- M src/openvpn/forward.c 1 file changed, 7 insertions(+), 8 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/27/827/1 diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index d50b24c..4ba7448 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -1390,8 +1390,6 @@ if (proto_ver =3D=3D 4) { - const struct openvpn_iphdr *pip; - /* make sure we got whole IP header */ if (BLEN(buf) < ((int) sizeof(struct openvpn_iphdr) + ip_hdr_offse= t)) { @@ -1404,18 +1402,17 @@ return; } - pip =3D (struct openvpn_iphdr *) (BPTR(buf) + ip_hdr_offset); + struct openvpn_iphdr pip; + memcpy(&pip, BPTR(buf) + ip_hdr_offset, sizeof(struct openvpn_iphd= r)); /* drop packets with same dest addr as gateway */ - if (tun_sa.addr.in4.sin_addr.s_addr =3D=3D pip->daddr) + if (tun_sa.addr.in4.sin_addr.s_addr =3D=3D pip.daddr) { drop =3D true; } } else if (proto_ver =3D=3D 6) { - const struct openvpn_ipv6hdr *pip6; - /* make sure we got whole IPv6 header */ if (BLEN(buf) < ((int) sizeof(struct openvpn_ipv6hdr) + ip_hdr_off= set)) { @@ -1428,9 +1425,11 @@ return; } + struct openvpn_ipv6hdr pip6; + memcpy(&pip6, BPTR(buf) + ip_hdr_offset, sizeof(struct openvpn_ipv= 6hdr)); + /* drop packets with same dest addr as gateway */ - pip6 =3D (struct openvpn_ipv6hdr *) (BPTR(buf) + ip_hdr_offset); - if (IN6_ARE_ADDR_EQUAL(&tun_sa.addr.in6.sin6_addr, &pip6->daddr)) + if (IN6_ARE_ADDR_EQUAL(&tun_sa.addr.in6.sin6_addr, &pip6.daddr)) { drop =3D true; } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/827?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I74a9eec4954f3f9d208792b6b34357571f76ae4c Gerrit-Change-Number: 827 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-MessageType: newchange --dYMm88Tb4F0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: plaisthos.

flichtenheld would like plaisthos to review this change.

Vi= ew Change

forward: Fix potential unaligned access in drop_if_recursive_=
routing

ASAN error:
forward.c:1433:13: runtime error: member acce= ss within
misaligned address 0x51e00002f52e for type
'const struc= t in6_addr', which requires 4 byte alignment

Change-Id: I74a9eec= 4954f3f9d208792b6b34357571f76ae4c
Signed-off-by: Frank Lichtenheld <f= rank@...2641...>
---
M src/openvpn/forward.c
1 file changed, 7 = insertions(+), 8 deletions(-)

git pull ssh://gerrit.openvpn.net:2=
9418/openvpn refs/changes/27/827/1
diff --git a/src/openvpn/forward=
.c b/src/openvpn/forward.c
index d50b24c..4ba7448 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn= /forward.c
@@ -1390,8 +1390,6 @@
if (proto_ver =3D=3D 4)
{
- const struct openvpn_iphdr *p= ip;

-
= /* make sure we got whole IP header */
if = (BLEN(buf) < ((int) sizeof(struct openvpn_iphdr) + ip_hdr_offset))
{
@@ -1404,18 +1402,17 @@
return;

}
=
- pip =3D (struct open= vpn_iphdr *) (BPTR(buf) + ip_hdr_offset);
+ struct openvpn_iphdr pip;
+ memcpy(&pip, BPTR(buf) + ip= _hdr_offset, sizeof(struct openvpn_iphdr));

/* drop packets with same dest addr as gateway */
- if (tun_sa.addr.in4.sin_add= r.s_addr =3D=3D pip->daddr)
+ if (tun_sa.addr.in4.sin_addr.s_addr =3D=3D pip.daddr)
{
drop =3D true;=
}
}
else if (p= roto_ver =3D=3D 6)
{
- const struct openvpn_ipv6hdr *pip6;
<= span style=3D"color: hsl(0, 100%, 40%);">-

/* make= sure we got whole IPv6 header */
if (BLEN(buf) &l= t; ((int) sizeof(struct openvpn_ipv6hdr) + ip_hdr_offset))
= {
@@ -1428,9 +1425,11 @@
= return;
}

+ struct openvpn_ipv6hdr pip6;
+ memcpy(&p= ip6, BPTR(buf) + ip_hdr_offset, sizeof(struct openvpn_ipv6hdr));
= +
/* d= rop packets with same dest addr as gateway */
- pip6 =3D (struct openvpn_ipv6hdr *) (BPTR(b= uf) + ip_hdr_offset);
-= if (IN6_ARE_ADDR_EQUAL(&tun_sa.addr.in6.sin6_addr, &pip6-&g= t;daddr))
+ if= (IN6_ARE_ADDR_EQUAL(&tun_sa.addr.in6.sin6_addr, &pip6.daddr))
{
drop =3D true; }

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

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I74a9eec4954f3f9d208792b6b34= 357571f76ae4c
Gerrit-Change-Number: 827
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <frank@...2723...= .>
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-MessageType: newchange
--dYMm88Tb4F0=--