Risks in having a shared folder on the same host partition as the machine folder?

This is for discussing general topics about how to use VirtualBox.
Post Reply
SecretCode
Posts: 67
Joined: 17. Jul 2009, 10:20
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Ubuntu, XP, other
Location: Finland

Risks in having a shared folder on the same host partition as the machine folder?

Post by SecretCode »

I think I recall reading that there were major risks in giving a guest VM write access through a shared folder to the same partition that the virtual machine files (.vdi files, and/or snapshots, and/or .vbox xml definition) are stored on. But I can't find any posts or pages about it now.

This must be a very common setup - if the host has only one drive or partition, shared folders will be on the same drive/partition. If the guest has write access to the machine folder, it could in principle delete critical files and corrupt/crash the vm.

Example (I'm using Linux guests on a Linux host but I expect the answer does not depend on OS types):
.vbox files, .vdi files and snapshots all stored, as default, in "~/VIrtualBox VMs".
Case 1: A shared folder to the host's home dir "~" is set up, with read/write access.
Case 2: A shared folder to "~/Shared" on the host is set up, with read/write access.

Questions:
Is this a genuine, major risk (to the extent that you should never do this - I don't expect shared folders in VMs will ever be risk-free)?
Was it a risk in the past, but now it isn't ... or is my memory failing? :D
Is case 2 - shared access to a distinct subdirectory - safer? - Does the shared folder protocol restrict file read/write/deletes to within the specified subdirectory?
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Risks in having a shared folder on the same host partition as the machine folder?

Post by scottgus1 »

SecretCode wrote:write access through a shared folder to the same partition that the virtual machine files (.vdi files, and/or snapshots, and/or .vbox xml definition) are stored on.
SecretCode wrote:write access to the machine folder
These aren't the same thing, as I read. The first could be lots of things, such as on a Windows host: "C:\MyVM" vs
"C:\Shared". Sharing the "Shared" folder won't allow access to "MyVM", even though they're on the same partition. The second is a possible and dangerous subset of the first.

Being able to write to a shared folder does allow writing to everything within that shared folder. I don't recall reading that there are circumstances now where a process with such write access could write to the root of the shared folder or another folder not in the path of the shared folder. Unless that was what WannaCry was doing through SMB1. And normal processes in PCs have been subverted to allow bad behaviors (Meltdown, Spectre, row hammering, etc.) So anything could happen in the future. But with SMB1 being deactivated in modern OS's, shared folders seem stable for now. As long as the VM itself isn't in the shared folder path, the VM should be safe.

Being able to write to the VM's folder (or a folder in the root path thereof) is a serious misconfiguration and should not be set up.

If my VM was in my user folder (typical for Windows hosts: "C:\Users\{me}\Virtualbox VMs\...") I would not share "C:\Users\{me}" to the VM, or anything else for that matter. "C:\Users\{me}\SharedWithMyVM" should be OK, since the VM doesn't exist in that path. Sharing the root of the whole partition, also a big no-no.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Risks in having a shared folder on the same host partition as the machine folder?

Post by fth0 »

SecretCode wrote:Is this a genuine, major risk (to the extent that you should never do this - I don't expect shared folders in VMs will ever be risk-free)?
In this absolute form I'd say no. But on the other hand I wouldn't provide a shared folder to a VM that I didn't trust at all.

Like any large (non-trivial) software, VirtualBox has security-related bugs, and I wouldn't be surprised if there was a "path-escaping" bug in the shared folder implementation. On the positive side, creating and following symbolic links is deliberately prohibited by default, which shows that somebody gave it at least some sensible thought. Just my 2 cents.
SecretCode
Posts: 67
Joined: 17. Jul 2009, 10:20
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Ubuntu, XP, other
Location: Finland

Re: Risks in having a shared folder on the same host partition as the machine folder?

Post by SecretCode »

Thanks; I will go with sharing a subdirectory that does not include the VM folder.
scottgus1 wrote: Being able to write to the VM's folder (or a folder in the root path thereof) is a serious misconfiguration and should not be set up.
Is this documented? I couldn't see it, as noted in my OP.

It seems like it would be an important warning to have more prominently documented.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Risks in having a shared folder on the same host partition as the machine folder?

Post by scottgus1 »

SecretCode wrote:Is this documented?
Not that I know, but it makes sense to me.
Post Reply