Skip to content

Commit a70c7b3

Browse files
wdebruijkuba-moo
authored andcommitted
tun: revert fix group permission check
This reverts commit 3ca459e. The blamed commit caused a regression when neither tun->owner nor tun->group is set. This is intended to be allowed, but now requires CAP_NET_ADMIN. Discussion in the referenced thread pointed out that the original issue that prompted this patch can be resolved in userspace. The relaxed access control may also make a device accessible when it previously wasn't, while existing users may depend on it to not be. This is a clean pure git revert, except for fixing the indentation on the gid_valid line that checkpatch correctly flagged. Fixes: 3ca459e ("tun: fix group permission check") Link: https://lore.kernel.org/netdev/CAFqZXNtkCBT4f+PwyVRmQGoT3p1eVa01fCG_aNtpt6dakXncUg@mail.gmail.com/ Signed-off-by: Willem de Bruijn <willemb@google.com> Cc: Ondrej Mosnacek <omosnace@redhat.com> Cc: Stas Sergeev <stsp2@yandex.ru> Link: https://patch.msgid.link/20250204161015.739430-1-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 02b71dc commit a70c7b3

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

drivers/net/tun.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -574,18 +574,14 @@ static u16 tun_select_queue(struct net_device *dev, struct sk_buff *skb,
574574
return ret;
575575
}
576576

577-
static inline bool tun_capable(struct tun_struct *tun)
577+
static inline bool tun_not_capable(struct tun_struct *tun)
578578
{
579579
const struct cred *cred = current_cred();
580580
struct net *net = dev_net(tun->dev);
581581

582-
if (ns_capable(net->user_ns, CAP_NET_ADMIN))
583-
return 1;
584-
if (uid_valid(tun->owner) && uid_eq(cred->euid, tun->owner))
585-
return 1;
586-
if (gid_valid(tun->group) && in_egroup_p(tun->group))
587-
return 1;
588-
return 0;
582+
return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
583+
(gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
584+
!ns_capable(net->user_ns, CAP_NET_ADMIN);
589585
}
590586

591587
static void tun_set_real_num_queues(struct tun_struct *tun)
@@ -2782,7 +2778,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
27822778
!!(tun->flags & IFF_MULTI_QUEUE))
27832779
return -EINVAL;
27842780

2785-
if (!tun_capable(tun))
2781+
if (tun_not_capable(tun))
27862782
return -EPERM;
27872783
err = security_tun_dev_open(tun->security);
27882784
if (err < 0)

0 commit comments

Comments
 (0)