Skip to content

block: validate direct I/O memory alignment

Keith Busch dm-devel linux-block linux-fsdevel regressions stable 1 version Applied

Status from this message: Applied, thanks!

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest5 patches 15 repliesApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/5block: use blkdev_iov_iter_get_pages status for errorsblock/fops.c+1 -10 replies
2/5block: fix dio leak on metadata mapping errorblock/fops.c+4 -20 replies
3/5loop: set dma_alignment from the backing file for direct I/Odrivers/block/loop.c+38 -80 replies
4/5zloop: set dma_alignment from the backing files for direct I/Odrivers/block/zloop.c+25 -100 replies
5/5block: validate user space vectors during extractionblock/bio.c block/blk-map.c block/fops.c +4 more+74 -84 replies

Reviews trailers per patch

All 5 patches have a Reviewed-by or Acked-by.

PatchHannes ReineckeChristoph Hellwig
1/5R-b R-b
2/5R-b R-b
3/5R-b R-b
4/5R-b R-b
5/5R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH RESEND 0/5] block: validate direct I/O memory alignment

From: Keith Busch <[email protected]>

Resending in case this got lost.

This addresses the misaligned direct-io problem behind various threads:

https://lore.kernel.org/linux-xfs/[email protected]/
https://lore.kernel.org/all/CAC_j7i1R7oy+nRhxEjCTba=DUgn02w9X+p94DCu0aHv5+5tKnQ@mail.gmail.com/
https://lore.kernel.org/linux-block/ai7rnH20IYeSmY8s@gallifrey/
https://lore.kernel.org/linux-block/[email protected]/

The previously tested fixes are correct as far as they go, but they treat the symptom: they only matter because an invalid bio reaches those drivers in the first place.

The reason it reaches them is an assumption I made when I removed direct-io alignment checks in 5ff3f74e145a ("block: simplify direct io validity check") and 7eac331869575 ("iomap: simplify direct io validity check"): every bio is eventually split to the device limits, and the upper layers cope with resulting errors once the bio has formed. Both were optimistic assumptions. Drivers with their own ->submit_bio may never pass through blk_mq_submit_bio()'s split, so the check never runs for them, and as numerous threads showed, the consumers don't uniformly handle this condition.

This series stops the invalid bio at the source instead. It validates the buffer's alignment against the alignment limits when the bio is built from the iov_iter. The check is folded into the bvec extraction that already walks the vectors, so it adds only a comparison on a path that is pinning direct-io pages anyway. Misalignment is now uniformly rejected with EINVAL before submission for every direct-io path.

Only changes in this version are just adding the reviewers from the previous:

https://lore.kernel.org/linux-block/[email protected]/

Keith Busch (5):
block: use blkdev_iov_iter_get_pages status for errors
block: fix dio leak on metadata mapping error
loop: set dma_alignment from the backing file for direct I/O
zloop: set dma_alignment from the backing files for direct I/O
block: validate user space vectors during extraction

 block/bio.c           | 56 ++++++++++++++++++++++++++++++++++++++++---
 block/blk-map.c       |  2 +-
 block/fops.c          | 10 ++++----
 drivers/block/loop.c  | 46 ++++++++++++++++++++++++++++-------
 drivers/block/zloop.c | 35 +++++++++++++++++++--------
 fs/iomap/direct-io.c  |  1 +
 include/linux/bio.h   |  2 +-
 include/linux/uio.h   | 10 +++++++-
 lib/iov_iter.c        |  9 ++++++-
 9 files changed, 142 insertions(+), 29 deletions(-)
Signature · 1 line
2.52.0