]>
git.ipfire.org Git - thirdparty/wireguard-go.git/log
Jason A. Donenfeld [Fri, 4 Jun 2021 14:33:28 +0000 (16:33 +0200)]
device: zero out allowedip node pointers when removing
This should make it a bit easier for the garbage collector.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Thu, 3 Jun 2021 16:22:50 +0000 (18:22 +0200)]
device: limit allowedip fuzzer a to 4 times through
Trying this for every peer winds up being very slow and precludes it
from acceptable runtime in the CI, so reduce this to 4.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Thu, 3 Jun 2021 14:12:29 +0000 (16:12 +0200)]
device: simplify allowedips lookup signature
The inliner should handle this for us.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Thu, 3 Jun 2021 13:40:09 +0000 (15:40 +0200)]
device: remove nodes by peer in O(1) instead of O(n)
Now that we have parent pointers hooked up, we can simply go right to
the node and remove it in place, rather than having to recursively walk
the entire trie.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Thu, 3 Jun 2021 12:50:28 +0000 (14:50 +0200)]
device: remove recursion from insertion and connect parent pointers
This makes the insertion algorithm a bit more efficient, while also now
taking on the additional task of connecting up parent pointers. This
will be handy in the following commit.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Thu, 3 Jun 2021 11:51:03 +0000 (13:51 +0200)]
device: reduce size of trie struct
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Josh Bleecher Snyder [Sat, 3 Apr 2021 17:15:59 +0000 (10:15 -0700)]
go.mod: bump golang.org/x/sys again
To pick up https://go-review.googlesource.com/c/sys/+/307129.
Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
Jason A. Donenfeld [Fri, 21 May 2021 22:57:42 +0000 (00:57 +0200)]
device: allow reducing queue constants on iOS
Heavier network extensions might require the wireguard-go component to
use less ram, so let users of this reduce these as needed.
At some point we'll put this behind a configuration method of sorts, but
for now, just expose the consts as vars.
Requested-by: Josh Bleecher Snyder <josh@tailscale.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Thu, 20 May 2021 16:26:01 +0000 (18:26 +0200)]
tun: linux: account for interface removal from outside
On Linux we can run `ip link del wg0`, in which case the fd becomes
stale, and we should exit. Since this is an intentional action, don't
treat it as an error.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Thu, 20 May 2021 16:09:55 +0000 (18:09 +0200)]
conn: linux: protect read fds
The -1 protection was removed and the wrong error was returned, causing
us to read from a bogus fd. As well, remove the useless closures that
aren't doing anything, since this is all synchronized anyway.
Fixes: 10533c3 ("all: make conn.Bind.Open return a slice of receive functions")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Thu, 20 May 2021 15:56:36 +0000 (17:56 +0200)]
rwcancel: use ordinary os.ErrClosed instead of custom error
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Thu, 20 May 2021 15:42:34 +0000 (17:42 +0200)]
rwcancel: use poll instead of select
Suggested-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Thu, 13 May 2021 23:07:55 +0000 (01:07 +0200)]
device: optimize Peer.String even more
This reduces the allocation, branches, and amount of base64 encoding.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Josh Bleecher Snyder [Thu, 13 May 2021 22:30:18 +0000 (15:30 -0700)]
device: optimize Peer.String
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Jason A. Donenfeld [Tue, 11 May 2021 14:47:17 +0000 (16:47 +0200)]
conn: windows: set count=0 on retry
When retrying, if count is not 0, we forget to dequeue another request,
and so the ring fills up and errors out.
Reported-by: Sascha Dierberg <dierberg@dresearch-fe.de>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Mon, 10 May 2021 20:23:32 +0000 (22:23 +0200)]
main: replace crlf on windows in fmt test
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Fri, 7 May 2021 10:56:10 +0000 (12:56 +0200)]
main: check that code is formatted in unit test
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Fri, 7 May 2021 10:21:27 +0000 (12:21 +0200)]
tun: format
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Fri, 7 May 2021 10:21:21 +0000 (12:21 +0200)]
device: add ID to repeated routines
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Fri, 7 May 2021 10:17:41 +0000 (12:17 +0200)]
device: remove unusual ... in messages
We dont use ... in any other present progressive messages except these.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Fri, 7 May 2021 07:39:06 +0000 (09:39 +0200)]
device: avoid verbose log line during ordinary shutdown sequence
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Fri, 7 May 2021 07:26:24 +0000 (09:26 +0200)]
tun: windows: set event before waiting
In
097af6e ("tun: windows: protect reads from closing") we made sure no
functions are running when End() is called, to avoid a UaF. But we still
need to kick that event somehow, so that Read() is allowed to exit, in
order to release the lock. So this commit calls SetEvent, while moving
the closing boolean to be atomic so it can be modified without locks,
and then moves to a WaitGroup for the RCU-like pattern.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Fri, 7 May 2021 07:17:35 +0000 (09:17 +0200)]
tun: windows: rearrange struct to avoid alignment trap on 32bit
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Fri, 7 May 2021 07:10:41 +0000 (09:10 +0200)]
tun: windows: check alignment in unit test
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Josh Bleecher Snyder [Tue, 27 Apr 2021 17:15:15 +0000 (10:15 -0700)]
device: log all errors received by RoutineReceiveIncoming
When debugging, it's useful to know why a receive func exited.
We were already logging that, but only in the "death spiral" case.
Move the logging up, to capture it always.
Reduce the verbosity, since it is not an error case any more.
Put the receive func name in the log line.
Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
Jason A. Donenfeld [Thu, 6 May 2021 09:03:04 +0000 (11:03 +0200)]
tun/netstack: update go mod and remove GSO argument
Reported-by: John Xiong <xiaoyang1258@yeah.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Wed, 5 May 2021 09:42:45 +0000 (11:42 +0200)]
tun: windows: send MTU update when forced MTU changes
Otherwise the padding doesn't get updated.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 27 Apr 2021 02:22:45 +0000 (22:22 -0400)]
tun: windows: protect reads from closing
The code previously used the old errors channel for checking, rather
than the simpler boolean, which caused issues on shutdown, since the
errors channel was meaningless. However, looking at this exposed a more
basic problem: Close() and all the other functions that check the closed
boolean can race. So protect with a basic RW lock, to ensure that
Close() waits for all pending operations to complete.
Reported-by: Joshua Sjoding <joshua.sjoding@scjalliance.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 27 Apr 2021 02:07:03 +0000 (22:07 -0400)]
conn: windows: do not error out when receiving UDP jumbogram
If we receive a large UDP packet, don't return an error to receive.go,
which then terminates the receive loop. Instead, simply retry.
Considering Winsock's general finickiness, we might consider other
places where an attacker on the wire can generate error conditions like
this.
Reported-by: Sascha Dierberg <sascha.dierberg@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Sat, 24 Apr 2021 17:07:27 +0000 (13:07 -0400)]
version: bump snapshot
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Mon, 19 Apr 2021 21:10:23 +0000 (15:10 -0600)]
tun: freebsd: avoid OOB writes
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Mon, 19 Apr 2021 21:01:36 +0000 (15:01 -0600)]
tun: freebsd: become controlling process when reopening tun FD
When we pass the TUN FD to the child, we have to call TUNSIFPID;
otherwise when we close the device, we get a splat in dmesg.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Mon, 19 Apr 2021 20:54:59 +0000 (14:54 -0600)]
tun: freebsd: restructure and cleanup
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Mon, 19 Apr 2021 02:26:32 +0000 (20:26 -0600)]
tun: freebsd: remove horrific hack for getting tunnel name
As of FreeBSD 12.1, there's TUNGIFNAME.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Mon, 19 Apr 2021 02:09:04 +0000 (20:09 -0600)]
tun: freebsd: set IFF_MULTICAST for routing daemons
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Fri, 16 Apr 2021 05:32:44 +0000 (23:32 -0600)]
main: print kernel warning on OpenBSD and FreeBSD too
More kernels!
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Mon, 12 Apr 2021 22:19:35 +0000 (16:19 -0600)]
device: don't defer unlocking from loop
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Fri, 9 Apr 2021 23:21:35 +0000 (17:21 -0600)]
conn: reconstruct v4 vs v6 receive function based on symtab
This is kind of gross but it's better than the alternatives.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Kristupas Antanavičius [Mon, 12 Apr 2021 11:50:58 +0000 (14:50 +0300)]
device: allocate new buffer in receive death spiral
Note: this bug is "hidden" by avoiding "death spiral" code path by
6228659 ("device: handle broader range of errors in RoutineReceiveIncoming").
If the code reached "death spiral" mechanism, there would be multiple
double frees happening. This results in a deadlock on iOS, because the
pools are fixed size and goroutine might stop until somebody makes
space in the pool.
This was almost 100% repro on the new ARM Macbooks:
- Build with 'ios' tag for Mac. This will enable bounded pools.
- Somehow call device.IpcSet at least couple of times (update config)
- device.BindUpdate() would be triggered
- RoutineReceiveIncoming would enter "death spiral".
- RoutineReceiveIncoming would stall on double free (pool is already
full)
- The stuck routine would deadlock 'device.closeBindLocked()' function
on line 'netc.stopping.Wait()'
Signed-off-by: Kristupas Antanavičius <kristupas.antanavicius@nordsec.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Sat, 10 Apr 2021 00:08:48 +0000 (18:08 -0600)]
conn: windows: reset ring to starting position after free
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Fri, 9 Apr 2021 00:17:59 +0000 (18:17 -0600)]
conn: windows: compare head and tail properly
By not comparing these with the modulo, the ring became nearly never
full, resulting in completion queue buffers filling up prematurely.
Reported-by: Joshua Sjoding <joshua.sjoding@scjalliance.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 6 Apr 2021 17:45:10 +0000 (11:45 -0600)]
winrio: test that IOCP-based RIO is supported
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Josh Bleecher Snyder [Wed, 31 Mar 2021 20:55:18 +0000 (13:55 -0700)]
all: make conn.Bind.Open return a slice of receive functions
Instead of hard-coding exactly two sources from which
to receive packets (an IPv4 source and an IPv6 source),
allow the conn.Bind to specify a set of sources.
Beneficial consequences:
* If there's no IPv6 support on a system,
conn.Bind.Open can choose not to return a receive function for it,
which is simpler than tracking that state in the bind.
This simplification removes existing data races from both
conn.StdNetBind and bindtest.ChannelBind.
* If there are more than two sources on a system,
the conn.Bind no longer needs to add a separate muxing layer.
Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
Jason A. Donenfeld [Fri, 2 Apr 2021 16:36:41 +0000 (10:36 -0600)]
conn: winrio: pass key parameter into struct
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Josh Bleecher Snyder [Tue, 30 Mar 2021 19:36:59 +0000 (12:36 -0700)]
device: handle broader range of errors in RoutineReceiveIncoming
RoutineReceiveIncoming exits immediately on net.ErrClosed,
but not on other errors. However, for errors that are known
to be permanent, such as syscall.EAFNOSUPPORT,
we may as well exit immediately instead of retrying.
This considerably speeds up the package device tests right now,
because the Bind sometimes (incorrectly) returns syscall.EAFNOSUPPORT
instead of net.ErrClosed.
Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
Josh Bleecher Snyder [Mon, 29 Mar 2021 20:27:21 +0000 (13:27 -0700)]
conn: document retry loop in StdNetBind.Open
It's not obvious on a first read what the loop is doing.
Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
Josh Bleecher Snyder [Mon, 29 Mar 2021 20:21:06 +0000 (13:21 -0700)]
conn: use local ipvN vars in StdNetBind.Open
This makes it clearer that they are fresh on each attempt,
and avoids the bookkeeping required to clearing them on failure.
Also, remove an unnecessary err != nil.
Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
Josh Bleecher Snyder [Mon, 29 Mar 2021 20:11:11 +0000 (13:11 -0700)]
conn: unify code in StdNetBind.Send
The sending code is identical for ipv4 and ipv6;
select the conn, then use it.
Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
Josh Bleecher Snyder [Mon, 29 Mar 2021 19:36:09 +0000 (12:36 -0700)]
device: rename unsafeCloseBind to closeBindLocked
And document a bit.
This name is more idiomatic.
Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
Jason A. Donenfeld [Tue, 23 Mar 2021 19:07:19 +0000 (13:07 -0600)]
version: bump snapshot
Jason A. Donenfeld [Tue, 23 Mar 2021 18:41:34 +0000 (12:41 -0600)]
tun: freebsd: use broadcast mode instead of PPP mode
It makes the routing configuration simpler.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Thu, 11 Mar 2021 16:29:10 +0000 (09:29 -0700)]
device: signal to close device in separate routine
Otherwise we wind up deadlocking.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Thu, 11 Mar 2021 16:23:11 +0000 (09:23 -0700)]
tun: linux: do not spam events every second from hack listener
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Kay Diam [Sun, 7 Mar 2021 16:21:31 +0000 (17:21 +0100)]
tun: freebsd: allow empty names
This change allows omitting the tun interface name setting. When the
name is not set, the kernel automatically picks up the tun name and
index.
Signed-off-by: Kay Diam <kay.diam@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Wed, 3 Mar 2021 11:26:59 +0000 (12:26 +0100)]
winpipe: move syscalls into x/sys
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Wed, 3 Mar 2021 14:05:19 +0000 (15:05 +0100)]
memmod: use resource functions from x/sys
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Wed, 3 Mar 2021 13:38:26 +0000 (14:38 +0100)]
memmod: do not use IsBadReadPtr
It should be enough to check for the trailing zero name.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Sat, 6 Mar 2021 16:20:46 +0000 (09:20 -0700)]
conn: linux: unexport mutex
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Fri, 5 Mar 2021 22:06:08 +0000 (15:06 -0700)]
mod: bump x/sys
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Sat, 6 Mar 2021 16:03:28 +0000 (09:03 -0700)]
mod: rename COPYING to LICENSE
Otherwise the netstack module doesn't show up on the package site.
https://github.com/golang/go/issues/43817#issuecomment-
764987580
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Sat, 6 Mar 2021 15:21:18 +0000 (08:21 -0700)]
tun/netstack: bump deps and api
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Thu, 25 Feb 2021 11:28:53 +0000 (12:28 +0100)]
device: get rid of peers.empty boolean in timersActive
There's no way for len(peers)==0 when a current peer has
isRunning==false.
This requires some struct reshuffling so that the uint64 pointer is
aligned.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Mon, 22 Feb 2021 17:47:41 +0000 (18:47 +0100)]
conn: implement RIO for fast Windows UDP sockets
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Mon, 22 Feb 2021 14:43:08 +0000 (15:43 +0100)]
global: remove TODO name graffiti
Googlers have a habit of graffiting their name in TODO items that then
are never addressed, and other people won't go near those because
they're marked territory of another animal. I've been gradually cleaning
these up as I see them, but this commit just goes all the way and
removes the remaining stragglers.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Mon, 22 Feb 2021 03:30:31 +0000 (04:30 +0100)]
device: test up/down using virtual conn
This prevents port clashing bugs.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Mon, 22 Feb 2021 01:57:41 +0000 (02:57 +0100)]
device: cleanup unused test components
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Mon, 22 Feb 2021 01:01:50 +0000 (02:01 +0100)]
conn: make binds replacable
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Mon, 22 Feb 2021 14:12:03 +0000 (15:12 +0100)]
device: disable waitpool tests
This code is stable, and the test is finicky, especially on high core
count systems, so just disable it.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Brad Fitzpatrick [Thu, 18 Feb 2021 22:53:22 +0000 (14:53 -0800)]
tun: make NativeTun.Close well behaved, not crash on double close
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Brad Fitzpatrick [Thu, 18 Feb 2021 22:42:04 +0000 (14:42 -0800)]
README: bump document Go requirement to 1.16
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Jason A. Donenfeld [Wed, 17 Feb 2021 21:19:27 +0000 (22:19 +0100)]
global: stop using ioutil
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 16 Feb 2021 20:05:25 +0000 (21:05 +0100)]
conn: bump to 1.16 and get rid of NetErrClosed hack
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Fri, 12 Feb 2021 17:00:59 +0000 (18:00 +0100)]
version: bump snapshot
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Fri, 12 Feb 2021 16:59:50 +0000 (17:59 +0100)]
device: remove old version file
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Thu, 11 Feb 2021 14:48:56 +0000 (15:48 +0100)]
gitignore: remove old hacks
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Wed, 10 Feb 2021 17:19:11 +0000 (18:19 +0100)]
device: use container/list instead of open coding it
This linked list implementation is awful, but maybe Go 2 will help
eventually, and at least we're not open coding the hlist any more.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Wed, 10 Feb 2021 00:01:37 +0000 (01:01 +0100)]
device: retry Up() in up/down test
We're loosing our ownership of the port when bringing the device down,
which means another test process could reclaim it. Avoid this by
retrying for 4 seconds.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 9 Feb 2021 23:43:31 +0000 (00:43 +0100)]
conn: close old fd before trying again
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 9 Feb 2021 23:39:28 +0000 (00:39 +0100)]
device: flush peer queues before starting device
In case some old packets snuck in there before, this flushes before
starting afresh.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 9 Feb 2021 23:21:12 +0000 (00:21 +0100)]
device: create peer queues at peer creation time
Rather than racing with Start(), since we're never destroying these
queues, we just set the variables at creation time.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 9 Feb 2021 23:12:23 +0000 (00:12 +0100)]
device: return error from Up() and Down()
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 9 Feb 2021 19:18:21 +0000 (20:18 +0100)]
rwcancel: add an explicit close call
This lets us collect FDs even if the GC doesn't do it for us.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 9 Feb 2021 18:54:00 +0000 (19:54 +0100)]
rwcancel: use errors.Is for unwrapping
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 9 Feb 2021 18:48:27 +0000 (19:48 +0100)]
tun: use errors.Is for unwrapping
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 9 Feb 2021 18:46:57 +0000 (19:46 +0100)]
conn: use errors.Is for unwrapping
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 9 Feb 2021 18:26:45 +0000 (19:26 +0100)]
device: handshake routine writes into encryption queue
Since RoutineHandshake calls peer.SendKeepalive(), it potentially is a
writer into the encryption queue, so we need to bump the wg count.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Josh Bleecher Snyder [Tue, 9 Feb 2021 17:53:00 +0000 (09:53 -0800)]
device: make RoutineReadFromTUN keep encryption queue alive
RoutineReadFromTUN can trigger a call to SendStagedPackets.
SendStagedPackets attempts to protect against sending
on the encryption queue by checking peer.isRunning and device.isClosed.
However, those are subject to TOCTOU bugs.
If that happens, we get this:
goroutine 1254 [running]:
golang.zx2c4.com/wireguard/device.(*Peer).SendStagedPackets(0xc000798300)
.../wireguard-go/device/send.go:321 +0x125
golang.zx2c4.com/wireguard/device.(*Device).RoutineReadFromTUN(0xc000014780)
.../wireguard-go/device/send.go:271 +0x21c
created by golang.zx2c4.com/wireguard/device.NewDevice
.../wireguard-go/device/device.go:315 +0x298
Fix this with a simple, big hammer: Keep the encryption queue
alive as long as it might be written to.
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Jason A. Donenfeld [Tue, 9 Feb 2021 17:45:12 +0000 (18:45 +0100)]
conn: try harder to have v4 and v6 ports agree
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Josh Bleecher Snyder [Tue, 9 Feb 2021 17:08:17 +0000 (09:08 -0800)]
device: only allocate peer queues once
This serves two purposes.
First, it makes repeatedly stopping then starting a peer cheaper.
Second, it prevents a data race observed accessing the queues.
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Josh Bleecher Snyder [Tue, 9 Feb 2021 16:27:48 +0000 (08:27 -0800)]
device: clarify device.state.state docs (again)
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Josh Bleecher Snyder [Tue, 9 Feb 2021 16:20:11 +0000 (08:20 -0800)]
device: run fewer iterations in TestUpDown
The high iteration count was useful when TestUpDown
was the nexus of new bugs to investigate.
Now that it has stabilized, that's less valuable.
And it slows down running the tests and crowds out other tests.
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Josh Bleecher Snyder [Tue, 9 Feb 2021 16:18:47 +0000 (08:18 -0800)]
device: run fewer trials in TestWaitPool when race detector enabled
On a many-core machine with the race detector enabled,
this test can take several minutes to complete.
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Josh Bleecher Snyder [Tue, 9 Feb 2021 16:15:21 +0000 (08:15 -0800)]
device: remove nil elem check in finalizers
This is not necessary, and removing it speeds up detection of UAF bugs.
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
Jason A. Donenfeld [Tue, 9 Feb 2021 15:11:33 +0000 (16:11 +0100)]
device: rename unsafeRemovePeer to removePeerLocked
This matches the new naming scheme of upLocked and downLocked.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 9 Feb 2021 14:39:19 +0000 (15:39 +0100)]
device: remove deviceStateNew
It's never used and we won't have a use for it. Also, move to go-running
stringer, for those without GOPATHs.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 9 Feb 2021 14:35:43 +0000 (15:35 +0100)]
device: fix comment typo and shorten state.mu.Lock to state.Lock
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 9 Feb 2021 14:32:55 +0000 (15:32 +0100)]
device: fix typo in comment
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 9 Feb 2021 14:30:32 +0000 (15:30 +0100)]
device: fix alignment on 32-bit machines and test for it
The test previously checked the offset within a substruct, not the
offset within the allocated struct, so this adds the two together.
It then fixes an alignment crash on 32-bit machines.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 9 Feb 2021 14:25:43 +0000 (15:25 +0100)]
device: do not log on idempotent device state change
Part of being actually idempotent is that we shouldn't penalize code
that takes advantage of this property with a log splat.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Jason A. Donenfeld [Tue, 9 Feb 2021 14:09:50 +0000 (15:09 +0100)]
device: do not attach finalizer to non-returned object
Before, the code attached a finalizer to an object that wasn't returned,
resulting in immediate garbage collection. Instead return the actual
pointer.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>