• David Howells's avatar
    iov_iter: Fix iter_xarray_get_pages{,_alloc}() · 6c776766
    David Howells authored
    The maths at the end of iter_xarray_get_pages() to calculate the actual
    size doesn't work under some circumstances, such as when it's been asked to
    extract a partial single page.  Various terms of the equation cancel out
    and you end up with actual == offset.  The same issue exists in
    iter_xarray_get_pages_alloc().
    
    Fix these to just use min() to select the lesser amount from between the
    amount of page content transcribed into the buffer, minus the offset, and
    the size limit specified.
    
    This doesn't appear to have caused a problem yet upstream because network
    filesystems aren't getting the pages from an xarray iterator, but rather
    passing it directly to the socket, which just iterates over it.  Cachefiles
    *does* do DIO from one to/from ext4/xfs/btrfs/etc. but it always asks for
    whole pages to be written or read.
    
    Fixes: 7ff50620 ("iov_iter: Add ITER_XARRAY")
    Reported-by: default avatarJeff Layton <jlayton@kernel.org>
    Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
    cc: Alexander Viro <viro@zeniv.linux.org.uk>
    cc: Dominique Martinet <asmadeus@codewreck.org>
    cc: Mike Marshall <hubcap@omnibond.com>
    cc: Gao Xiang <xiang@kernel.org>
    cc: linux-afs@lists.infradead.org
    cc: v9fs-developer@lists.sourceforge.net
    cc: devel@lists.orangefs.org
    cc: linux-erofs@lists.ozlabs.org
    cc: linux-cachefs@redhat.com
    cc: linux-fsdevel@vger.kernel.org
    Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
    6c776766
iov_iter.c 49.2 KB