mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 5.15 01/14] tun: fix group permission check
@ 2025-01-26 15:04 Sasha Levin
  2025-01-26 15:04 ` [PATCH AUTOSEL 5.15 02/14] mmc: core: Respect quirk_max_rate for non-UHS SDIO card Sasha Levin
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: Sasha Levin @ 2025-01-26 15:04 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Stas Sergeev, Willem de Bruijn, Jason Wang, Jakub Kicinski,
	Sasha Levin, willemdebruijn.kernel, andrew+netdev, davem,
	edumazet, pabeni, netdev

From: Stas Sergeev <stsp2@yandex.ru>

[ Upstream commit 3ca459eaba1bf96a8c7878de84fa8872259a01e3 ]

Currently tun checks the group permission even if the user have matched.
Besides going against the usual permission semantic, this has a
very interesting implication: if the tun group is not among the
supplementary groups of the tun user, then effectively no one can
access the tun device. CAP_SYS_ADMIN still can, but its the same as
not setting the tun ownership.

This patch relaxes the group checking so that either the user match
or the group match is enough. This avoids the situation when no one
can access the device even though the ownership is properly set.

Also I simplified the logic by removing the redundant inversions:
tun_not_capable() --> !tun_capable()

Signed-off-by: Stas Sergeev <stsp2@yandex.ru>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Link: https://patch.msgid.link/20241205073614.294773-1-stsp2@yandex.ru
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/net/tun.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 959ca6b9cd138..a85f743aa1573 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -575,14 +575,18 @@ static u16 tun_select_queue(struct net_device *dev, struct sk_buff *skb,
 	return ret;
 }
 
-static inline bool tun_not_capable(struct tun_struct *tun)
+static inline bool tun_capable(struct tun_struct *tun)
 {
 	const struct cred *cred = current_cred();
 	struct net *net = dev_net(tun->dev);
 
-	return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
-		  (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
-		!ns_capable(net->user_ns, CAP_NET_ADMIN);
+	if (ns_capable(net->user_ns, CAP_NET_ADMIN))
+		return 1;
+	if (uid_valid(tun->owner) && uid_eq(cred->euid, tun->owner))
+		return 1;
+	if (gid_valid(tun->group) && in_egroup_p(tun->group))
+		return 1;
+	return 0;
 }
 
 static void tun_set_real_num_queues(struct tun_struct *tun)
@@ -2718,7 +2722,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
 		    !!(tun->flags & IFF_MULTI_QUEUE))
 			return -EINVAL;
 
-		if (tun_not_capable(tun))
+		if (!tun_capable(tun))
 			return -EPERM;
 		err = security_tun_dev_open(tun->security);
 		if (err < 0)
-- 
2.39.5


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

end of thread, other threads:[~2025-01-26 15:04 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-26 15:04 [PATCH AUTOSEL 5.15 01/14] tun: fix group permission check Sasha Levin
2025-01-26 15:04 ` [PATCH AUTOSEL 5.15 02/14] mmc: core: Respect quirk_max_rate for non-UHS SDIO card Sasha Levin
2025-01-26 15:04 ` [PATCH AUTOSEL 5.15 03/14] wifi: brcmsmac: add gain range check to wlc_phy_iqcal_gainparams_nphy() Sasha Levin
2025-01-26 15:04 ` [PATCH AUTOSEL 5.15 04/14] tomoyo: don't emit warning in tomoyo_write_control() Sasha Levin
2025-01-26 15:04 ` [PATCH AUTOSEL 5.15 05/14] mfd: lpc_ich: Add another Gemini Lake ISA bridge PCI device-id Sasha Levin
2025-01-26 15:04 ` [PATCH AUTOSEL 5.15 06/14] HID: Wacom: Add PCI Wacom device support Sasha Levin
2025-01-26 15:04 ` [PATCH AUTOSEL 5.15 07/14] net/mlx5: use do_aux_work for PHC overflow checks Sasha Levin
2025-01-26 15:04 ` [PATCH AUTOSEL 5.15 08/14] wifi: iwlwifi: avoid memory leak Sasha Levin
2025-01-26 15:04 ` [PATCH AUTOSEL 5.15 09/14] i2c: Force ELAN06FA touchpad I2C bus freq to 100KHz Sasha Levin
2025-01-26 15:04 ` [PATCH AUTOSEL 5.15 10/14] APEI: GHES: Have GHES honor the panic= setting Sasha Levin
2025-01-26 15:04 ` [PATCH AUTOSEL 5.15 11/14] net: wwan: iosm: Fix hibernation by re-binding the driver around it Sasha Levin
2025-01-26 15:04 ` [PATCH AUTOSEL 5.15 12/14] mmc: sdhci-msm: Correctly set the load for the regulator Sasha Levin
2025-01-26 15:04 ` [PATCH AUTOSEL 5.15 13/14] tipc: re-order conditions in tipc_crypto_key_rcv() Sasha Levin
2025-01-26 15:04 ` [PATCH AUTOSEL 5.15 14/14] selftests/net/ipsec: Fix Null pointer dereference in rtattr_pack() Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®