Package: e2fsprogs
Version: 1.43.4-2
Severity: critical

e2fsck potentially moves blocks around in sparse files when running with
-E bmap2extent, in particular when the blocks are physically adjacent on
the underlying block device, but have a hole in between in the file.

This script reproduces the problem on my system (run as root in an empty
directory!):

#!/bin/bash -ex
rm -f image
mkdir -p m
umount m || true
dd if=/dev/zero bs=1M seek=99 count=1 of=image
mkfs.ext3 -E nodiscard -b 4096 image
mount -o loop image m
echo -n a > m/x
echo -n b | dd of=m/x bs=1 seek=8k
ls -i m/x
ino=$(stat -c%i m/x)
sha1sum m/x
umount m
debugfs image -R "stat <$ino>" | cat
tune2fs -O extent image
e2fsck -fE bmap2extent image || true
debugfs image -R "stat <$ino>" | cat
mount -o loop image m
sha1sum m/x
umount m
rm image
rmdir m

The e2fsck invocation turns this part of the debugfs output:

BLOCKS:
(0):24576, (2):24577

into this:

EXTENTS:
(0-1):24576-24577

With version 1.44.5-1~bpo9+1, the test above does not produce corruption on
my system, but I have not investigated whether that is just coincidence or
because the bug has been fixed. As this silently corrupts files, I would
think it should get some fix in stretch, and be it by disabling the
feature.

Reply via email to