[Fixed] [5.2][Jolla Phone 2026] WireGuard VPN crashes other network connections

Going to throw my hat in the ring here because today I finally got around to reconfiguring my own network and I’m most definitely seeing the same sort of crash when trying to bring up WireGuard. The connman settings file looks like this:

Name=obfuscated
Type=wireguard
Host=obfuscated.com
VPN.Domain=sailfishos.org
WireGuard.Address=fe80::6a6f:7369:1:1/64
WireGuard.PrivateKey=obfuscated=
WireGuard.PublicKey=obfuscated=
WireGuard.PresharedKey=obfuscated=
WireGuard.AllowedIPs=fe80::1/128
WireGuard.EndpointPort=12345
WireGuard.PersistentKeepalive=30

What I’m trying to do is ostensibly the same thing as OP, to establish an additional interface I can connect purely link-local to my server over (in my case using fe80::%wg0, and I wish I could name the interface myself). What ends up happening is connman crash-looping, leaving many wg# interfaces behind, and the internet connection going down. To get it to stop it seems like I have to remove the peer on the server side, though I’m not sure if that’s what actually does the trick.

SFOS 5.2.0.22 (JP2026)

Have the same problem. So it seems to be still present in 5.2.0.22 will try suggested fix later.

And: even a reboot doesn’t help. VPN directly connects.

The easiest way I’ve found is to add VPN to the top menu, then go to Utilities and restart networking, then immediately hit the VPN button when it turns on. I think you have longer if the server isn’t responding (I removed the peer).

Anyway, I finally found some time so here’s what’s happening:

Thread 1 "connmand" received signal SIGSEGV, Segmentation fault.
get_interface_addresses (if_addr=if_addr@entry=0x7fc7516220) at src/inet.c:1260
1260				if (!if_addr->allow_unspec && is_addr_unspec(
(gdb) bt
#0  get_interface_addresses (if_addr=if_addr@entry=0x7fc7516220) at src/inet.c:1260
#1  0x0000000000485280 in connman_inet_ipv6_get_route_addresses (index=<optimized out>, network=network@entry=0x7fc7516338, netmask=netmask@entry=0x7fc7516340, destination=destination@entry=0x7fc7516348) at src/inet.c:2516
#2  0x00000000004400d8 in add_network_route (data=data@entry=0x2c149670) at plugins/vpn.c:1683
#3  0x000000000044020c in set_routes (provider=0x2c1d0a60, type=CONNMAN_PROVIDER_ROUTE_UNKNOWN) at plugins/vpn.c:1849
#4  0x00000000004783e0 in set_connected (provider=0x2c1d0a60, connected=true) at src/provider.c:484
#5  0x0000000000440534 in set_provider_state (data=data@entry=0x2c149670) at plugins/vpn.c:328
#6  0x00000000004416d0 in property_changed (conn=<optimized out>, message=<optimized out>, user_data=<optimized out>) at plugins/vpn.c:2224
#7  0x00000000004d0700 in signal_filter (connection=0x2c113b60, message=0x2c1bdea0, user_data=0x2c16d5f0) at gdbus/watch.c:428
#8  0x00000000004d08b8 in message_filter (connection=0x2c113b60, message=0x2c1bdea0, user_data=<optimized out>) at gdbus/watch.c:578
#9  0x00000079bdbf0c94 in dbus_connection_dispatch () from /usr/lib64/libdbus-1.so.3
#10 0x00000000004cfab0 in message_dispatch (data=0x2c113b60) at gdbus/mainloop.c:80
#11 message_dispatch (data=0x2c113b60) at gdbus/mainloop.c:67
#12 0x00000079bdcac294 in ?? () from /usr/lib64/libglib-2.0.so.0
#13 0x00000079bdcafbdc in ?? () from /usr/lib64/libglib-2.0.so.0
#14 0x00000079bdcb06ac in g_main_loop_run () from /usr/lib64/libglib-2.0.so.0
#15 0x000000000041979c in main (argc=<optimized out>, argv=<optimized out>) at src/main.c:461
(gdb) info locals
ifaddr = 0x2c1facf0
ifa = 0x2c1fd478
addrs = {0x2c1fd4b0, 0x2c1fd4d4, 0x0, 0x0}
addr_in = <optimized out>
addr_in6 = <optimized out>
name = "wg4", '\000' <repeats 12 times>
len = <optimized out>
err = -2
i = <optimized out>
__FUNCTION__ = "get_interface_addresses"
(gdb) p *ifa
$5 = {ifa_next = 0x0, ifa_name = 0x2c1fcb0c "wg4", ifa_flags = 98513, ifa_addr = 0x2c1fd4b0, ifa_netmask = 0x2c1fd4d4, ifa_ifu = {ifu_broadaddr = 0x0, ifu_dstaddr = 0x0}, ifa_data = 0x0}

ifa_ifu.ifu_dstaddr in ifaddr returned by getifaddrs() is NULL, because no P2P destination address has been assigned to the interface. The macro IN6_IS_ADDR_UNSPECIFIED() in is_addr_unspec (which I assume has been inlined here) dereferences the pointer.

I’m purely guessing the fix is just this: This will paper over the problem but the bug is almost certainly in the kernel:

diff --git a/connman/src/inet.c b/connman/src/inet.c
index 7908f980..221d3c8f 100644
--- a/connman/src/inet.c
+++ b/connman/src/inet.c
@@ -1246,7 +1246,8 @@ static int get_interface_addresses(struct interface_address *if_addr)
 		}
 
 		if (if_addr->ipaddrs[ADDR_TYPE_BRDADDR] &&
-					(ifa->ifa_flags & IFF_BROADCAST)) {
+					(ifa->ifa_flags & IFF_BROADCAST) &&
+					ifa->ifa_ifu.ifu_broadaddr) {
 			if (!if_addr->allow_unspec && is_addr_unspec(
 						if_addr->family,
 						ifa->ifa_ifu.ifu_broadaddr))
@@ -1256,7 +1257,8 @@ static int get_interface_addresses(struct interface_address *if_addr)
 		}
 
 		if (if_addr->ipaddrs[ADDR_TYPE_DSTADDR] &&
-					(ifa->ifa_flags & IFF_POINTOPOINT)) {
+					(ifa->ifa_flags & IFF_POINTOPOINT) &&
+					ifa->ifa_ifu.ifu_dstaddr) {
 			if (!if_addr->allow_unspec && is_addr_unspec(
 						if_addr->family,
 						ifa->ifa_ifu.ifu_dstaddr))

But I don’t have a build setup so I’m a little short of testing it.

Thx. I tried that several times, but never tried it quick enough apparently. That did the trick and I got out of the ghost VPN. Funnily I deleted the server entry and I was still able to connect. Maybe I should have restarted the router after deleting, but anyway, now after making this quick “restart”/”turn-off” combo, I am back to normal.

Now I hope/wait for some 5.2.0.x to include your patch..

Thx!

I’ve looked at bit at musl, glibc, and linux. They both do the same thing to fill out ifa_ifu.ifu_dstaddr when translating the netlink data and in glibc’s case this has remained unchanged since the initial commit in 2003. Neither of them actually touch the flags, they just copy them directly from the kernel. The bug is definitely not in connman, as getifaddrs() explicitly specifies that ifu_dstaddr is valid if IFF_POINTOPOINT is set. Between linux and libc I’m guessing this is a kernel bug. libc calls RTM_GETLINK followed by RTM_GETADDR.

For RTM_GETLINK it’s pretty simple: in drivers/net/wireguard/device.c:wg_setup(), wireguard sets:

dev->addr_len = 0;
...
dev->flags = IFF_POINTOPOINT | IFF_NOARP;

and in net/core/rtnetlink.c:rtnl_fill_ifinfo() linux does the following:

if (dev->addr_len) {
	if (nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr) ||
	    nla_put(skb, IFLA_BROADCAST, dev->addr_len, dev->broadcast))
		goto nla_put_failure;
}

So no IFLA_ADDRESS or IFLA_BROADCAST is returned for the first entry that connman encounters. This isn’t a problem though since the address is NULL, so it just skips that entry. Based on ipv6 sit, dev->broadcast should have contained the P2P destination address, which works out as ifu_dstaddr is in a union with ifu_broadaddr, which is where libc puts the IFLA_BROADCAST address.

For RTM_GETADDR we turn to net/ipv6/addrconf.c:inet6_fill_ifaddr(), where we see this:

if (!ipv6_addr_any(&ifa->peer_addr)) {
	if (nla_put_in6_addr(skb, IFA_LOCAL, &ifa->addr) < 0 ||
	    nla_put_in6_addr(skb, IFA_ADDRESS, &ifa->peer_addr) < 0)
		goto error;
} else {
	if (nla_put_in6_addr(skb, IFA_ADDRESS, &ifa->addr) < 0)
		goto error;
}

ipv6_addr_any() just checks if the entire address is zero so presumably this means that the peer_addr is unset and thus it only returns the interface address. What libc does here is, if it receives an IFA_LOCAL first, it puts the IFA_ADDRESS in ifu_dstaddr, so the second time connman encounters the wgN interface, it still has the IFF_POINTOPOINT bit set and it again has no ifu_dstaddr. This time it has an address though, so it processes the entry and crashes. This isn’t a problem on IPv4, since those have broadcast addresses sent as IFA_BROADCAST that end up in the same memory due to the unioning.

I’ve pulled the netlink data with strace and confirmed that this is what’s happening, and the output of getifaddrs() looks like this on my (working) desktop setup, which has the same wireguard setup as I’ve been trying on my phone:

lo				addr=family=17					broadaddr=yes	flags=10049
enp1s0f0		addr=family=17					broadaddr=yes	flags=1002
sit0			addr=family=17					broadaddr=yes	flags=80
wlp2s0			addr=family=17					broadaddr=yes	flags=11043
wghermes		addr=NULL						broadaddr=no	flags=100D1
wgwirbelwind	addr=NULL						broadaddr=no	flags=100D1
wgtest			addr=NULL						broadaddr=no	flags=100D1
lo				addr=127.0.0.1					broadaddr=yes	flags=10049
wlp2s0			addr=192.168.0.132				broadaddr=yes	flags=11043
wgtest			addr=198.51.100.1				broadaddr=yes	flags=100D1
lo				addr=::1						broadaddr=no	flags=10049
wlp2s0			addr=fe80::67b:cbff:feb3:dbe8	broadaddr=no	flags=11043
wghermes		addr=fe80::6a6f:7369:0:1		broadaddr=no	flags=100D1
wgwirbelwind	addr=fe80::6a6f:7369:0:1		broadaddr=no	flags=100D1
wgtest			addr=fe80::6a6f:7369:0:1		broadaddr=no	flags=100D1

IFF_POINTOPOINT is 1<<4, so you’ll see it’s set on every wg interface. IPv4 setups are unaffected since the getifaddrs() responses are filtered by address family as well.

I’m not really sure how to fix this. It doesn’t exactly make sense to put a singular destination address in dev->broadcast since there can be many, and I don’t know if it’s safe to remove the IFF_POINTOPOINT flag from wg interfaces. It clearly is a P2P interface but libc code unchanged since 2003 expects there to be multiple addresses in the rtnetlink response.

@jlaakkonen Sorry to bother you directly like this, just want to make sure you see the posts above :slight_smile:

Yeah. Good to ping to bring attention. The Topic Title has [FIXED] prefixed, which apparently isn’t true. At least not for 5.2.0.22.

It appears I was once again sniped.

Hi!

Thanks for the info and no problem in sending that notification.

If that is the case I think it is all the same to add the resulting errors into the functions that are used to check the addresses and to handle the error codes as a part of criteria for skipping the item. Might be that something like this is needed later on elsewhere. So I’ll skip the AI slop.

Honestly, configuring a WireGuard connection using link-local addresses is just asking for trouble. The requirement to define the interface with the link-local address is one issue to begin with. Routing might be another thing I don’t even want to put my head into now… Maybe you should look into ULA (unique local address) IPv6 addresses instead?

I’m pretty sure at least in ConnMan this hasn’t been considered as a scenario in any way. The IPv6 side is quite raw still and relies on kernel to do its job, this was confirmed by the previous upstream maintainer.

I think your proposed fix is perfectly fine. I asked dalias (author of musl) what he thought about getifaddrs not honoring the man page and he basically just asked me to ask you what you want to happen with it. It’s not a POSIX function so it has no formal definition to follow. It sounds like you’re okay with leaving it as-is and handling the missing addresses.

As for routing link-local IPv6, the entire reason I chose to do it this way is because I want the address to be unrouteable when the correct interface isn’t up. On every computer I’ve set this up on I (have to) dial it with a scoped IPv6 address, eg. fe80::1%wg0, and as you can see I give my interfaces persistent names so it’s not quite so ad-hoc. fe80::/10 dev … is the default route that exists for all v6-capable interfaces, so you really shouldn’t have to do anything on the connman side.

Hi,

I have now a lot of things here:

for all of you to test, it has the:

These are built on top of the 1.40+git26.6 that is shipped with latest 5.2 release. Let me know how these work if you have time and energy to check. So the disconnection while sleeping should not happen with WireGuard, nor it should use any DNS records that the transport medium could not handle (this feature might have issues, please report).

Well my use case certainly seems to be fixed. I can access both email and IRC over fe80::1%wg0 now :). It took me a while to realize that glibc does not support scoped addresses in /etc/hosts so I’m having to put fe80::1%wg0 everywhere. If you’re taking requests, I wish I could supply the interface name in the connman config, even if limited to eg. starting with wg[^0-9], or wg followed by an obscenely high number.

Edit: completely untested, haven’t even tried compiling it, but something like this:

diff --git a/connman/vpn/plugins/wireguard.c b/connman/vpn/plugins/wireguard.c
index 400a075e..639c0aed 100644
--- a/connman/vpn/plugins/wireguard.c
+++ b/connman/vpn/plugins/wireguard.c
@@ -91,7 +91,8 @@ struct {
 	{"WireGuard.AllowedIPs", true},
 	{"WireGuard.EndpointPort", true},
 	{"WireGuard.PersistentKeepalive", true},
-	{"WireGuard.DisableIPv6", true}
+	{"WireGuard.DisableIPv6", true},
+	{"WireGuard.InterfaceName", true},
 };
 
 static struct wireguard_info *create_private_data(struct vpn_provider *provider)
@@ -895,7 +896,38 @@ static int wg_connect(struct vpn_provider *provider,
 	}
 	g_free(gateway);
 
-	ifname = get_ifname();
+	option = vpn_provider_get_string(provider, "WireGuard.InterfaceName");
+	if (option) {
+		int hasnondigit = 0;
+		unsigned i;
+		err = -EINVAL;
+		if (option[0] != 'w' || option[1] != 'g') {
+			DBG("Wireguard.InterfaceName %s must begin with wg",
+								option);
+			goto error;
+		}
+		for (i = 2; i < IFNAMSIZ-1 && isalnum(option[i]); i++)
+			if (!isdigit(option[i]))
+				hasnondigit = 1;
+		if (i == IFNAMSIZ-1) {
+			DBG("Wireguard.InterfaceName %s is longer than %d characters",
+								option, IFNAMSIZ-1);
+			goto error;
+		}
+		if (option[i]) {
+			DBG("Wireguard.InterfaceName %s contains non-alpha-numerics",
+									option);
+			goto error;
+		}
+		if (!hasnondigit) {
+			DBG("Wireguard.InterfaceName %s must contain a non-digit",
+									option);
+			goto error;
+		}
+		wg_del_device(option);
+		ifname = option;
+	} else
+		ifname = get_ifname();
 	if (!ifname) {
 		DBG("Failed to find an usable device name");
 		err = -ENOENT;