Development discussion of WireGuard
 help / color / mirror / Atom feed
* Possible race condition in Wireguard-go
@ 2023-05-16 13:06 Anton
  0 siblings, 0 replies; only message in thread
From: Anton @ 2023-05-16 13:06 UTC (permalink / raw)
  To: wireguard

Hello all

I've found a possible race condition resulting in a panic in wireguard-go.
It happens when a client session disconnects, not often - once in a
few days with a few (5-10) sessions running.
The app I'm working on is based on wireguard-go/tun/netstack/tun.go code.

The problem reveals itself as a panic (see below).
It happens when peer.RoutineSequentialReceiver() go-routine does a
(*tun.Device).Write(), which calls gvisor (*Endpoint).InjectInbound(),
but endpoint could have been made nil to this point of time, b/c
tun.stack.RemoveNIC(1) called from tunDev.Close() assigns nil to

A possible solution:

If I move
> device.tun.device.Close()

below the
> device.RemoveAllPeers()

thus making peer-related operations to finish before the
device.tun.device.Close(), then crash doesn't happen.

By now the code has been running for a week.
I'll test it for another week or two.


> 2023-05-04T00:34:10.000 INF services\wireguard\service\service.go:162 > Cleaning up session 7f100e49-6517-4141-be66-1ac7c47ed5e8
> DEBUG: (myst) 2023/05/04 00:34:10 Device closing
> 2023-05-04T00:34:10.000 INF services\wireguard\service\stats_publisher.go:65 > Stopped publishing statistics for session 7f100e49-6517-4141-be66-1ac7c47ed5e8
> DEBUG: (myst) 2023/05/04 00:34:10 peer(/Zbg…wTzA) - Routine: sequential receiver - stopped
> panic: runtime error: invalid memory address or nil pointer dereference
> [signal 0xc0000005 code=0x0 addr=0x20 pc=0x7ff62082c781]

> goroutine 485845 [running]:
>         C:/Users/user/go/pkg/mod/
>*netTun).Write(0xc002211600, {0xc0020348a0?, 0x1, 0xc0015ac810?}, 0x10)
>         C:/Users/user/src/node/services/wireguard/endpoint/netstack-provider/netstack.go:164 +0x141
>*Peer).RoutineSequentialReceiver(0xc001229c00, 0x1)
>         C:/Users/user/go/pkg/mod/ +0x23a
> created by*Peer).Start
>         C:/Users/user/go/pkg/mod/ +0x2e5

A link to related code:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-26 14:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-16 13:06 Possible race condition in Wireguard-go Anton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).