All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net 0/4] wireguard patches for 5.18-rc1
@ 2022-03-30  1:31 Jason A. Donenfeld
  2022-03-30  1:31 ` [PATCH net 1/4] wireguard: queueing: use CFI-safe ptr_ring cleanup function Jason A. Donenfeld
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Jason A. Donenfeld @ 2022-03-30  1:31 UTC (permalink / raw)
  To: netdev, davem, kuba; +Cc: Jason A. Donenfeld

Hi Dave/Jakub,

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.

The relevant commits have stable@ and fixes tags.

Thanks,
Jason


Jason A. Donenfeld (3):
  wireguard: queueing: use CFI-safe ptr_ring cleanup function
  wireguard: selftests: simplify RNG seeding
  wireguard: socket: ignore v6 endpoints when ipv6 is disabled

Wang Hai (1):
  wireguard: socket: free skb in send6 when ipv6 is disabled

 drivers/net/wireguard/queueing.c              |  3 ++-
 drivers/net/wireguard/socket.c                |  5 ++--
 tools/testing/selftests/wireguard/qemu/init.c | 26 +++++--------------
 3 files changed, 12 insertions(+), 22 deletions(-)

-- 
2.35.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net 1/4] wireguard: queueing: use CFI-safe ptr_ring cleanup function
  2022-03-30  1:31 [PATCH net 0/4] wireguard patches for 5.18-rc1 Jason A. Donenfeld
@ 2022-03-30  1:31 ` Jason A. Donenfeld
  2022-03-30  1:31 ` [PATCH net 2/4] wireguard: selftests: simplify RNG seeding Jason A. Donenfeld
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Jason A. Donenfeld @ 2022-03-30  1:31 UTC (permalink / raw)
  To: netdev, davem, kuba; +Cc: Jason A. Donenfeld, PaX Team, stable

We make too nuanced use of ptr_ring to entirely move to the skb_array
wrappers, but we at least should avoid the naughty function pointer cast
when cleaning up skbs. Otherwise RAP/CFI will honk at us. This patch
uses the __skb_array_destroy_skb wrapper for the cleanup, rather than
directly providing kfree_skb, which is what other drivers in the same
situation do too.

Reported-by: PaX Team <pageexec@freemail.hu>
Fixes: 886fcee939ad ("wireguard: receive: use ring buffer for incoming handshakes")
Cc: stable@vger.kernel.org
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/net/wireguard/queueing.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireguard/queueing.c b/drivers/net/wireguard/queueing.c
index 1de413b19e34..8084e7408c0a 100644
--- a/drivers/net/wireguard/queueing.c
+++ b/drivers/net/wireguard/queueing.c
@@ -4,6 +4,7 @@
  */
 
 #include "queueing.h"
+#include <linux/skb_array.h>
 
 struct multicore_worker __percpu *
 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)
 {
 	free_percpu(queue->worker);
 	WARN_ON(!purge && !__ptr_ring_empty(&queue->ring));
-	ptr_ring_cleanup(&queue->ring, purge ? (void(*)(void*))kfree_skb : NULL);
+	ptr_ring_cleanup(&queue->ring, purge ? __skb_array_destroy_skb : NULL);
 }
 
 #define NEXT(skb) ((skb)->prev)
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net 2/4] wireguard: selftests: simplify RNG seeding
  2022-03-30  1:31 [PATCH net 0/4] wireguard patches for 5.18-rc1 Jason A. Donenfeld
  2022-03-30  1:31 ` [PATCH net 1/4] wireguard: queueing: use CFI-safe ptr_ring cleanup function Jason A. Donenfeld
@ 2022-03-30  1:31 ` Jason A. Donenfeld
  2022-03-30  1:31 ` [PATCH net 3/4] wireguard: socket: free skb in send6 when ipv6 is disabled Jason A. Donenfeld
  2022-03-30  1:31 ` [PATCH net 4/4] wireguard: socket: ignore v6 endpoints " Jason A. Donenfeld
  3 siblings, 0 replies; 5+ messages in thread
From: Jason A. Donenfeld @ 2022-03-30  1:31 UTC (permalink / raw)
  To: netdev, davem, kuba; +Cc: Jason A. Donenfeld

The seed_rng() function was written to work across lots of old kernels,
back when WireGuard used a big compatibility layer. Now that things have
evolved, we can vastly simplify this, by just marking the RNG as seeded.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 tools/testing/selftests/wireguard/qemu/init.c | 26 +++++--------------
 1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/tools/testing/selftests/wireguard/qemu/init.c b/tools/testing/selftests/wireguard/qemu/init.c
index c9698120ac9d..0b45055d9de0 100644
--- a/tools/testing/selftests/wireguard/qemu/init.c
+++ b/tools/testing/selftests/wireguard/qemu/init.c
@@ -56,26 +56,14 @@ static void print_banner(void)
 
 static void seed_rng(void)
 {
-	int fd;
-	struct {
-		int entropy_count;
-		int buffer_size;
-		unsigned char buffer[256];
-	} entropy = {
-		.entropy_count = sizeof(entropy.buffer) * 8,
-		.buffer_size = sizeof(entropy.buffer),
-		.buffer = "Adding real entropy is not actually important for these tests. Don't try this at home, kids!"
-	};
+	int bits = 256, fd;
 
-	if (mknod("/dev/urandom", S_IFCHR | 0644, makedev(1, 9)))
-		panic("mknod(/dev/urandom)");
-	fd = open("/dev/urandom", O_WRONLY);
+	pretty_message("[+] Fake seeding RNG...");
+	fd = open("/dev/random", O_WRONLY);
 	if (fd < 0)
-		panic("open(urandom)");
-	for (int i = 0; i < 256; ++i) {
-		if (ioctl(fd, RNDADDENTROPY, &entropy) < 0)
-			panic("ioctl(urandom)");
-	}
+		panic("open(random)");
+	if (ioctl(fd, RNDADDTOENTCNT, &bits) < 0)
+		panic("ioctl(RNDADDTOENTCNT)");
 	close(fd);
 }
 
@@ -270,10 +258,10 @@ static void check_leaks(void)
 
 int main(int argc, char *argv[])
 {
-	seed_rng();
 	ensure_console();
 	print_banner();
 	mount_filesystems();
+	seed_rng();
 	kmod_selftests();
 	enable_logging();
 	clear_leaks();
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net 3/4] wireguard: socket: free skb in send6 when ipv6 is disabled
  2022-03-30  1:31 [PATCH net 0/4] wireguard patches for 5.18-rc1 Jason A. Donenfeld
  2022-03-30  1:31 ` [PATCH net 1/4] wireguard: queueing: use CFI-safe ptr_ring cleanup function Jason A. Donenfeld
  2022-03-30  1:31 ` [PATCH net 2/4] wireguard: selftests: simplify RNG seeding Jason A. Donenfeld
@ 2022-03-30  1:31 ` Jason A. Donenfeld
  2022-03-30  1:31 ` [PATCH net 4/4] wireguard: socket: ignore v6 endpoints " Jason A. Donenfeld
  3 siblings, 0 replies; 5+ messages in thread
From: Jason A. Donenfeld @ 2022-03-30  1:31 UTC (permalink / raw)
  To: netdev, davem, kuba; +Cc: Wang Hai, stable, Jason A . Donenfeld

From: Wang Hai <wanghai38@huawei.com>

I got a memory leak report:

unreferenced object 0xffff8881191fc040 (size 232):
  comm "kworker/u17:0", pid 23193, jiffies 4295238848 (age 3464.870s)
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace:
    [<ffffffff814c3ef4>] slab_post_alloc_hook+0x84/0x3b0
    [<ffffffff814c8977>] kmem_cache_alloc_node+0x167/0x340
    [<ffffffff832974fb>] __alloc_skb+0x1db/0x200
    [<ffffffff82612b5d>] wg_socket_send_buffer_to_peer+0x3d/0xc0
    [<ffffffff8260e94a>] wg_packet_send_handshake_initiation+0xfa/0x110
    [<ffffffff8260ec81>] wg_packet_handshake_send_worker+0x21/0x30
    [<ffffffff8119c558>] process_one_work+0x2e8/0x770
    [<ffffffff8119ca2a>] worker_thread+0x4a/0x4b0
    [<ffffffff811a88e0>] kthread+0x120/0x160
    [<ffffffff8100242f>] ret_from_fork+0x1f/0x30

In function wg_socket_send_buffer_as_reply_to_skb() or wg_socket_send_
buffer_to_peer(), the semantics of send6() is required to free skb. But
when CONFIG_IPV6 is disable, kfree_skb() is missing. This patch adds it
to fix this bug.

Signed-off-by: Wang Hai <wanghai38@huawei.com>
Fixes: e7096c131e51 ("net: WireGuard secure network tunnel")
Cc: stable@vger.kernel.org
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/net/wireguard/socket.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/wireguard/socket.c b/drivers/net/wireguard/socket.c
index 6f07b949cb81..467eef0e563b 100644
--- a/drivers/net/wireguard/socket.c
+++ b/drivers/net/wireguard/socket.c
@@ -160,6 +160,7 @@ static int send6(struct wg_device *wg, struct sk_buff *skb,
 	rcu_read_unlock_bh();
 	return ret;
 #else
+	kfree_skb(skb);
 	return -EAFNOSUPPORT;
 #endif
 }
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net 4/4] wireguard: socket: ignore v6 endpoints when ipv6 is disabled
  2022-03-30  1:31 [PATCH net 0/4] wireguard patches for 5.18-rc1 Jason A. Donenfeld
                   ` (2 preceding siblings ...)
  2022-03-30  1:31 ` [PATCH net 3/4] wireguard: socket: free skb in send6 when ipv6 is disabled Jason A. Donenfeld
@ 2022-03-30  1:31 ` Jason A. Donenfeld
  3 siblings, 0 replies; 5+ messages in thread
From: Jason A. Donenfeld @ 2022-03-30  1:31 UTC (permalink / raw)
  To: netdev, davem, kuba; +Cc: Jason A. Donenfeld, stable

The previous commit fixed a memory leak on the send path in the event
that IPv6 is disabled at compile time, but how did a packet even arrive
there to begin with? It turns out we have previously allowed IPv6
endpoints even when IPv6 support is disabled at compile time. This is
awkward and inconsistent. Instead, let's just ignore all things IPv6,
the same way we do other malformed endpoints, in the case where IPv6 is
disabled.

Fixes: e7096c131e51 ("net: WireGuard secure network tunnel")
Cc: stable@vger.kernel.org
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/net/wireguard/socket.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireguard/socket.c b/drivers/net/wireguard/socket.c
index 467eef0e563b..0414d7a6ce74 100644
--- a/drivers/net/wireguard/socket.c
+++ b/drivers/net/wireguard/socket.c
@@ -242,7 +242,7 @@ int wg_socket_endpoint_from_skb(struct endpoint *endpoint,
 		endpoint->addr4.sin_addr.s_addr = ip_hdr(skb)->saddr;
 		endpoint->src4.s_addr = ip_hdr(skb)->daddr;
 		endpoint->src_if4 = skb->skb_iif;
-	} else if (skb->protocol == htons(ETH_P_IPV6)) {
+	} else if (IS_ENABLED(CONFIG_IPV6) && skb->protocol == htons(ETH_P_IPV6)) {
 		endpoint->addr6.sin6_family = AF_INET6;
 		endpoint->addr6.sin6_port = udp_hdr(skb)->source;
 		endpoint->addr6.sin6_addr = ipv6_hdr(skb)->saddr;
@@ -285,7 +285,7 @@ void wg_socket_set_peer_endpoint(struct wg_peer *peer,
 		peer->endpoint.addr4 = endpoint->addr4;
 		peer->endpoint.src4 = endpoint->src4;
 		peer->endpoint.src_if4 = endpoint->src_if4;
-	} else if (endpoint->addr.sa_family == AF_INET6) {
+	} else if (IS_ENABLED(CONFIG_IPV6) && endpoint->addr.sa_family == AF_INET6) {
 		peer->endpoint.addr6 = endpoint->addr6;
 		peer->endpoint.src6 = endpoint->src6;
 	} else {
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-03-30  1:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-30  1:31 [PATCH net 0/4] wireguard patches for 5.18-rc1 Jason A. Donenfeld
2022-03-30  1:31 ` [PATCH net 1/4] wireguard: queueing: use CFI-safe ptr_ring cleanup function Jason A. Donenfeld
2022-03-30  1:31 ` [PATCH net 2/4] wireguard: selftests: simplify RNG seeding Jason A. Donenfeld
2022-03-30  1:31 ` [PATCH net 3/4] wireguard: socket: free skb in send6 when ipv6 is disabled Jason A. Donenfeld
2022-03-30  1:31 ` [PATCH net 4/4] wireguard: socket: ignore v6 endpoints " Jason A. Donenfeld

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.