All of
 help / color / mirror / Atom feed
From: Laszlo Ersek <>
Cc: Eric Dumazet <>,
	Lorenzo Colitti <>,
	Paolo Abeni <>,
	Pietro Borrello <>,,
Subject: [PATCH 2/2] net: tap_open(): set sk_uid from current_fsuid()
Date: Mon, 31 Jul 2023 18:42:37 +0200	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

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

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

- 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 <>
Cc: Lorenzo Colitti <>
Cc: Paolo Abeni <>
Cc: Pietro Borrello <>
Fixes: 66b2c338adce ("tap: tap_open(): correctly initialize socket uid")
Signed-off-by: Laszlo Ersek <>
 drivers/net/tap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index 9137fb8c1c42..49d1d6acf95e 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -534,7 +534,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;

  parent reply	other threads:[~2023-07-31 16:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-31 16:42 [PATCH 0/2] tun/tap: set sk_uid from current_fsuid() Laszlo Ersek
2023-07-31 16:42 ` [PATCH 1/2] net: tun_chr_open(): " Laszlo Ersek
2023-07-31 16:42 ` Laszlo Ersek [this message]
2023-08-03 16:43 ` [PATCH 0/2] tun/tap: " Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.