On Sun, Apr 16, 2017 at 05:06:20PM +0200, Stefan Sperling wrote:
> On Sun, Apr 16, 2017 at 04:26:51PM +0200, Stefan Sperling wrote:
> > An openvpn server running on OpenBSD/sparc64 6.1 crashes when a client
> > connects and starts doing traffic. Is anyone else seeing this?
> > 
> > (gdb) run
> > Starting program: /usr/local/sbin/openvpn /etc/openvpn/server.conf
> > (no debugging symbols found)
> > 
> > Program received signal SIGBUS, Bus error.
> > 0x000000a99df82664 in write_tun_header () from /usr/local/sbin/openvpn
> > (gdb) bt
> > #0  0x000000a99df82664 in write_tun_header () from /usr/local/sbin/openvpn
> > #1  0x000000a99df136d4 in process_outgoing_tun () from 
> > /usr/local/sbin/openvpn
> > #2  0x000000a99df31094 in tunnel_server_udp () from /usr/local/sbin/openvpn
> > #3  0x000000a99df3a6ac in main () from /usr/local/sbin/openvpn
> > 
> 
> The happens because of a cast from an unaligned u_int8_t * to struct ip *.
> The diff below fixes the crash. This fix exploits the fact that this code
> is just looking for the IP header version, which will always sit in the
> first nibble of the buffer.
> 
> Alternatives would be a memcpy() to a local struct ip (less efficient),
> or making sure that the buffer pointer is always aligned (more effort
> and larger diff).
> 
> Is this ok as a quick fix?
 
Ignore my previous diff. It breaks inet6 across the VPN.
Obviously I am not smarter than memcpy() so let's just use that.

Index: Makefile
===================================================================
RCS file: /cvs/ports/net/openvpn/Makefile,v
retrieving revision 1.73
diff -u -p -r1.73 Makefile
--- Makefile    28 Mar 2017 22:16:37 -0000      1.73
+++ Makefile    16 Apr 2017 14:51:26 -0000
@@ -3,6 +3,7 @@
 COMMENT=       easy-to-use, robust, and highly configurable VPN
 
 DISTNAME=      openvpn-2.4.1
+REVISION=      0
 CATEGORIES=    net security
 
 HOMEPAGE=      https://openvpn.net/index.php/open-source/
Index: patches/patch-src_openvpn_tun_c
===================================================================
RCS file: /cvs/ports/net/openvpn/patches/patch-src_openvpn_tun_c,v
retrieving revision 1.12
diff -u -p -r1.12 patch-src_openvpn_tun_c
--- patches/patch-src_openvpn_tun_c     28 Mar 2017 22:16:37 -0000      1.12
+++ patches/patch-src_openvpn_tun_c     16 Apr 2017 15:39:20 -0000
@@ -1,9 +1,10 @@
 $OpenBSD: patch-src_openvpn_tun_c,v 1.12 2017/03/28 22:16:37 jca Exp $
 
 - no need for link0 any more, we have separate tap interfaces
+- fix bus error in write_tun_header() due to misaligned access
 
 --- src/openvpn/tun.c.orig     Wed Mar 22 16:34:21 2017
-+++ src/openvpn/tun.c  Mon Mar 27 06:01:57 2017
++++ src/openvpn/tun.c  Sun Apr 16 17:36:51 2017
 @@ -1201,7 +1201,7 @@ do_ifconfig(struct tuntap *tt,
          if (tun)
          {
@@ -37,3 +38,18 @@ $OpenBSD: patch-src_openvpn_tun_c,v 1.12
                          IFCONFIG_PATH,
                          actual,
                          ifconfig_local,
+@@ -1654,11 +1659,11 @@ write_tun_header(struct tuntap *tt, uint8_t *buf, int 
+     {
+         u_int32_t type;
+         struct iovec iv[2];
+-        struct ip *iph;
++        struct ip iph;
+ 
+-        iph = (struct ip *) buf;
++        memcpy(&iph, buf, sizeof(iph));
+ 
+-        if (iph->ip_v == 6)
++        if (iph.ip_v == 6)
+         {
+             type = htonl(AF_INET6);
+         }

Reply via email to