Skip to content

Commit 1f686f2

Browse files
committed
Merge branch 'wireguard-patches-for-5-18-rc1'
Jason A. Donenfeld says: ==================== wireguard patches for 5.18-rc1 Here's a small set of fixes for the next net push: 1) Pipacs reported a CFI violation in a cleanup routine, which he triggered using grsec's RAP. I haven't seen reports of this yet from the Android/CFI world yet, but it's only a matter of time there. 2) A small rng cleanup to the self test harness to make it initialize faster on 5.18. 3) Wang reported and fixed a skb leak for CONFIG_IPV6=n. 4) After Wang's fix for the direct leak, I investigated how that code path even could be hit, and found that the netlink layer still handles IPv6 endpoints, when it probably shouldn't. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents c9ad266 + 77fc73a commit 1f686f2

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

drivers/net/wireguard/queueing.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include "queueing.h"
7+
#include <linux/skb_array.h>
78

89
struct multicore_worker __percpu *
910
wg_packet_percpu_multicore_worker_alloc(work_func_t function, void *ptr)
@@ -42,7 +43,7 @@ void wg_packet_queue_free(struct crypt_queue *queue, bool purge)
4243
{
4344
free_percpu(queue->worker);
4445
WARN_ON(!purge && !__ptr_ring_empty(&queue->ring));
45-
ptr_ring_cleanup(&queue->ring, purge ? (void(*)(void*))kfree_skb : NULL);
46+
ptr_ring_cleanup(&queue->ring, purge ? __skb_array_destroy_skb : NULL);
4647
}
4748

4849
#define NEXT(skb) ((skb)->prev)

drivers/net/wireguard/socket.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ static int send6(struct wg_device *wg, struct sk_buff *skb,
160160
rcu_read_unlock_bh();
161161
return ret;
162162
#else
163+
kfree_skb(skb);
163164
return -EAFNOSUPPORT;
164165
#endif
165166
}
@@ -241,7 +242,7 @@ int wg_socket_endpoint_from_skb(struct endpoint *endpoint,
241242
endpoint->addr4.sin_addr.s_addr = ip_hdr(skb)->saddr;
242243
endpoint->src4.s_addr = ip_hdr(skb)->daddr;
243244
endpoint->src_if4 = skb->skb_iif;
244-
} else if (skb->protocol == htons(ETH_P_IPV6)) {
245+
} else if (IS_ENABLED(CONFIG_IPV6) && skb->protocol == htons(ETH_P_IPV6)) {
245246
endpoint->addr6.sin6_family = AF_INET6;
246247
endpoint->addr6.sin6_port = udp_hdr(skb)->source;
247248
endpoint->addr6.sin6_addr = ipv6_hdr(skb)->saddr;
@@ -284,7 +285,7 @@ void wg_socket_set_peer_endpoint(struct wg_peer *peer,
284285
peer->endpoint.addr4 = endpoint->addr4;
285286
peer->endpoint.src4 = endpoint->src4;
286287
peer->endpoint.src_if4 = endpoint->src_if4;
287-
} else if (endpoint->addr.sa_family == AF_INET6) {
288+
} else if (IS_ENABLED(CONFIG_IPV6) && endpoint->addr.sa_family == AF_INET6) {
288289
peer->endpoint.addr6 = endpoint->addr6;
289290
peer->endpoint.src6 = endpoint->src6;
290291
} else {

tools/testing/selftests/wireguard/qemu/init.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,14 @@ static void print_banner(void)
5656

5757
static void seed_rng(void)
5858
{
59-
int fd;
60-
struct {
61-
int entropy_count;
62-
int buffer_size;
63-
unsigned char buffer[256];
64-
} entropy = {
65-
.entropy_count = sizeof(entropy.buffer) * 8,
66-
.buffer_size = sizeof(entropy.buffer),
67-
.buffer = "Adding real entropy is not actually important for these tests. Don't try this at home, kids!"
68-
};
59+
int bits = 256, fd;
6960

70-
if (mknod("/dev/urandom", S_IFCHR | 0644, makedev(1, 9)))
71-
panic("mknod(/dev/urandom)");
72-
fd = open("/dev/urandom", O_WRONLY);
61+
pretty_message("[+] Fake seeding RNG...");
62+
fd = open("/dev/random", O_WRONLY);
7363
if (fd < 0)
74-
panic("open(urandom)");
75-
for (int i = 0; i < 256; ++i) {
76-
if (ioctl(fd, RNDADDENTROPY, &entropy) < 0)
77-
panic("ioctl(urandom)");
78-
}
64+
panic("open(random)");
65+
if (ioctl(fd, RNDADDTOENTCNT, &bits) < 0)
66+
panic("ioctl(RNDADDTOENTCNT)");
7967
close(fd);
8068
}
8169

@@ -270,10 +258,10 @@ static void check_leaks(void)
270258

271259
int main(int argc, char *argv[])
272260
{
273-
seed_rng();
274261
ensure_console();
275262
print_banner();
276263
mount_filesystems();
264+
seed_rng();
277265
kmod_selftests();
278266
enable_logging();
279267
clear_leaks();

0 commit comments

Comments
 (0)