ext4: fix data corruption caused by overlapping unaligned and aligned IO
authorLukas Czerner <lczerner@redhat.com>
Sat, 11 May 2019 01:45:33 +0000 (21:45 -0400)
committerBen Hutchings <ben@decadent.org.uk>
Mon, 23 Sep 2019 20:12:04 +0000 (21:12 +0100)
commit36f680c1be1b46d2470fbf577ba229f4d81a154e
treeda4de451d4ba4717b898972d4df701537204b94a
parentafa9b5186c1bf4b8a828af1899231642a1cf5a39
ext4: fix data corruption caused by overlapping unaligned and aligned IO

commit 57a0da28ced8707cb9f79f071a016b9d005caf5a upstream.

Unaligned AIO must be serialized because the zeroing of partial blocks
of unaligned AIO can result in data corruption in case it's overlapping
another in flight IO.

Currently we wait for all unwritten extents before we submit unaligned
AIO which protects data in case of unaligned AIO is following overlapping
IO. However if a unaligned AIO is followed by overlapping aligned AIO we
can still end up corrupting data.

To fix this, we must make sure that the unaligned AIO is the only IO in
flight by waiting for unwritten extents conversion not just before the
IO submission, but right after it as well.

This problem can be reproduced by xfstest generic/538

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
[bwh: Backported to 3.16:
 - Test aio_mutex instead of unaligned_aio
 - Adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/ext4/file.c