aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/selftest (follow)
Commit message (Collapse)AuthorAgeFilesLines
* allowedips: free empty intermediate nodes when removing single nodeJason A. Donenfeld2021-06-041-85/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* allowedips: initialize list head in selftestJason A. Donenfeld2021-06-041-1/+2
| | | | | | | | | | | | The randomized trie tests weren't initializing the dummy peer list head, resulting in a NULL pointer dereference when used. Fix this by initializing it in the randomized trie test, just like we do for the static unit test. While we're at it, all of the other strings like this have the word "self-test", so add it to the missing place here. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* noise: separate receive counter from send counterJason A. Donenfeld2020-05-191-5/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In "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. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* selftests: initalize ipv6 members to NULL to squelch clang warningJason A. Donenfeld2020-05-051-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Without setting these to NULL, clang complains in certain configurations that have CONFIG_IPV6=n: In file included from drivers/net/wireguard/ratelimiter.c:223: drivers/net/wireguard/selftest/ratelimiter.c:173:34: error: variable 'skb6' is uninitialized when used here [-Werror,-Wuninitialized] ret = timings_test(skb4, hdr4, skb6, hdr6, &test_count); ^~~~ drivers/net/wireguard/selftest/ratelimiter.c:123:29: note: initialize the variable 'skb6' to silence this warning struct sk_buff *skb4, *skb6; ^ = NULL drivers/net/wireguard/selftest/ratelimiter.c:173:40: error: variable 'hdr6' is uninitialized when used here [-Werror,-Wuninitialized] ret = timings_test(skb4, hdr4, skb6, hdr6, &test_count); ^~~~ drivers/net/wireguard/selftest/ratelimiter.c:125:22: note: initialize the variable 'hdr6' to silence this warning struct ipv6hdr *hdr6; ^ We silence this warning by setting the variables to NULL as the warning suggests. Reported-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* allowedips: avoid double lock in selftest error caseJason A. Donenfeld2019-11-261-8/+9
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* allowedips: maintain per-peer list of allowedipsJason A. Donenfeld2019-02-261-50/+43
| | | | | | | | | | This makes `wg show` and `wg showconf` and the like significantly faster, since we don't have to iterate through every node of the trie for every single peer. It also makes netlink cursor resumption much less problematic, since we're just iterating through a list, rather than having to save a traversal stack. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* ratelimiter: build tests with !IPV6Jason A. Donenfeld2019-01-231-5/+2
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: update copyrightJason A. Donenfeld2019-01-073-3/+3
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* allowedips: fix sparse warnings in optional selftestsJason A. Donenfeld2018-10-271-12/+14
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: give if statements brackets and other cleanupsJason A. Donenfeld2018-10-091-2/+4
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* allowedips: remove control statement from macro by rewritingJason A. Donenfeld2018-10-081-67/+118
| | | | | | | | This is a significant rearrangement that makes things less clear, to satisfy a checkpatch.pl requirement. Suggested-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: more nitsJason A. Donenfeld2018-10-082-37/+35
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: rename struct wireguard_ to struct wg_Jason A. Donenfeld2018-10-081-3/+3
| | | | | | | This required a bit of pruning of our christmas trees. Suggested-by: Jiri Pirko <jiri@resnulli.us> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: prefix functions used in callbacks with wg_Jason A. Donenfeld2018-10-081-2/+2
| | | | | Suggested-by: Jiri Pirko <jiri@resnulli.us> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: style nitsJason A. Donenfeld2018-10-073-29/+26
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* allowedips: document additional nobsJason A. Donenfeld2018-10-071-0/+12
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: rename include'd C files to be .cJason A. Donenfeld2018-10-063-3/+3
| | | | | | | | | | This is done by 259 other files in the kernel tree: linux $ rg '#include.*\.c' -l | wc -l 259 Suggested-by: Sultan Alsawaf <sultanxda@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* allowedips: remove ifdefs in favor of IS_ENABLEDJason A. Donenfeld2018-10-061-20/+30
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* ratelimiter: prefer IS_ENABLEDJason A. Donenfeld2018-10-021-3/+2
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: prefix all functions with wg_Jason A. Donenfeld2018-10-023-44/+51
| | | | | | | | | | | | | | I understand why this must be done, though I'm not so happy about having to do it. In some places, it puts us over 80 chars and we have to break lines up in further ugly ways. And in general, I think this makes things harder to read. Yet another thing we must do to please upstream. Maybe this can be replaced in the future by some kind of automatic module namespacing logic in the linker, or even combined with LTO and aggressive symbol stripping. Suggested-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* allowedips: work around kasan stack frame bug in selftestJason A. Donenfeld2018-09-231-2/+9
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: put SPDX identifier on its own lineJason A. Donenfeld2018-09-203-6/+6
| | | | | | | The kernel has very specific rules correlating file type with comment type, and also SPDX identifiers can't be merged with other comments. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* ratelimiter: disable selftest with KASANJason A. Donenfeld2018-09-201-0/+4
| | | | | | | | | This this relies on instructions taking a "normal" amount of time, we really can't run this with KASAN, especially inside QEMU, so just disable it for KASAN, since it's hard to make it complete on slow systems. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* allowedips: change from BUG_ON to WARN_ONJason A. Donenfeld2018-09-201-1/+1
| | | | | | | | | This is never going to hit anyway, and if it does, it's a development problem that will be caught with the selftests anyway. So don't make Andrew Lunn upset, and just change it to a WARN_ON. Suggested-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: always find OOM unlikelyJason A. Donenfeld2018-09-042-7/+7
| | | | | Suggested-by: Sultan Alsawaf <sultanxda@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: prefer sizeof(*pointer) when possibleJason A. Donenfeld2018-09-042-9/+7
| | | | | Suggested-by: Sultan Alsawaf <sultanxda@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* crypto: import zincJason A. Donenfeld2018-09-034-7091/+0
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* crypto: use unaligned helpersJason A. Donenfeld2018-08-281-7/+7
| | | | | | | | This is not useful for WireGuard, but for the general use case we probably want it this way, and the speed difference is mostly lost in the noise. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: run through clang-formatJason A. Donenfeld2018-08-283-123/+216
| | | | | | | | | This is the worst commit in the whole repo, making the code much less readable, but so it goes with upstream maintainers. We are now woefully wrapped at 80 columns. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* chacha20poly1305: selftest: use arrays for test vectorsJason A. Donenfeld2018-08-061-777/+3577
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* crypto: move simd context to specific typeJason A. Donenfeld2018-08-062-37/+35
| | | | | Suggested-by: Andy Lutomirski <luto@kernel.org> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* chacha20poly1305: selftest: split up test vector constantsJason A. Donenfeld2018-07-311-69/+210
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* main: add missing chacha20poly1305 headerJason A. Donenfeld2018-07-311-1/+0
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* selftest: ratelimiter: improve chance of success via retryJason A. Donenfeld2018-07-061-1/+6
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* ratelimiter: mitigate reference underflowJason A. Donenfeld2018-06-191-0/+2
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* simd: encapsulate fpu amortization into nice functionsJason A. Donenfeld2018-06-172-8/+9
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* chacha20poly1305: test for authtag failureJason A. Donenfeld2018-05-311-3/+21
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* chacha20poly1305: test scattergather functions tooJason A. Donenfeld2018-05-311-2/+44
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* chacha20poly1305: combine stack variables into unionJason A. Donenfeld2018-05-311-8/+11
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* chacha20poly1305: split up into separate filesJason A. Donenfeld2018-05-312-10/+11
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* allowedips: Fix graphviz output after endianness patchJonathan Neuschäfer2018-05-141-3/+16
| | | | | | | | | | | | | Commit 5e3532e ("allowedips: use native endian on lookup") did two things: It changed the endianness of (struct allowedips_node).bits to native endian, and it moved the CIDR masking to the output code path (walk_by_peer). Adjust print_node in src/selftest/allowedips.h to deal with these changes. Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* allowedips: add selftest for allowedips_walk_by_peerJason A. Donenfeld2018-05-101-1/+60
| | | | | | | Also we satisfy lockdep here. Suggested-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* chacha20poly1305: put magic constant behind macroJason A. Donenfeld2018-04-051-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* chacha20poly1305: add self tests from wycheproofJason A. Donenfeld2018-04-051-3/+1026
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* curve25519: add self tests from wycheproofJason A. Donenfeld2018-04-041-0/+504
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* poly1305: fix up selftest counterJason A. Donenfeld2018-02-081-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* curve25519: break more things with more test casesJason A. Donenfeld2018-02-011-0/+12
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* curve25519: verify that specialized basepoint implementations are correctJason A. Donenfeld2018-02-011-3/+17
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* poly1305: add poly-specific self-testsJason A. Donenfeld2018-01-191-0/+1566
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: year bumpJason A. Donenfeld2018-01-036-6/+6
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>