linux/drivers/net/wireguard
Jason A. Donenfeld bf7b042dc6 wireguard: allowedips: free empty intermediate nodes when removing single node
When removing single nodes, it's possible that that node's parent is an
empty intermediate node, in which case, it too should be removed.
Otherwise the trie fills up and never is fully emptied, leading to
gradual memory leaks over time for tries that are modified often. There
was originally code to do this, but was removed during refactoring in
2016 and never reworked. Now that we have proper parent pointers from
the previous commits, we can implement this properly.

In order to reduce branching and expensive comparisons, we want to keep
the double pointer for parent assignment (which lets us easily chain up
to the root), but we still need to actually get the parent's base
address. So encode the bit number into the last two bits of the pointer,
and pack and unpack it as needed. This is a little bit clumsy but is the
fastest and less memory wasteful of the compromises. Note that we align
the root struct here to a minimum of 4, because it's embedded into a
larger struct, and we're relying on having the bottom two bits for our
flag, which would only be 16-bit aligned on m68k.

The existing macro-based helpers were a bit unwieldy for adding the bit
packing to, so this commit replaces them with safer and clearer ordinary
functions.

We add a test to the randomized/fuzzer part of the selftests, to free
the randomized tries by-peer, refuzz it, and repeat, until it's supposed
to be empty, and then then see if that actually resulted in the whole
thing being emptied. That combined with kmemcheck should hopefully make
sure this commit is doing what it should. Along the way this resulted in
various other cleanups of the tests and fixes for recent graphviz.

Fixes: e7096c131e ("net: WireGuard secure network tunnel")
Cc: stable@vger.kernel.org
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-06-04 14:25:14 -07:00
..
selftest wireguard: allowedips: free empty intermediate nodes when removing single node 2021-06-04 14:25:14 -07:00
allowedips.c wireguard: allowedips: free empty intermediate nodes when removing single node 2021-06-04 14:25:14 -07:00
allowedips.h wireguard: allowedips: free empty intermediate nodes when removing single node 2021-06-04 14:25:14 -07:00
cookie.c
cookie.h
device.c wireguard: queueing: get rid of per-peer ring buffers 2021-02-23 15:59:34 -08:00
device.h wireguard: queueing: get rid of per-peer ring buffers 2021-02-23 15:59:34 -08:00
main.c wireguard: allowedips: allocate nodes in kmem_cache 2021-06-04 14:25:14 -07:00
Makefile wireguard: do not use -O3 2021-06-04 14:25:14 -07:00
messages.h wireguard: queueing: preserve flow hash across packet scrubbing 2020-05-20 20:55:09 -07:00
netlink.c netlink: consistently use NLA_POLICY_MIN_LEN() 2020-08-18 12:28:45 -07:00
netlink.h
noise.c wireguard: noise: take lock when removing handshake entry from table 2020-09-09 11:31:37 -07:00
noise.h wireguard: noise: separate receive counter from send counter 2020-05-20 20:55:09 -07:00
peer.c wireguard: peer: allocate in kmem_cache 2021-06-04 14:25:14 -07:00
peer.h wireguard: peer: allocate in kmem_cache 2021-06-04 14:25:14 -07:00
peerlookup.c wireguard: peerlookup: take lock before checking hash in replace operation 2020-09-09 11:31:38 -07:00
peerlookup.h
queueing.c wireguard: queueing: get rid of per-peer ring buffers 2021-02-23 15:59:34 -08:00
queueing.h wireguard: queueing: get rid of per-peer ring buffers 2021-02-23 15:59:34 -08:00
ratelimiter.c
ratelimiter.h
receive.c wireguard: queueing: get rid of per-peer ring buffers 2021-02-23 15:59:34 -08:00
send.c wireguard: queueing: get rid of per-peer ring buffers 2021-02-23 15:59:34 -08:00
socket.c wireguard: use synchronize_net rather than synchronize_rcu 2021-06-04 14:25:14 -07:00
socket.h
timers.c
timers.h
version.h