Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 843776 - app-emulation/virtualbox: Wrong IPC socket being deleted when VirtualBox is run via su on Linux, leading to possible disk corruption in VMs
Summary: app-emulation/virtualbox: Wrong IPC socket being deleted when VirtualBox is r...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Lars Wendler (Polynomial-C) (RETIRED)
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2022-05-11 11:18 UTC by Johan Hedlin
Modified: 2022-06-15 12:37 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Patch to replace the use of whoami with $LOGNAME/$USER (virtualbox_ipc_socket_cleanup_fix_user.patch,430 bytes, patch)
2022-05-11 11:18 UTC, Johan Hedlin
Details | Diff
Result of "emerge --info" (emerge_info.txt,5.75 KB, text/plain)
2022-05-11 11:18 UTC, Johan Hedlin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Johan Hedlin 2022-05-11 11:18:04 UTC
Created attachment 778115 [details, diff]
Patch to replace the use of whoami with $LOGNAME/$USER

This bug report has been submitted upstream as ticket #20928 (https://www.virtualbox.org/ticket/20928), but Gentoo-specific modifications will override an eventual upstream fix. See that ticket for more complete details and replication steps.

VirtualBox, via gentoo/app-emulation/virtualbox/files/virtualbox-ose-6-wrapper, checks for the presence of a VBoxSVC process owned by the current user and will delete a user-specific directory in /tmp if no process is found. But the process check uses the "whoami" command to get the current username and the deletion uses the environment variables $LOGNAME or $USER. Certain implementations of su, such as the one from util-linux, does not update $LOGNAME or $USER when switching to the root user, but whoami will return "root". Thus, if a user named "vmuser" runs VirtualBox through su, it will search for processes owned by root but delete the socket belonging to vmuser.

The removal of these files will then lead to bad side effects for VMs that were previously running, as future calls to VirtualBox will create a new IPC socket in /tmp. When using this new socket, all VMs will be shown as being powered off when they might still be running. It is also possible to start another instance of a running VM, which leads to disk corruption when both instances attempt to write to the same disk image.

I have attached a small patch to replace the use of whoami with $LOGNAME/$USER, and hereby make this modification available under the MIT license. The patch needs to be applied to gentoo/app-emulation/virtualbox/files/virtualbox-ose-6-wrapper and not the VirtualBox source tree, as the relevant files from upstream will be replaced by the wrapper.

The result of "emerge --info" is attached to this bug report.
Comment 1 Johan Hedlin 2022-05-11 11:18:57 UTC
Created attachment 778118 [details]
Result of "emerge --info"
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-06-10 03:04:28 UTC
This is pretty serious and it's a Gentoo-specific regression.

The patch seems reasonable enough.
Comment 3 Christophe PEREZ 2022-06-10 03:15:31 UTC
Hello,
I don't know if this is related, but I ran into a bug today that might be related.
My server hadn't been stopped for 6 months, and it had gone from version 6.1.28-r2 to version 6.1.32-r1 without virtualbox being restarted.
After an unfortunate power outage, I had to restart my server, and then I couldn't launch a virtual machine anymore because of the error described here https://forums.virtualbox.org/viewtopic.php?f=7&t =105337
And I was able to circumvent the problem by manually launching /usr/lib64/virtualbox/VBoxXPCOMIPCD and /usr/lib64/virtualbox/VBoxSVC beforehand.
And indeed, I run my virtual machine using su.
I don't know if the problem is solved by the unstable version 6.1.34
Comment 4 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-06-13 16:13:06 UTC
I'll commit the fix for this in 3 days (16th) if no response.
Comment 5 Johan Hedlin 2022-06-15 12:04:38 UTC
(In reply to Christophe PEREZ from comment #3)
> My server hadn't been stopped for 6 months, and it had gone from version
> 6.1.28-r2 to version 6.1.32-r1 without virtualbox being restarted.
> After an unfortunate power outage, I had to restart my server, and then I
> couldn't launch a virtual machine anymore because of the error described
> here https://forums.virtualbox.org/viewtopic.php?f=7&t=105337
> [...]
> And indeed, I run my virtual machine using su.
I haven't seen the NS_ERROR_SOCKET_FAIL message, but it does sound like that problem could be related to this bug. Gentoo switched to a different implementation of su (which will trigger this bug) in December, so that could be what caused your system to break: https://gitweb.gentoo.org/repo/gentoo.git/commit/sys-apps/util-linux?id=c550eb53b108fcf6d4e2a38778230bc9a7d078e8
Comment 6 Larry the Git Cow gentoo-dev 2022-06-15 12:37:57 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=32e104524f206f4c02aa95f739995ad084c57201

commit 32e104524f206f4c02aa95f739995ad084c57201
Author:     Lars Wendler <polynomial-c@gentoo.org>
AuthorDate: 2022-06-15 12:36:35 +0000
Commit:     Lars Wendler <polynomial-c@gentoo.org>
CommitDate: 2022-06-15 12:37:52 +0000

    app-emulation/virtualbox: Revbumps to remove uage of whoami
    
    Thanks-to: Johan Hedlin <Busan15@protonmail.com>
    Closes: https://bugs.gentoo.org/843776
    Signed-off-by: Lars Wendler <polynomial-c@gentoo.org>

 app-emulation/virtualbox/files/virtualbox-ose-6-wrapper                 | 2 +-
 .../{virtualbox-6.1.32-r1.ebuild => virtualbox-6.1.32-r2.ebuild}        | 0
 .../{virtualbox-6.1.34.ebuild => virtualbox-6.1.34-r1.ebuild}           | 0
 3 files changed, 1 insertion(+), 1 deletion(-)