Virtualbox encounters 'Effective UID is not root' when starting a VM

Bug #1935856 reported by MarkJBobak
46
This bug affects 10 people
Affects Status Importance Assigned to Milestone
virtualbox (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

I can run Virtualbox, and create a new VM, but when I try to run it, I encounter:
Effective UID is not root (euid=1000 egid=1000 uid=1000 gid=1000) (rc=-10)

Please try reinstalling VirtualBox.

where: SUPR3HardenedMain what: 2 VERR_PERMISSION_DENIED (-10) - Permission denied.

I have tried re-installing Virtualbox:
sudo apt purge virtualbox-*
sudo apt install virtualbox

but no help.

I made sure my user was added to vboxusers group, but also no help there.

Help?

-Mark

ProblemType: Bug
DistroRelease: Ubuntu 21.04
Package: virtualbox 6.1.22-dfsg-2~ubuntu1.21.04.1
ProcVersionSignature: Ubuntu 5.11.0-24.25-generic 5.11.22
Uname: Linux 5.11.0-24-generic x86_64
NonfreeKernelModules: zfs zunicode zavl icp zcommon znvpair nvidia_modeset nvidia
ApportVersion: 2.20.11-0ubuntu65.1
Architecture: amd64
CasperMD5CheckResult: unknown
CurrentDesktop: ubuntu:GNOME
Date: Mon Jul 12 13:36:37 2021
InstallationDate: Installed on 2020-08-31 (315 days ago)
InstallationMedia: Ubuntu 20.04 LTS "Focal Fossa" - Release amd64 (20200423)
SourcePackage: virtualbox
UpgradeStatus: Upgraded to hirsute on 2021-05-10 (63 days ago)

Revision history for this message
MarkJBobak (mark-bobak) wrote :
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in virtualbox (Ubuntu):
status: New → Confirmed
Revision history for this message
Oliver Maurhart (dyle71) wrote :

Hi *,

I'm affected by this bug too. What I noticed:
When I run
```
$ strace -ff -o VBoxManage.trace VBoxManage startvm 92522455-ebd0-4a67-8a38-4ba05ca3fc00
```
and check the trace files for any "perm" I see
```
$ grep -i perm VBoxManage.trace.101*
...
VBoxManage.trace.10169:openat(AT_FDCWD, "/dev/loop5", O_RDONLY|O_NONBLOCK|O_CLOEXEC) = -1 EACCES (Permission denied)
VBoxManage.trace.10169:openat(AT_FDCWD, "/dev/loop3", O_RDONLY|O_NONBLOCK|O_CLOEXEC) = -1 EACCES (Permission denied)
VBoxManage.trace.10179:openat(AT_FDCWD, "/dev/vboxnetctl", O_RDWR) = -1 EACCES (Permission denied)
VBoxManage.trace.10183:capset({version=0 /* _LINUX_CAPABILITY_VERSION_??? */, pid=0}, {effective=1<<CAP_NET_RAW|1<<CAP_SYS_NICE, permitted=1<<CAP_NET_RAW|1<<CAP_SYS_NICE, inheritable=0}) = -1 EINVAL (Invalid argument)
...
```

Checking the (device-)file in question, I see:
```
$ ls -l /dev/vboxnetctl
crw------- 1 root root 10, 120 Jul 30 09:27 /dev/vboxnetctl
```

I'm not root, so that's clear to me then. But my user is member of the vboxuser group.
So changing the access permission to
```
$ sudo chgrp vboxusers /dev/vboxnetctl && sudo chmod g+rw /dev/vboxnetctl
$ ls -l /dev/vboxnetctl
crw-rw---- 1 root vboxusers 10, 120 Jul 30 09:27 /dev/vboxnetctl
```

And trying again, renders now
```
$ strace -ff -o VBoxManage.trace VBoxManage startvm 92522455-ebd0-4a67-8a38-4ba05ca3fc00
...
$ grep -i perm VBox*
...
VBoxManage.trace.9788:openat(AT_FDCWD, "/dev/loop5", O_RDONLY|O_NONBLOCK|O_CLOEXEC) = -1 EACCES (Permission denied)
VBoxManage.trace.9788:openat(AT_FDCWD, "/dev/loop3", O_RDONLY|O_NONBLOCK|O_CLOEXEC) = -1 EACCES (Permission denied)
VBoxManage.trace.9798:openat(AT_FDCWD, "/dev/vboxnetctl", O_RDWR) = -1 EPERM (Operation not permitted)
VBoxManage.trace.9802:capset({version=0 /* _LINUX_CAPABILITY_VERSION_??? */, pid=0}, {effective=1<<CAP_NET_RAW|1<<CAP_SYS_NICE, permitted=1<<CAP_NET_RAW|1<<CAP_SYS_NICE, inheritable=0}) = -1 EINVAL (Invalid argument)
...
```

So, it's "Operation not permitted" and somehow relates to Linux Capabilities
```
$ man capabilities
```

Mehhh, ... puhh ... I'll investigate further...

Revision history for this message
Oliver Maurhart (dyle71) wrote :

Add-on: I checked the sources provided at https://download.virtualbox.org/virtualbox/6.1.22/ and I think the responsible code snippet is in VirtualBox-6.1.22/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp

```
$ cat -n VirtualBox-6.1.22/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp | grep -A 10 2550
  2550 /*
  2551 * Check that we're root, if we aren't then the installation is butchered.
  2552 */
  2553 g_uid = getuid();
  2554 g_gid = getgid();
  2555 if (geteuid() != 0 /* root */)
  2556 supR3HardenedFatalMsg("SUPR3HardenedMain", kSupInitOp_RootCheck, VERR_PERMISSION_DENIED,
  2557 "Effective UID is not root (euid=%d egid=%d uid=%d gid=%d)",
  2558 geteuid(), getegid(), g_uid, g_gid);
  2559 #endif /* SUP_HARDENED_SUID */
  2560
```

When making a small demo:
```
$ cat a.c
#include <stdio.h>
#include <fcntl.h>

#include <unistd.h>
#include <sys/types.h>

int main(int argc, char** argv) {

    printf("Real user id: %d\n", getuid());
    printf("Effective user id: %d\n", geteuid());

    int res = openat(AT_FDCWD, "/dev/vboxnetctl", O_RDWR);

    if (res == -1) {
        perror(NULL);
        return 1;
    }
    printf("Opened file.\n");
    return 0;
}
```
with

```
$ gcc a.c
$ sudo chown root: a.out
$ ls -l a.out
-rwxrwxr-x 1 root root 16312 Jul 30 12:05 a.out

$ ./a.out
Real user id: 1000
Effective user id: 1000
Operation not permitted

$ sudo ./a.out
Real user id: 0
Effective user id: 0
Opened file.

$ sudo chmod u+s a.out
$ ./a.out
Real user id: 1000
Effective user id: 0
Opened file.
```

However, regardless if I provide each and every executable in /usr/lib/virtualbox/* the sticky bit with `chmod u+s` this error keeps popping up.

X11 showing the error dialog refers to /usr/lib/virtualbox/VBoxManage. But it seems very resilient to any of my attempts.

BUT: running VBoxManage as root (e.g. `sudo VirtualBox`) works like charm.

Revision history for this message
MarkJBobak (mark-bobak) wrote : Re: [Bug 1935856] Re: Virtualbox encounters 'Effective UID is not root' when starting a VM

Nice. I'm currently away from my computer, but I'll have a look ASAP.

Thanks!

-Mark

On Fri, Jul 30, 2021, 06:41 Oliver Maurhart <email address hidden>
wrote:

> Add-on: I checked the sources provided at
> https://download.virtualbox.org/virtualbox/6.1.22/ and I think the
> responsible code snippet is in
> VirtualBox-6.1.22/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp
>
> ```
> $ cat -n
> VirtualBox-6.1.22/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp | grep
> -A 10 2550
> 2550 /*
> 2551 * Check that we're root, if we aren't then the installation
> is butchered.
> 2552 */
> 2553 g_uid = getuid();
> 2554 g_gid = getgid();
> 2555 if (geteuid() != 0 /* root */)
> 2556 supR3HardenedFatalMsg("SUPR3HardenedMain",
> kSupInitOp_RootCheck, VERR_PERMISSION_DENIED,
> 2557 "Effective UID is not root (euid=%d
> egid=%d uid=%d gid=%d)",
> 2558 geteuid(), getegid(), g_uid, g_gid);
> 2559 #endif /* SUP_HARDENED_SUID */
> 2560
> ```
>
> When making a small demo:
> ```
> $ cat a.c
> #include <stdio.h>
> #include <fcntl.h>
>
> #include <unistd.h>
> #include <sys/types.h>
>
> int main(int argc, char** argv) {
>
> printf("Real user id: %d\n", getuid());
> printf("Effective user id: %d\n", geteuid());
>
> int res = openat(AT_FDCWD, "/dev/vboxnetctl", O_RDWR);
>
> if (res == -1) {
> perror(NULL);
> return 1;
> }
> printf("Opened file.\n");
> return 0;
> }
> ```
> with
>
> ```
> $ gcc a.c
> $ sudo chown root: a.out
> $ ls -l a.out
> -rwxrwxr-x 1 root root 16312 Jul 30 12:05 a.out
>
> $ ./a.out
> Real user id: 1000
> Effective user id: 1000
> Operation not permitted
>
> $ sudo ./a.out
> Real user id: 0
> Effective user id: 0
> Opened file.
>
> $ sudo chmod u+s a.out
> $ ./a.out
> Real user id: 1000
> Effective user id: 0
> Opened file.
> ```
>
> However, regardless if I provide each and every executable in
> /usr/lib/virtualbox/* the sticky bit with `chmod u+s` this error keeps
> popping up.
>
> X11 showing the error dialog refers to /usr/lib/virtualbox/VBoxManage.
> But it seems very resilient to any of my attempts.
>
> BUT: running VBoxManage as root (e.g. `sudo VirtualBox`) works like
> charm.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1935856
>
> Title:
> Virtualbox encounters 'Effective UID is not root' when starting a VM
>
> To manage notifications about this bug go to:
>
> https://bugs.launchpad.net/ubuntu/+source/virtualbox/+bug/1935856/+subscriptions
>
>

Revision history for this message
Oliver Maurhart (dyle71) wrote :

Errm, I don't know what to say.
Today I rebooted and tried again... and it worked. o.O

```
$ VBoxManage startvm 92522455-ebd0-4a67-8a38-4ba05ca3fc00
Waiting for VM "92522455-ebd0-4a67-8a38-4ba05ca3fc00" to power on...
VM "92522455-ebd0-4a67-8a38-4ba05ca3fc00" has been successfully started.
```

I did not reinstall Virtualbox. Just an ordinary regular apt update && apt upgrade today.

Hm, what remains is my sticky bit for /usr/share/virtualbox/VirtualBoxVM:
```
$ find /usr/lib/virtualbox/ -type f -executable | xargs ls -l | grep rws
-rwsr-xr-x 1 root root 166208 Jun 22 09:15 /usr/lib/virtualbox/VirtualBoxVM
```

I don't know why it works today, despite my tries yesterday... maybe the virtual box kernel modules have some magic residing in memory and thus ignoring my attempts until a reboot.

See myself puzzled...

Revision history for this message
Sergey Menshikov (sergem) wrote :

I confirm that setting suid on VirtualBoxVM mitigates the issue.
sudo chmod g+s /usr/lib/virtualbox/VirtualBoxVM

Revision history for this message
MarkJBobak (mark-bobak) wrote :

Confirmed!

Sergei, I needed to do sudo chmod u+s, *not* sudo chmod g+s. g+s didn't
work.

On Sat, Jul 31, 2021 at 4:45 PM Sergey Menshikov <email address hidden>
wrote:

> I confirm that setting suid on VirtualBoxVM mitigates the issue.
> sudo chmod g+s /usr/lib/virtualbox/VirtualBoxVM
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1935856
>
> Title:
> Virtualbox encounters 'Effective UID is not root' when starting a VM
>
> To manage notifications about this bug go to:
>
> https://bugs.launchpad.net/ubuntu/+source/virtualbox/+bug/1935856/+subscriptions
>
>

Revision history for this message
Alexandre Horst (ahorst) wrote :

In addition, I needed to

sudo chmod u+s /usr/lib/virtualbox/VBoxNetAdpCtl

too to change network interfaces on the "Host Network Manager".

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.