From: "flichtenheld (Code Review)" Date: Wed, 11 Dec 2024 16:28:32 +0000 In-Reply-To: References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, gert@...1296... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="S93O42R2AD8="; 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 , cron2 Cc: openvpn-devel --S93O42R2AD8= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, flichtenheld, plaisthos. Hello cron2, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/827?usp=3Demail to look at the new patch set (#2). The following approvals got outdated and were removed: Code-Review-1 by cron2 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 v2: Use memcmp instead of memcpy Change-Id: I74a9eec4954f3f9d208792b6b34357571f76ae4c Signed-off-by: Frank Lichtenheld --- M src/openvpn/forward.c M src/openvpn/proto.h 2 files changed, 11 insertions(+), 8 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/27/827/2 diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index d50b24c..2c72001 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,16 @@ return; } - pip =3D (struct openvpn_iphdr *) (BPTR(buf) + ip_hdr_offset); + struct openvpn_iphdr *pip =3D (struct openvpn_iphdr *) (BPTR(buf) = + ip_hdr_offset); /* drop packets with same dest addr as gateway */ - if (tun_sa.addr.in4.sin_addr.s_addr =3D=3D pip->daddr) + if (memcmp(&tun_sa.addr.in4.sin_addr.s_addr, &pip->daddr, sizeof(p= ip->daddr)) =3D=3D 0) { 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 +1424,10 @@ return; } + struct openvpn_ipv6hdr *pip6 =3D (struct openvpn_ipv6hdr *) (BPTR(= buf) + ip_hdr_offset); + /* 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 (OPENVPN_IN6_ARE_ADDR_EQUAL(&tun_sa.addr.in6.sin6_addr, &pip6->= daddr)) { drop =3D true; } diff --git a/src/openvpn/proto.h b/src/openvpn/proto.h index 7b94fbc..00c4e55 100644 --- a/src/openvpn/proto.h +++ b/src/openvpn/proto.h @@ -83,6 +83,12 @@ #define SIZE_ETH_TO_8021Q_HDR (sizeof(struct openvpn_8021qhdr) \ - sizeof(struct openvpn_ethhdr)) +/** Version of IN6_ARE_ADDR_EQUAL that is guaranteed to work for + unaligned access. E.g. Linux uses 32bit compares which are + not safe if the struct is unaligned. */ +#define OPENVPN_IN6_ARE_ADDR_EQUAL(a, b) \ + (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) = =3D=3D 0) + struct openvpn_iphdr { #define OPENVPN_IPH_GET_VER(v) (((v) >> 4) & 0x0F) #define OPENVPN_IPH_GET_LEN(v) (((v) & 0x0F) << 2) -- 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: 2 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: cron2 Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --S93O42R2AD8= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: cron2, flichtenheld, plaisthos. <= /p>

flichtenheld uploaded patch set #2 to this change.

<= p>View Ch= ange

The following approvals got outdated and were removed: Code-Review-1 by cron2

forward: Fix potential unaligned access in drop_if_r=
ecursive_routing

ASAN error:
forward.c:1433:13: runtime error: me= mber access within
misaligned address 0x51e00002f52e for type
'co= nst struct in6_addr', which requires 4 byte alignment

v2: Use me= mcmp instead of memcpy

Change-Id: I74a9eec4954f3f9d208792b6b34357571= f76ae4c
Signed-off-by: Frank Lichtenheld <frank@...2641...>
---=
M src/openvpn/forward.c
M src/openvpn/proto.h
2 files changed, 11= insertions(+), 8 deletions(-)

git pull ssh://gerrit.openvpn.net:=
29418/openvpn refs/changes/27/827/2
diff --git a/src/openvpn/forwar=
d.c b/src/openvpn/forward.c
index d50b24c..2c72001 100644
--- a/src/openvpn/forward.c
+++ b/src/openvp= n/forward.c
@@ -1390,8 +1390,6 @@
<= br> 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_offset))
{
@@ -1404,18 +1402,16 @@
return;

}

- pip =3D (struct ope= nvpn_iphdr *) (BPTR(buf) + ip_hdr_offset);
+ struct openvpn_iphdr *pip =3D (struct openvp= n_iphdr *) (BPTR(buf) + ip_hdr_offset);

= /* drop packets with same dest addr as gateway */
- if (tun_sa.addr.in4.sin_addr.s_= addr =3D=3D pip->daddr)
+ if (memcmp(&tun_sa.addr.in4.sin_addr.s_addr, &pip-&g= t;daddr, sizeof(pip->daddr)) =3D=3D 0)
{=
drop =3D true;
}
= }
else if (proto_ver =3D=3D 6)
{

- con= st struct openvpn_ipv6hdr *pip6;
-
/* make sure we got whole IPv6 header = */
if (BLEN(buf) < ((int) sizeof(struct openvpn= _ipv6hdr) + ip_hdr_offset))
{
@@ -= 1428,9 +1424,10 @@
return;
= }

+ struct openvpn_ipv6hdr *pip6 =3D (struct openvpn_ipv6hdr *) (= BPTR(buf) + ip_hdr_offset);
+
/* drop packets with same dest addr as ga= teway */
- pip6 = =3D (struct openvpn_ipv6hdr *) (BPTR(buf) + ip_hdr_offset);
- if (IN6_ARE_ADDR_EQUAL(&t= un_sa.addr.in6.sin6_addr, &pip6->daddr))
+ if (OPENVPN_IN6_ARE_ADDR_EQUAL(&tun= _sa.addr.in6.sin6_addr, &pip6->daddr))
{
drop =3D true;
}=
diff --git a/src/openvpn/proto.h b/src/openvpn/proto.h
= index 7b94fbc..00c4e55 100644
--- a/src/openvpn/proto= .h
+++ b/src/openvpn/proto.h
@@ -83,6 +83,1= 2 @@
#define SIZE_ETH_TO_8021Q_HDR (sizeof(struct openvpn_= 8021qhdr) \
- sizeof(struct= openvpn_ethhdr))

+/** Version of IN6_ARE_ADDR_EQUAL that is guaranteed to wor= k for
+ unaligned = access. E.g. Linux uses 32bit compares which are
+ not safe if the struct is unaligned. */
+#define OPENVPN_IN6_AR= E_ADDR_EQUAL(a, b) \
= + (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struc= t in6_addr)) =3D=3D 0)
change 827. To unsubscribe, or for help writing mail f= ilters, visit settings.<= /p>
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I74a9eec4954f3f9d208792b6b34= 357571f76ae4c
Gerrit-Change-Number: 827
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
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: cron2 <gert@...1296...>= ;
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newpatchset
--S93O42R2AD8=--