Core dump ("unaligned access") on OpenBSD3.5 (DS10 - Alpha arch)
Hi
I'm trying to setup an OpenVPN server on a Comapq DS10 box. The DS10 is Alph architecture, and running OpenBSD 3.5 for Alpha. I'm using OpenVPN 2.0 rc4, both on client and server.
*******************
Problem Description
*******************
I've compiled OpenVPN 2.0 rc4 (server) on the DS10 with the following versions of gcc and OpenSSL:
gcc 2.95.3
OpenSSL 0.9.7c
The client is running Windows XP and OpenVPN 2.0 rc4.
I can connect each endpoint, but when I try to ping either endpoint of the vpn tunnel, the OpenVPN server dumps core and dies:
pid 17868 (openvpn): unaligned access: va=0x12012f82f pc=0x120023900 ra=0x1200238f4 op=ldl
Bus error (core dumped)
Using gdb, I find:
# gdb /usr/local/sbin/openvpn openvpn.core GNU gdb 4.16.1 ... This GDB was configured as "alpha-unknown-openbsd3.5"... Core was generated by `openvpn'.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Program terminated with signal 10, Bus error.
#0 0x120023904 in mroute_extract_addr_from_packet (src=0x1ffffb220, dest=0x1ffffb208, buf=0x1, tunnel_type=-20292) at mroute.c:113
113 memcpy (src->addr, &ip->saddr, 4);
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
I think my system choke on the 'ip->saddr' address in the memcpy statement.
Question:
---------
Any idea if I can change anything in the openvpn source to fix this ?
Thanks
Christian
**********************
SERVER AND CLIENT LOGS
**********************
Server startup:
---------------
Thu Dec 16 12:23:57 2004 OpenVPN 2.0_rc4 alpha-unknown-openbsd3.5 [SSL] built on Dec 16 2004
Thu Dec 16 12:23:57 2004 IMPORTANT: OpenVPN's default port number is now 1194, based on an official port number assignment by IANA.
OpenVPN 2.0-beta16 and earlier used 5000 as the default port.
Thu Dec 16 12:23:57 2004 gw 192.168.1.3
Thu Dec 16 12:23:57 2004 /sbin/ifconfig tun1 destroy
Thu Dec 16 12:23:57 2004 /sbin/ifconfig tun1 create
Thu Dec 16 12:23:57 2004 NOTE: Tried to delete pre-existing tun/tap instance
Signature · 98 lines
No Problem if failure
Thu Dec 16 12:23:57 2004 /sbin/ifconfig tun1 10.1.0.1 10.1.0.2 mtu 1500
netmask 255.255.255.255 up
Thu Dec 16 12:23:57 2004 TUN/TAP device /dev/tun1 opened
add net 10.1.0.0: gateway 10.1.0.2
Thu Dec 16 12:23:57 2004 Listening for incoming TCP connection on [undef]:1194
Thu Dec 16 12:23:57 2004 TCPv4_SERVER link local (bound): [undef]:1194
Thu Dec 16 12:23:57 2004 TCPv4_SERVER link remote: [undef]
Thu Dec 16 12:23:57 2004 Initialization Sequence Completed
Client Startup:
---------------
Thu Dec 16 10:45:18 2004 OpenVPN 2.0_rc4 Win32-MinGW [SSL] [LZO] built on Dec
14 2004
Thu Dec 16 10:45:18 2004 IMPORTANT: OpenVPN's default port number is now 1194,
based on an official port number assignment by IANA. OpenVPN 2.0-beta16 and
earlier used 5000 as the default port.
Thu Dec 16 10:45:18 2004 WARNING: No server certificate verification method
has been enabled.
See http://openvpn.sourceforge.net/howto.html#mitm for more info.
Enter Private Key Password:
Thu Dec 16 10:45:22 2004 Attempting to establish TCP connection with
<vpnserver>:1194
Thu Dec 16 10:45:22 2004 TCP connection established with <vpnserver>:1194
Thu Dec 16 10:45:22 2004 TCPv4_CLIENT link local: [undef]
Thu Dec 16 10:45:22 2004 TCPv4_CLIENT link remote: <vpnserver>:1194
Thu Dec 16 10:45:25 2004 [<vpnserver>] Peer Connection Initiated with
<vpnserver>:1194
Thu Dec 16 10:45:26 2004 TAP-WIN32 device [Local Area Connection 2]
opened: \\.\Global\{F9DD4E44-5C85-4662-A35E-A45E7E515A41}.tap
Thu Dec 16 10:45:26 2004 Notified TAP-Win32 driver to set a DHCP IP/netmask of
10.1.0.6/255.255.255.
252 on interface {F9DD4E44-5C85-4662-A35E-A45E7E515A41} [DHCP-serv: 10.1.0.5,
lease-time: 31536000]
Thu Dec 16 10:45:26 2004 Successful ARP Flush on interface [65540]
{F9DD4E44-5C85-4662-A35E-A45E7E51
5A41}
Thu Dec 16 10:45:31 2004 Initialization Sequence Completed
**************
CONFIGURATIONS
**************
#-------------
# server.cnf
#-------------
#
# Tunnel mode
dev tun1
# Run as a single instance server
mode server
proto tcp-server
# Server endpoint appears first, followed
# by the gateway interface ip
ifconfig 10.1.0.1 10.1.0.2
# Range of IP addresses reserved for clients
ifconfig-pool 10.1.0.4 10.1.0.254
# route setup on the server
route 10.1.0.0 255.255.255.0
# route command pushed to the client
push "route 10.1.0.1 255.255.255.255"
# Specify tls-server for certificate exchange
tls-server
# Diffie-Hellman Parameters (tls-server only)
dh /data/CA-DB/dh1024.pem
# Root certificate
ca /data/CA-DB/cacert.pem
# Server certificate
cert /data/CA-DB/vpncert.pem
# Server private key
key /data/CA-DB/vpnkey.pem
# Check for revoked client certificates.
crl-verify /data/CA-DB/crl/crl.pem
#-------------
# client.cfg
#-------------
#
# Set tunnel mode
dev tun
# Hostname for the VPN server
remote <vpnserver>
proto tcp-client
# This end takes the client role for
# certificate exchange
tls-client
# Certificate Authority file
ca cacert.pem
# Our certificate/public key
cert client2.pem
# Our private key
key client2key.pem
# Get the rest of our configuration
# from the server.
pullQuoted 34 lines · On Thu, 16 Dec 2004, Christian [iso-8859-1] Røsnes wrote:
Hi
I'm trying to setup an OpenVPN server on a Comapq DS10 box. The DS10 is Alph architecture, and running OpenBSD 3.5 for Alpha. I'm using OpenVPN 2.0 rc4, both on client and server.
*******************
Problem Description
*******************I've compiled OpenVPN 2.0 rc4 (server) on the DS10 with the following versions of gcc and OpenSSL:
gcc 2.95.3
OpenSSL 0.9.7cThe client is running Windows XP and OpenVPN 2.0 rc4.
I can connect each endpoint, but when I try to ping either endpoint of the vpn tunnel, the OpenVPN server dumps core and dies:
pid 17868 (openvpn): unaligned access: va=0x12012f82f pc=0x120023900 ra=0x1200238f4 op=ldl
Bus error (core dumped)Using gdb, I find:
# gdb /usr/local/sbin/openvpn openvpn.core GNU gdb 4.16.1 ... This GDB was configured as "alpha-unknown-openbsd3.5"... Core was generated by `openvpn'.Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 8 lines
Program terminated with signal 10, Bus error.
#00x120023904inmroute_extract_addr_from_packet(src=0x1ffffb220, dest=0x1ffffb208, buf=0x1, tunnel_type=-20292) at mroute.c:113
113 memcpy (src->addr,&ip->saddr, 4);Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
I think my system choke on the '
ip->saddr' address in the memcpy statement.
That's strange that it would hit an alignment fault on a memcpy. memcpy is supposed to operate at byte granularity. The whole reason I use memcpy here in the first place is to prevent alignment faults on the legacy processors that have trouble with them.
Now on the other hand if the compiler tried to optimize the memcpy into a 32 bit move instruction, then there will be problems because ip is not aligned correctly for that.
What assembly code is being generated for the memcpy?
Try, just as a test, compiling without optimization, and see if it affects the code generated for the memcpy.
James
A message that is not in the archive (sent off-list or not yet received): [email protected]...
Quoted 45 lines · On Thu, 16 Dec 2004, Christian [iso-8859-1] Røsnes wrote:
Quoted 37 lines · James Yonan
Quoted 24 lines · On Thu, 16 Dec 2004, Christian [iso-8859-1] Røsnes wrote:
I can connect each endpoint, but when I try to ping either endpoint of the vpn tunnel, the OpenVPN server dumps core and dies:
pid 17868 (openvpn): unaligned access: va=0x12012f82f pc=0x120023900 ra=0x1200238f4 op=ldl
Bus error (core dumped)Using gdb, I find:
# gdb /usr/local/sbin/openvpn openvpn.core GNU gdb 4.16.1 ... This GDB was configured as "alpha-unknown-openbsd3.5"... Core was generated by `openvpn'.Program terminated with signal 10, Bus error.
#00x120023904inmroute_extract_addr_from_packet(src=0x1ffffb220, dest=0x1ffffb208, buf=0x1, tunnel_type=-20292) at mroute.c:113
113 memcpy (src->addr,&ip->saddr, 4);Quoted 2 lines
I think my system choke on the '
ip->saddr' address in the memcpy statement.That's strange that it would hit an alignment fault on a memcpy. memcpy is supposed to operate at byte granularity. The whole reason I use memcpy here in the first place is to prevent alignment faults on the legacy processors that have trouble with them.
Now on the other hand if the compiler tried to optimize the memcpy into a 32 bit move instruction, then there will be problems because ip is not aligned correctly for that.
Quoted 6 lines
What assembly code is being generated for the memcpy?
Try, just as a test, compiling without optimization, and see if it affects the code generated for the memcpy.
James
Quoted 8 lines
Yes, removing -O2 from CFLAGS, and recompiling fixed the core dump problem when pinging (although I get no answer, but that is maybe something related to my configuration).
Then, setting -02 and recompiling after that brought the core dump back when pinging.So, the optimization seems to cause this somehow.
I'll leave -O2 off for now.
Building without optimization might be overkill. Try keeping -O2 on, but add -fno-builtin-memcpy to eliminate the inlining of memcpy.
See also this bug report which looks like an exact match to what your are seeing:
http://gcc.gnu.org/ml/gcc-bugs/2000-03/msg00155.html
It looks like it might be possible to work around the issue with the right intermediate casting in mroute.c.
James
Also, try the attached patch with a standard build, i.e. optimization turned on and no special flags like -fno-builtin-memcpy.
I would be curious if the cast-to-char changes the memcpy inlining behavior to prevent the alignment fault.
Thanks,
James
mroute.c +4 -4
@@ -109,14 +109,14 @@ src->type =MR_ADDR_IPV4 ; src->netbits =0 ; src->len =4 ; -memcpy (src->addr, &ip->saddr,4 ); +memcpy (src->addr, (uint8_t *)&ip->saddr,4 ); }if (dest) { dest->type =MR_ADDR_IPV4 ; dest->netbits =0 ; dest->len =4 ; -memcpy (dest->addr, &ip->daddr,4 ); +memcpy (dest->addr, (uint8_t *)&ip->daddr,4 );/* mcast address? */ if (((*(in_addr_t *)dest->addr) &htonl (IP_MCAST_SUBNET_MASK )) ==htonl (IP_MCAST_NETWORK ))
@@ -147,14 +147,14 @@ src->type =MR_ADDR_ETHER ; src->netbits =0 ; src->len =6 ; -memcpy (src->addr, eth->source,6 ); +memcpy (src->addr, (uint8_t *)eth->source,6 ); }if (dest) { dest->type =MR_ADDR_ETHER ; dest->netbits =0 ; dest->len =6 ; -memcpy (dest->addr, eth->dest,6 ); +memcpy (dest->addr, (uint8_t *)eth->dest,6 );/* ethernet broadcast/multicast packet? */ if (is_mac_mcast_addr (eth->dest))
* James Yonan:
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Program terminated with signal 10, Bus error.
#00x120023904inmroute_extract_addr_from_packet(src=0x1ffffb220, dest=0x1ffffb208, buf=0x1, tunnel_type=-20292) at mroute.c:113
113 memcpy (src->addr,&ip->saddr, 4);Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 4 lines
Quoted 1 line
I think my system choke on the '
ip->saddr' address in the memcpy statement.That's strange that it would hit an alignment fault on a memcpy. memcpy is supposed to operate at byte granularity.
I suspect this statement is the problem:
const struct openvpn_iphdr *ip = (const struct openvpn_iphdr *) BPTR (buf);
The cast results in undefined behavior if BPTR (buf) has the wrong alignment. Recent versions of GCC know this and therefore conclude that BPTR must be properly aligned. As a result, it is possible to replace memcpy() with something that copies word-wise.
The char * casts in your other message won't fix this, they come too late. It's a common misconception that char pointers behave like machine addresses. They don't.
Just to be clear, this is not a bug in GCC. Your code is not valid C.
Quoted 24 lines · Florian Weimer
* James Yonan:
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Program terminated with signal 10, Bus error.
#00x120023904inmroute_extract_addr_from_packet(src=0x1ffffb220, dest=0x1ffffb208, buf=0x1, tunnel_type=-20292) at mroute.c:113
113 memcpy (src->addr,&ip->saddr, 4);Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 4 lines
Quoted 1 line
I think my system choke on the '
ip->saddr' address in the memcpy statement.That's strange that it would hit an alignment fault on a memcpy. memcpy is supposed to operate at byte granularity.
I suspect this statement is the problem:
const struct openvpn_iphdr *ip = (const struct openvpn_iphdr *) BPTR (buf);The cast results in undefined behavior if BPTR (buf) has the wrong alignment. Recent versions of GCC know this and therefore conclude that BPTR must be properly aligned. As a result, it is possible to replace
memcpy()with something that copies word-wise.
Quoted 5 lines
The char * casts in your other message won't fix this, they come too late. It's a common misconception that char pointers behave like machine addresses. They don't.
Just to be clear, this is not a bug in GCC. Your code is not valid C.
That's a great observation that probably explains the alpha alignment issues -- thanks!
James