Can a virtual machine (VM) ever overwrite the host disk, or a host a guest disk, or a guest another guest disk?

Solution 1:

Guest space to guest

On Linux Mint, using a VirtualBox, the installer tells me directly after the choice of the "Erase" option:

If you continue, the changes listed below will be written to the disks. Otherwise, you will be able to make further changes manually. The partition tables of the following devices are changed: SCSI3 (0,0,0)(sda) The following partitions are going to be formatted: partition #1 of SCSI3 (0,0,0)(sda) as ext4.

I have chosen "Continue" and nothing bad has happened. Probably, the message pops up because I have another VM already installed. I do not think that the VM will ever overwrite data of the host. It seems, though, that a VM can take space from another VM perhaps?

Virtual machines are completely self-contained. They are (broadly speaking) indistinguishable from a physical computer and don't know about each other unless you connect them somehow - just like physical computers.

That message is not caused by existence of another VM. It's a "sanity check" type of dialog. It asks you to double-check that installer's automatically made choices match your intentions.

I've experimentally confirmed that this message appears when installing Ubuntu 18.04 and 20.04 to an empty, non-partitioned drive.

Host space from guest

While from the inside a VM looks like a normal computer, from the outside (ie. host's perspective) it's just a bunch of files. Generally you'll have one file which describes VM's hardware configuration and one file for each virtual disk attached to the VM. So in most use cases, a VM consists of two files: one for the config and one for the disk.

Disk files can either be pre-allocated or dynamically allocated. Pre-allocated disk is created to take up amount of space equal to its capacity from the very beginning. It can improve performance slightly at the cost of consuming host's disk space for unused disk regions. If you don't have enough disk space for this, the process will fail while the VM is getting created but it's not running yet.

A dynamically allocated virtual disk file will grow as the guest is trying to write to its previously unused regions. The technical term for this is a sparse file. This is the case where host can indeed run out of disk space when guest is trying to write to its virtual disk. Nothing will be overwritten because it's just a typical case of a program trying to create a file too large to fit on the disk (the program being your VM software - the hypervisor). The fact that it's a virtual disk attached to a running VM is irrelevant, because from host's perspective it's a file no different than any other. The operating system's filesystem driver will simply deny writing to that file. How the hypervisor handles this is up to its implementation.

Guest space from host

Once again, for the host the virtual disk is just a file and it's subject to the same rules as any other file. Any process allowed to write to this file can make any modifications to it, unless this file is locked for exclusive writing by another process at the moment.

Solution 2:

"Ever" is a very long time, and if someone knows how to access other Guest or Host from a VM (I do know how), then yes, of course it is possible.

However, erase space or even a whole machine will not overwrite other systems outside its bounds.

Windows and Linux guests delete unused space from time to time with no issues.

I compact Virtual Disks (Windows and Linux) to recover deleted VM space with no issue.

What you want to do (expand a virtual disk or delete space inside a virtual disk) will not harm a host system or other guest.

Just make sure you do not run out of real disk space. That can cause issues to any system.

Anecdotal note: The first time I built a VM (Windows 98 which I still have on VMware Workstation Version 1 on a Windows NT4 Workstation host), the Windows 98 setup said "I am going to format your hard drive"

I sure did pause before saying OK, so your question is most reasonable and well put.

Solution 3:

Can a virtual machine (VM) ever overwrite the host disk,

Virtual Machine hosts have had security holes that let a guest break out of its VM, and history and experience tells us that this will happen again.

Once the guest breaks out of the VM, it can do whatever the host can do.

or a host a guest disk,

The host always has full control, it can do whatever it wants.

or a guest another guest disk?

Once a guest manages to break out of the VM, it can do whatever the host can do, so this reduces to #2.

Obviously, a simple configuration error where the same virtual disk is attached in writeable mode to multiple guest VMs, or where a physical disk of the host is attached in passthrough mode to a guest VM breaks down all protection as well, without needing a somewhat esoteric security bug.

Solution 4:

It really depends on how you configure things on the host side to know if there's going to be trouble down the road.

By default, if you create a VM with storage, a file is created that hosts the storage for this VM. In these cases, the guest cannot make any changes to the host, and in case of a dynamically sized disk, once the disk wants to write data that is larger than the allocated space because the host's disk is full, a write error occurs within the guest, that's it.

The problem here is that writing fails but doesn't give a clear meaning in the guest. It can be harder to troubleshoot, but it will be something like: "Error writing to file. Make sure the disk is writable. Even if your disk says enough space is full it will just not allow any writes. If you then inspect the host, you'll find out the disk is full. On the host side, you get a clear message that the disk is full because the host can actually see it, just not the guest.

Now, in which situation can a guest actually destroy data on a host's drive?

It is possible to assign a physical disk as storage medium for a VM. If this physical disk is also used by the system itself, you basically grant the guest access to the host in a way that was not intended. It is not what anyone should do, but I'm just naming it because it actually is possible.

Guest space to the guest

Even though the guest thinks its on a normal computer, it is all a virtual environment. Because the guest cannot actually tell it is inside a virtual environment, the messages you see on screen will not reflect that either. If it says: I'm going to delete all your data on your disk, it is only all the data the guest has access to which is what you defined in the host. Whether this is a virtual disk or physical disk as pass through, to the guest it is exactly the same.