tun: fix group permission check
authorStas Sergeev <stsp2@yandex.ru>
Thu, 5 Dec 2024 07:36:14 +0000 (10:36 +0300)
committerJakub Kicinski <kuba@kernel.org>
Sun, 8 Dec 2024 01:43:02 +0000 (17:43 -0800)
commit3ca459eaba1bf96a8c7878de84fa8872259a01e3
treec8c10ae5651d1d005d683763c04a4c336e520587
parent81d89e6e88d5d592c1792940753d69d9753b3a8a
tun: fix group permission check

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>
drivers/net/tun.c