VirtualBox

Opened 3 years ago

Closed 2 years ago

#20512 closed defect (fixed)

Sporadic data corruption on a VHD virtual disk with ext4 => fixed in SVN/next maintenance

Reported by: Mikhail Kovalev Owned by:
Component: other Version: VirtualBox 6.1.26
Keywords: Cc:
Guest type: Linux Host type: Windows

Description

We observed this problem on VirtualBox 6.1.18 - 6.1.26, Windows 10 host, Debian 9 or Debian 10 VM. We don't know if the other versions are affected or not. We could reproduce it with and without Hyper-V enabled. So far we only saw this problem on small VHDs (up to 10MB size) with the ext4 file system.

How to reproduce:

  1. Start the VM
  2. Attach a VHD (~10 MB size) to the (running) VM. We were creating a fresh VHD using the VirtualBox UI here.
  3. Format the disk from the VM. We used the following command:
    mkfs.ext4 -m 0 /dev/sdb
    
  4. Mount the disk inside the VM. We used the following mounting options:
    mount -t ext4 -o sync,nodelalloc /dev/sdb /test
    

Note: if we remove the "nodelalloc" setting, it's much harder to reproduce the data corruption (but we still could reproduce it a few times).

  1. Write some data to the disk. E.g.
    dd bs=1 count=60 if=/dev/random of=/test/test1
    
  2. Unmount the disk and mount it again:
    umount/mount
    mount -t ext4 -o sync,nodelalloc /dev/sdb /test
    
  3. The data on the disk might get corrupted now: the file content will be replaced with NULL bytes (either the whole file or starting from some offset). Screenshot attached. The corruption doesn't happen every time. But we can easily reproduce it in 2-3 tries at most.

I am also attaching VBox.log and the zipped corrupted .vhd.

Attachments (4)

screenshot.PNG (43.2 KB ) - added by Mikhail Kovalev 3 years ago.
Screenshot of data corruption
Debian 10-2021-08-19-11-23-30.log (88.9 KB ) - added by Mikhail Kovalev 3 years ago.
VBox.log
test.vhd.zip (8.5 KB ) - added by Mikhail Kovalev 3 years ago.
Corrupted vhd
changeset_146628.diff (711 bytes ) - added by Klaus Espenlaub 3 years ago.

Download all attachments as: .zip

Change History (9)

by Mikhail Kovalev, 3 years ago

Attachment: screenshot.PNG added

Screenshot of data corruption

by Mikhail Kovalev, 3 years ago

VBox.log

by Mikhail Kovalev, 3 years ago

Attachment: test.vhd.zip added

Corrupted vhd

comment:1 by Mikhail Kovalev, 3 years ago

The VBox.log is from a custom VirtualBox build. But we can also reproduce the problem on the original VirtualBox. So if this is critical - I can provide a VBox.log from the original VirtualBox

comment:2 by aeichner, 3 years ago

Summary: Sporadic data corruption on a VHD virtual disk with ext4Sporadic data corruption on a VHD virtual disk with ext4 => fixed in SVN/next maintenance

Thanks for the report, this will be fixed in the next maintenance release! This happens only if the virtual disk size of the image (9. something MiB in your case) is not aligned to the VHD data block size (the default is 2 MiB) and the guest tries to allocate the last block in the image. So the current workaround until a fixed version is released is to make sure that the disk image size is a multiple of 2MiB.

by Klaus Espenlaub, 3 years ago

Attachment: changeset_146628.diff added

comment:3 by Klaus Espenlaub, 3 years ago

Attached the diff in case it's urgent. Yes, you're using a very odd size of the disk image in your reproduction case (and likely in the other cases where this happened in production). You end up with a disk image with 19407 sectors or 9,936,384 bytes, i.e. even less than the 19531 or 19532 sectors which would be the "rounded down" or "rounded up" value for a disk size of 10,000,000 bytes (giving 9,999,872 bytes or 10,000,384 bytes).

comment:4 by Mikhail Kovalev, 3 years ago

Thank you very much, both for the patch and for the explanation!

comment:5 by aeichner, 2 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette