]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
iov_iter: Fix iter_xarray_get_pages{,_alloc}()
authorDavid Howells <dhowells@redhat.com>
Thu, 9 Jun 2022 08:07:01 +0000 (09:07 +0100)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 26 Aug 2022 08:53:01 +0000 (10:53 +0200)
commit93b0b089de762aa3580b9a080fb196d0ea104fd1
tree64d5bb9d842399b56ba96f80ffa7862636927f7f
parent9acf3d8ac113e97b0780dd92d89858d4eeca44e6
iov_iter: Fix iter_xarray_get_pages{,_alloc}()

BugLink: https://bugs.launchpad.net/bugs/1982968
[ Upstream commit 6c77676645ad42993e0a8bdb8dafa517851a352a ]

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: 7ff5062079ef ("iov_iter: Add ITER_XARRAY")
Reported-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: David 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: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
lib/iov_iter.c