Skip to contentSkip to conversation

drivers/net/tun.c: CAP_NET_ADMIN conditional not reached

DISCUSSION Petar Bogdanovic 1 participant 1 message Jul 28, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

drivers/net/tun.c says:

    1004  if (((tun->owner != -1 && cred->euid != tun->owner) ||
    1005       (tun->group != -1 && !in_egroup_p(tun->group))) &&
    1006      !capable(CAP_NET_ADMIN))
    1007          return -EPERM;

this will skip !capable(CAP_NET_ADMIN) if tun->owner and tun->group are both -1, which seems to be their default value (see lines 854,855). ip(8) from iproute2 won't do any TUNSETOWNER/TUNSETGROUP ioctl() if no uid and/or gid is supplied so when using `ip tuntap' as an unprivileged user, you'll be unable to create a new tun(4) but won't have any problems attaching to an existing device created without both user and group options.

I'm not sure whether this is intentional since it has been around for years.. although triggering it with tunctl(8) was not possible---tunctl without `-u' seems to use 0 as the default value for TUNSETOWNER.

Petar Bogdanovic