]> git.baikalelectronics.ru Git - kernel.git/commit
direct-io: defer alignment check until after the EOF check
authorGabriel Krisman Bertazi <krisman@collabora.com>
Thu, 8 Oct 2020 06:26:20 +0000 (02:26 -0400)
committerJan Kara <jack@suse.cz>
Thu, 8 Oct 2020 16:26:46 +0000 (18:26 +0200)
commit1cc1f21a16c52f5e6fb90aa77a4452ba2717bc9e
tree904189a17aff244fa79019bf62240b69f91cd310
parent1e59eb8f5dc93e7679ea30a7fc1b00195fe83728
direct-io: defer alignment check until after the EOF check

Prior to commit e7edf43218a3 ("Fix race when checking i_size on direct
i/o read"), an unaligned direct read past end of file would trigger EOF,
since generic_file_aio_read detected this read-at-EOF condition and
skipped the direct IO read entirely, returning 0. After that change, the
read now reaches dio_generic, which detects the misalignment and returns
EINVAL.

This consolidates the generic direct-io to follow the same behavior of
filesystems.  Apparently, this fix will only affect ocfs2 since other
filesystems do this verification before calling do_blockdev_direct_IO,
with the exception of f2fs, which has the same bug, but is fixed in the
next patch.

it can be verified by a read loop on a file that does a partial read
before EOF (On file that doesn't end at an aligned address).  The
following code fails on an unaligned file on filesystems without
prior validation without this patch, but not on btrfs, ext4, and xfs.

  while (done < total) {
    ssize_t delta = pread(fd, buf + done, total - done, off + done);
    if (!delta)
      break;
    ...
  }

Fix this regression by moving the misalignment check to after the EOF
check added by commit 8b7328800d32 ("direct-io: Fix negative return from
dio read beyond eof").

Based on a patch by Jamie Liu.

Link: https://lore.kernel.org/r/20201008062620.2928326-4-krisman@collabora.com
Reported-by: Jamie Liu <jamieliu@google.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Jan Kara <jack@suse.cz>
fs/direct-io.c