linux/drivers/net/wireguard
Jason A. Donenfeld a9e90d9931 wireguard: noise: separate receive counter from send counter
In "wireguard: queueing: preserve flow hash across packet scrubbing", we
were required to slightly increase the size of the receive replay
counter to something still fairly small, but an increase nonetheless.
It turns out that we can recoup some of the additional memory overhead
by splitting up the prior union type into two distinct types. Before, we
used the same "noise_counter" union for both sending and receiving, with
sending just using a simple atomic64_t, while receiving used the full
replay counter checker. This meant that most of the memory being
allocated for the sending counter was being wasted. Since the old
"noise_counter" type increased in size in the prior commit, now is a
good time to split up that union type into a distinct "noise_replay_
counter" for receiving and a boring atomic64_t for sending, each using
neither more nor less memory than required.

Also, since sometimes the replay counter is accessed without
necessitating additional accesses to the bitmap, we can reduce cache
misses by hoisting the always-necessary lock above the bitmap in the
struct layout. We also change a "noise_replay_counter" stack allocation
to kmalloc in a -DDEBUG selftest so that KASAN doesn't trigger a stack
frame warning.

All and all, removing a bit of abstraction in this commit makes the code
simpler and smaller, in addition to the motivating memory usage
recuperation. For example, passing around raw "noise_symmetric_key"
structs is something that really only makes sense within noise.c, in the
one place where the sending and receiving keys can safely be thought of
as the same type of object; subsequent to that, it's important that we
uniformly access these through keypair->{sending,receiving}, where their
distinct roles are always made explicit. So this patch allows us to draw
that distinction clearly as well.

Fixes: e7096c131e ("net: WireGuard secure network tunnel")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-05-20 20:55:09 -07:00
..
selftest wireguard: noise: separate receive counter from send counter 2020-05-20 20:55:09 -07:00
allowedips.c wireguard: allowedips: fix use-after-free in root_remove_peer_lists 2020-02-05 14:14:18 +01:00
allowedips.h
cookie.c
cookie.h
device.c wireguard: queueing: account for skb->protocol==0 2020-03-18 18:51:43 -07:00
device.h net: introduce skb_list_walk_safe for skb segment walking 2020-01-08 15:19:54 -08:00
main.c wireguard: main: remove unused include <linux/version.h> 2019-12-16 19:22:22 -08:00
Makefile
messages.h wireguard: queueing: preserve flow hash across packet scrubbing 2020-05-20 20:55:09 -07:00
netlink.c wireguard: noise: error out precomputed DH during handshake rather than config 2020-03-18 18:51:43 -07:00
netlink.h
noise.c wireguard: noise: separate receive counter from send counter 2020-05-20 20:55:09 -07:00
noise.h wireguard: noise: separate receive counter from send counter 2020-05-20 20:55:09 -07:00
peer.c wireguard: noise: error out precomputed DH during handshake rather than config 2020-03-18 18:51:43 -07:00
peer.h
peerlookup.c
peerlookup.h
queueing.c wireguard: queueing: cleanup ptr_ring in error path of packet_queue_init 2020-04-29 14:23:05 -07:00
queueing.h wireguard: queueing: preserve flow hash across packet scrubbing 2020-05-20 20:55:09 -07:00
ratelimiter.c
ratelimiter.h
receive.c wireguard: noise: separate receive counter from send counter 2020-05-20 20:55:09 -07:00
send.c wireguard: noise: separate receive counter from send counter 2020-05-20 20:55:09 -07:00
socket.c wireguard: socket: remove errant restriction on looping to self 2020-05-06 20:03:47 -07:00
socket.h
timers.c
timers.h
version.h