Miroslav Franc b65b67
From: Pietro Borrello <borrello@diag.uniroma1.it>
Miroslav Franc b65b67
Date: Sat, 4 Feb 2023 17:39:22 +0000
Miroslav Franc b65b67
Subject: tap: tap_open(): correctly initialize socket uid
Miroslav Franc b65b67
Git-commit: 66b2c338adce580dfce2199591e65e2bab889cff
Miroslav Franc b65b67
Patch-mainline: v6.3-rc1
Miroslav Franc b65b67
References: CVE-2023-1076 bsc#1208599
Miroslav Franc b65b67
Miroslav Franc b65b67
sock_init_data() assumes that the `struct socket` passed in input is
Miroslav Franc b65b67
contained in a `struct socket_alloc` allocated with sock_alloc().
Miroslav Franc b65b67
However, tap_open() passes a `struct socket` embedded in a `struct
Miroslav Franc b65b67
tap_queue` allocated with sk_alloc().
Miroslav Franc b65b67
This causes a type confusion when issuing a container_of() with
Miroslav Franc b65b67
SOCK_INODE() in sock_init_data() which results in assigning a wrong
Miroslav Franc b65b67
sk_uid to the `struct sock` in input.
Miroslav Franc b65b67
On default configuration, the type confused field overlaps with
Miroslav Franc b65b67
padding bytes between `int vnet_hdr_sz` and `struct tap_dev __rcu
Miroslav Franc b65b67
*tap` in `struct tap_queue`, which makes the uid of all tap sockets 0,
Miroslav Franc b65b67
i.e., the root one.
Miroslav Franc b65b67
Fix the assignment by using sock_init_data_uid().
Miroslav Franc b65b67
Miroslav Franc b65b67
Fixes: 86741ec25462 ("net: core: Add a UID field to struct sock.")
Miroslav Franc b65b67
Signed-off-by: Pietro Borrello <borrello@diag.uniroma1.it>
Miroslav Franc b65b67
Reviewed-by: Eric Dumazet <edumazet@google.com>
Miroslav Franc b65b67
Signed-off-by: David S. Miller <davem@davemloft.net>
Miroslav Franc b65b67
Acked-by: Miroslav Franc <mfranc@suse.cz>
Miroslav Franc b65b67
---
Miroslav Franc b65b67
 drivers/net/tap.c | 2 +-
Miroslav Franc b65b67
 1 file changed, 1 insertion(+), 1 deletion(-)
Miroslav Franc b65b67
Miroslav Franc b65b67
diff --git a/drivers/net/tap.c b/drivers/net/tap.c
Miroslav Franc b65b67
index a2be1994b389..8941aa199ea3 100644
Miroslav Franc b65b67
--- a/drivers/net/tap.c
Miroslav Franc b65b67
+++ b/drivers/net/tap.c
Miroslav Franc b65b67
@@ -533,7 +533,7 @@ static int tap_open(struct inode *inode, struct file *file)
Miroslav Franc b65b67
 	q->sock.state = SS_CONNECTED;
Miroslav Franc b65b67
 	q->sock.file = file;
Miroslav Franc b65b67
 	q->sock.ops = &tap_socket_ops;
Miroslav Franc b65b67
-	sock_init_data(&q->sock, &q->sk);
Miroslav Franc b65b67
+	sock_init_data_uid(&q->sock, &q->sk, inode->i_uid);
Miroslav Franc b65b67
 	q->sk.sk_write_space = tap_sock_write_space;
Miroslav Franc b65b67
 	q->sk.sk_destruct = tap_sock_destruct;
Miroslav Franc b65b67
 	q->flags = IFF_VNET_HDR | IFF_NO_PI | IFF_TAP;
Miroslav Franc b65b67