Skip to contentSkip to conversation

net: tun_chr_open(): set sk_uid from current_fsuid()

PATCH In review Dong Chenchen 2 participants 3 messages Aug 15, 2023 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 1/2 net: tun_chr_open(): set sk_uid from current_fsuid()

From: Laszlo Ersek <[email protected]>

stable inclusion
from stable-v5.10.189
commit 5ea23f1cb67e4468db7ff651627892c9217fec24
category: bugfix
bugzilla: 189104, https://gitee.com/src-openeuler/kernel/issues/I7QXHX
CVE: CVE-2023-4194

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=5ea23f1cb67e4468db7ff651627892c9217fec24

---------------------------

commit 9bc3047374d5bec163e83e743709e23753376f0c upstream.

Commit a096ccca6e50 initializes the "sk_uid" field in the protocol socket (struct sock) from the "/dev/net/tun" device node's owner UID. Per original commit 86741ec25462 ("net: core: Add a UID field to struct sock.", 2016-11-04), that's wrong: the idea is to cache the UID of the userspace process that creates the socket. Commit 86741ec25462 mentions socket() and accept(); with "tun", the action that creates the socket is open("/dev/net/tun").

Therefore the device node's owner UID is irrelevant. In most cases, "/dev/net/tun" will be owned by root, so in practice, commit a096ccca6e50 has no observable effect:

- before, "sk_uid" would be zero, due to undefined behavior (CVE-2023-1076),

- after, "sk_uid" would be zero, due to "/dev/net/tun" being owned by root.

What matters is the (fs)UID of the process performing the open(), so cache that in "sk_uid".

Cc Eric Dumazet <[email protected]>
Cc Lorenzo Colitti <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Pietro Borrello <[email protected]>
Fixes a096ccca6e50 ("tun: tun_chr_open(): correctly initialize socket uid")

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2173435

---
 drivers/net/tun.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/tun.c +1 -1
index f8feec522b32..50c2ce392cd1 100644
@@ -3456,7 +3456,7 @@ static int tun_chr_open(struct inode *inode, struct file * file)
 	tfile->socket.file = file;
 	tfile->socket.ops = &tun_socket_ops;
 
-	sock_init_data_uid(&tfile->socket, &tfile->sk, inode->i_uid);
+	sock_init_data_uid(&tfile->socket, &tfile->sk, current_fsuid());
 
 	tfile->sk.sk_write_space = tun_sock_write_space;
 	tfile->sk.sk_sndbuf = INT_MAX;
Signature · 1 line
2.25.1
#2 lore raw
Quoted 10 lines · Dong Chenchen

From: Laszlo Ersek <[email protected]>

stable inclusion
from stable-v5.10.189
commit 5ea23f1cb67e4468db7ff651627892c9217fec24
category: bugfix
bugzilla: 189104, https://gitee.com/src-openeuler/kernel/issues/I7QXHX
CVE: CVE-2023-4194

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=5ea23f1cb67e4468db7ff651627892c9217fec24

Why are you not just merging directly from the LTS branches into your tree? If you attempt to "cherry-pick" patches like this, you WILL miss valid bugfixes.

thanks,

greg k-h

#3 lore raw

PATCH v2 2/2 net: tap_open(): set sk_uid from current_fsuid()

In reply to a message not in the archive

From: Laszlo Ersek <[email protected]>

stable inclusion
from stable-v5.10.189
commit 33a339e717be2c88b7ad11375165168d5b40e38e
category: bugfix
bugzilla: 189104, https://gitee.com/src-openeuler/kernel/issues/I7QXHX
CVE: CVE-2023-4194

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=33a339e717be2c88b7ad11375165168d5b40e38e

---------------------------

commit 5c9241f3ceab3257abe2923a59950db0dc8bb737 upstream.

Commit 66b2c338adce initializes the "sk_uid" field in the protocol socket (struct sock) from the "/dev/tapX" device node's owner UID. Per original commit 86741ec25462 ("net: core: Add a UID field to struct sock.", 2016-11-04), that's wrong: the idea is to cache the UID of the userspace process that creates the socket. Commit 86741ec25462 mentions socket() and accept(); with "tap", the action that creates the socket is open("/dev/tapX").

Therefore the device node's owner UID is irrelevant. In most cases, "/dev/tapX" will be owned by root, so in practice, commit 66b2c338adce has no observable effect:

- before, "sk_uid" would be zero, due to undefined behavior (CVE-2023-1076),

- after, "sk_uid" would be zero, due to "/dev/tapX" being owned by root.

What matters is the (fs)UID of the process performing the open(), so cache that in "sk_uid".

Cc Eric Dumazet <[email protected]>
Cc Lorenzo Colitti <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Pietro Borrello <[email protected]>
Fixes 66b2c338adce ("tap: tap_open(): correctly initialize socket uid")

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2173435

---
 drivers/net/tap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/tap.c +1 -1
index d9018d9fe310..2c9ae02ada3e 100644
@@ -523,7 +523,7 @@ static int tap_open(struct inode *inode, struct file *file)
 	q->sock.state = SS_CONNECTED;
 	q->sock.file = file;
 	q->sock.ops = &tap_socket_ops;
-	sock_init_data_uid(&q->sock, &q->sk, inode->i_uid);
+	sock_init_data_uid(&q->sock, &q->sk, current_fsuid());
 	q->sk.sk_write_space = tap_sock_write_space;
 	q->sk.sk_destruct = tap_sock_destruct;
 	q->flags = IFF_VNET_HDR | IFF_NO_PI | IFF_TAP;
Signature · 1 line
2.25.1