Commit Graph

1297 Commits

Author SHA1 Message Date
Jason A. Donenfeld fdd99220e9 Kbuild: move module deps out of tests/
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-08-03 13:46:36 +02:00
Jason A. Donenfeld a77d553a3a selftest: move to subfolder
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-08-02 18:19:20 +02:00
Jason A. Donenfeld 13e89d4860 contrib: move patchers to contrib/kernel-tree
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-08-02 02:55:43 +02:00
Jason A. Donenfeld 427773bb17 Makefile: check tools as part of make check
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-08-02 02:55:42 +02:00
Jason A. Donenfeld 650a68f646 uapi: typeof is not necessary
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-08-02 02:55:42 +02:00
Jason A. Donenfeld 598f4c8542 c: specify static array size in function params
The C standard states:

  A declaration of a parameter as ``array of type'' shall be adjusted to ``qualified pointer to
  type'', where the type qualifiers (if any) are those specified within the [ and ] of the
  array type derivation. If the keyword static also appears within the [ and ] of the
  array type derivation, then for each call to the function, the value of the corresponding
  actual argument shall provide access to the first element of an array with at least as many
  elements as specified by the size expression.

By changing void func(int array[4]) to void func(int array[static 4]),
we automatically get the compiler checking argument sizes for us, which
is quite nice.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-08-02 02:55:42 +02:00
Jason A. Donenfeld cc605ab76a timers: use more clear pow macro
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-08-02 02:55:42 +02:00
Jason A. Donenfeld 7ac9f91951 ratelimiter: correct comment
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-23 12:41:39 +02:00
Jason A. Donenfeld 6766d7fbba timers: upstream removed the slack concept
No longer do we specify slack ourselves. Instead we need to add it
directly in the main scheduling.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-23 00:58:05 +02:00
Jason A. Donenfeld 2d8170c259 tools: Use seqpacket instead of dgram
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-22 20:30:34 +02:00
Jason A. Donenfeld d23fe2901d index hashtable: run random indices through siphash
If /dev/urandom is a NOBUS RNG backdoor, like the infamous Dual_EC_DRBG,
then sending 4 bytes of raw RNG output over the wire directly might not
be such a great idea. This mitigates that vulnerability by, at some
point before the indices are generated, creating a random secret. Then,
for each session index, we simply run SipHash24 on an incrementing
counter.

This is probably overkill because /dev/urandom is probably not a
backdoored RNG, and itself already uses several rounds of SHA-1 for
mixing. If the kernel RNG is backdoored, there may very well be
bigger problems at play. Four bytes is also not so many bytes.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-22 16:48:51 +02:00
Jason A. Donenfeld 82831962b8 cookie: do not expose csprng directly
It may not be wise to directly publish the output of the CSPRNG, so we
run the output through a round of Blake2s first.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-22 15:17:15 +02:00
Jason A. Donenfeld 8ac1ced115 socket: fix compat for 4.1 v6 sockets
It turns out 4.1 is even more broken than expected. While both 4.1 and
4.2 need to jigger the sysctl nob temporarily, it turns out that in 4.1
it's looking in the wrong namespace for the nob value. So, we have to
account for the different namespace semantics in the different versions.
Super ugly. But, all this code goes away once we upstream.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-22 14:27:43 +02:00
Jason A. Donenfeld 6a8ab6827e socket: reset IPv4 socket to NULL after free
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-21 17:20:38 +02:00
Jason A. Donenfeld 29a29f1343 socket: simpler debug message
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-21 17:18:19 +02:00
Jason A. Donenfeld e03350e0a4 Kconfig: select IP6_NF_IPTABLES if using IPV6
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-21 11:40:01 +02:00
Jason A. Donenfeld db51f00a1d tools: first additions of userspace integration
This is designed to work with a server that follows this:

  struct sockaddr_un addr = {
      .sun_family = AF_UNIX,
      .sun_path = "/var/run/wireguard/wguserspace0.sock"
  };
  int fd, ret;
  ssize_t len;
  socklen_t socklen;
  struct wgdevice *device;

  fd = socket(AF_UNIX, SOCK_DGRAM, 0);
  if (fd < 0)
      exit(1);
  if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
      exit(1);

  for (;;) {
      /* First we look at how big the next message is, so we know how much to
       * allocate. Note on BSD you can instead use ioctl(fd, FIONREAD, &len). */
      len = recv(fd, NULL, 0, MSG_PEEK | MSG_TRUNC);
      if (len < 0) {
          handle_error();
          continue;
      }
      /* Next we allocate a buffer for the received data. */
      device = NULL;
      if (len) {
          device = malloc(len);
          if (!device) {
              handle_error();
              continue;
          }
      }
      /* Finally we receive the data, storing too the return address. */
      socklen = sizeof(addr);
      len = recvfrom(fd, device, len, 0, (struct sockaddr *)&addr, (socklen_t *)&socklen);
      if (len < 0) {
          handle_error();
          free(device);
          continue;
      }
      if (!len) { /* If len is zero, it's a "get" request, so we send our device back. */
          device = get_current_wireguard_device(&len);
          sendto(fd, device, len, 0, (struct sockaddr *)&addr, socklen);
      } else { /* Otherwise, we just received a wgdevice, so we should "set" and send back the return status. */
          ret = set_current_wireguard_device(device);
          sendto(fd, &ret, sizeof(ret), 0, (struct sockaddr *)&addr, socklen);
          free(device);
      }
  }

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-20 22:04:56 +02:00
Jason A. Donenfeld f650e11c1e build system: revamp building and configuration
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-18 03:41:57 +02:00
Jason A. Donenfeld ab013cc1ad tests: improve test suite and add qemu tester
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-18 03:41:57 +02:00
Jason A. Donenfeld ea6d4a5cad receive: assume we usually succeed with userspace
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-10 21:44:38 +02:00
Jason A. Donenfeld 5ee298c4fe receive: no need to test for !len
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-10 21:44:38 +02:00
Jason A. Donenfeld e9ccb85445 timers: apply slack to hotpath timers
For timers in the hotpath, we don't want them to be rescheduled so
aggressively, and since they don't need to be that precise, we can set a
decent amount of slack.

With the persistent keepalive timer, we have something of a special
case. Since the timeout isn't fixed like the others, we don't want to
make it more often than the kernel ordinarily would. So, instead, we
make it a minimum.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-10 21:44:38 +02:00
Jason A. Donenfeld 45092f8fb2 timers: move timer calls out of hot loop
We sacrifice a little bit of precision here, but this avoids jockeying
around the timers for every packet, when we're sending in bundles anyway
to minimize cache misses.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-10 20:24:26 +02:00
Jason A. Donenfeld c60e34aa2c timers: document conditions for calling
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-10 12:54:02 +02:00
Jason A. Donenfeld c4c3a558a1 persistent keepalive: use unsigned long to avoid multiplication in hotpath
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-10 03:46:56 +02:00
Jason A. Donenfeld 2e1bceea13 persistent keepalive: use authenticated keepalives
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-10 03:46:56 +02:00
Jason A. Donenfeld 4a5231e2ba keepalives: only queue keepalive when queue is empty
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-08 23:55:23 +02:00
Jason A. Donenfeld bcce73b296 timers: do not consider keepalives to be data sent
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-08 20:45:32 +02:00
Jason A. Donenfeld 8a4a28ebed timers: rename *authorized* functions to *authenticated*
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-08 20:30:57 +02:00
Jason A. Donenfeld fcd889b205 persistent keepalive: start sending immediately
Rather than only start sending the persistent keepalive packets when the
device first sends data, this changes it to send the packets immediately
on `ip link set up`. This makes things generally seem more stateless,
since the administrator does not have to manually ping the endpoint.

Of course, if you have a lot of peers and all of them have persistent
keepalive enabled, this could cause a lot of unwanted immediate traffic.
On the other hand, if all of those peers are at some point going to be
sending packets, this would happen anyway. I suppose the moral of the
story is that persistent keepalive is a feature really just for clients
behind NAT, not for servers, and it should be used sparingly, which is
why we've set it off by default in the first place.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-08 14:28:15 +02:00
Jason A. Donenfeld d6c566c92a persistent keepalive: add kernel mechanism
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-08 02:29:38 +02:00
Jason A. Donenfeld a79e13c554 curve25519: unneeded zeros variable
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-07 03:40:35 +02:00
Jason A. Donenfeld d62fa841bd device: move unlikely check to if clause
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-05 21:13:53 +02:00
Jason A. Donenfeld 6bb01a673d receive: protect against impossible conditions
It should never be the case that skb->head + skb->transport_header -
skb->data is greater than 2^16, but in case the kernel network stack
borks this at some point in the future, we don't want this to slyly
introduce a vulnerability into WireGuard.

Further, really smart compilers might be able to make deductions about
data_offset, and optimize accordingly.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-03 22:04:51 +02:00
Jason A. Donenfeld 79d5e05cc8 tai64n: don't forget to add 2^62, to be in spec
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-02 03:22:34 +02:00
Jason A. Donenfeld d172fddcd5 receive: error conditions are unlikely
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-01 04:01:40 +02:00
Jason A. Donenfeld dcf5fd4513 Readme: the documentation moved to .io
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-06-30 21:45:42 +02:00
Daniel Kahn Gillmor 662128e5b9 Readme: use https instead of http
For the websites referenced that offer https instead of http, use
https.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-06-30 20:48:12 +02:00
Jason A. Donenfeld d4ee6b8c53 Makefile: Add more verbose dependency errors
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-06-30 04:13:55 +02:00
Jason A. Donenfeld 8c9b847669 device init: free wq after padata
The padata free functions make reference to their parent workqueue, so
it's important that we wait to free the workqueue after the padata.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-06-30 02:58:39 +02:00
Jason A. Donenfeld 49668ee002 chacha20poly1305: use more standard way of testing FPU features
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-06-29 23:15:30 +02:00
Jason A. Donenfeld 5a137558a6 device: remove updating of trans_start
Per http://lists.openwall.net/netdev/2016/05/03/87 dev->trans_start has
been removed, and updates are now supposed to be handled with
netif_trans_update, which now updates the particular txqueue's
trans_start instead.

However, netdev_start_xmit already updates this member after calling
ndo_start_xmit, so the new netif_trans_update function smartly makes the
comment that for drivers that don't use LLTX, it's not neccessary to
call netif_trans_update.

Except we do use LLTX, so it would seem again that we do need to be
calling netif_trans_update. However, glancing at drivers like vxlan and
other similar virtual tunnels, this doesn't seem to be the case. I
suspect the reason is that we both also set IFF_NO_QUEUE, so we aren't
even using a txqueue for updating.

Thus, this patch removes updating of trans_start all together. I believe
this should be okay for older kernels too.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-06-29 22:46:45 +02:00
Jason A. Donenfeld 1a9406e232 Kconfig patching: do not match on NETFILTER
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-06-29 22:27:41 +02:00
Jason A. Donenfeld 8ab00aff6b Kconfig: more fully select dependencies
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-06-29 04:41:01 +02:00
Jason A. Donenfeld c0566bb9e9 tests: make fatal
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-06-25 16:48:39 +02:00
Jason A. Donenfeld e20c4c14e6 nonce: switch to RFC6479 to better support packet reordering
With packets hitting multiple cores, a 64bit backtrack was too small.
This algorithm increases our backtrack to 1984bits.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-06-25 16:48:39 +02:00
Jason A. Donenfeld b448d6f35b Initial commit
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-06-25 16:48:39 +02:00