Skip to content

iomap, splice: Fix DIO/splice_read race memory corruptor and kill off ITER_PIPE

David Howells linux-block linux-fsdevel linux-mm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 2 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2vfs, iomap: Fix generic_file_splice_read() to avoid reversion of ITER_PIPEfs/splice.c+68 -80 replies
2/2iov_iter: Kill ITER_PIPEfs/cifs/file.c include/linux/uio.h lib/iov_iter.c +1 more+4 -5130 replies

Reviews trailers per patch

None of the 2 patches has a Reviewed-by or Acked-by.

Patch[email protected]
1/2T-b
2/2T-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 0/2] iomap, splice: Fix DIO/splice_read race memory corruptor and kill off ITER_PIPE

Hi Jens, Christoph, Al,

Syzbot found a bug[1] that my bio/FOLL_PIN code[2] inadvertently introduced. The problem is that with my patches, pages obtained from kernel-backed iterators aren't ref'd or pinned when they're extracted and thus struct bio doesn't retain them. A DIO-read from a file through iomap that races with truncate may in __iomap_dio_rw() call iov_iter_revert() on the iov_iter it was given.

Unfortunately, if the iterator is an ITER_PIPE, the reversion has side
effects: the pages rolled back get released. Those pages, however, are not retained by the uncompleted bio and may get modified after their release.

The first patch fixes this by switching to bulk allocating all the necessary pages up front and adding them to an ITER_BVEC iterator, doing the I/O and only then trimming the excess pages. The remaining pages are then pushed into the pipe. This has the downside (as the code stands) of not handling any partial page lurking in the pipe - though that could be places as the first element in the bvec. OTOH, using the bulk allocation API should be more efficient.

As this is the only user of ITER_PIPE, the second patch removes ITER_PIPE and all its associated iov_iter helper functions.

Thanks to Hillf Danton for spotting that iov_iter_revert() was involved[3].

[!] Jens: Note that there's a window in the linux-block/for-next branch
with a memory corruptor bug that someone bisecting might hit. These two patches would be better pushed to the front of my iov-extract branch to eliminate the window. Would it be possible for you to replace my branch in your for-next branch at this point?

I've pushed the patches here also:

https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=iov-fixes

David

David Howells (2):
vfs, iomap: Fix generic_file_splice_read() to avoid reversion of
ITER_PIPE
iov_iter: Kill ITER_PIPE

 fs/cifs/file.c      |   8 +-
 fs/splice.c         |  76 ++++++-
 include/linux/uio.h |  14 --
 lib/iov_iter.c      | 492 +-------------------------------------------
 mm/filemap.c        |   3 -
 5 files changed, 72 insertions(+), 521 deletions(-)