block: fix leaking page ref on truncated direct io for-5.20/block-iter
authorKeith Busch <kbusch@kernel.org>
Tue, 12 Jul 2022 15:32:56 +0000 (08:32 -0700)
committerJens Axboe <axboe@kernel.dk>
Wed, 13 Jul 2022 20:20:41 +0000 (14:20 -0600)
commit44b6b0b0e980d99d24de7e5d57baae48a78db3b6
tree6314746d47174913ec5994754b73e5e5baa2a2b4
parentac3c48e32c047a3781d6bc28bb5013e4431350fd
block: fix leaking page ref on truncated direct io

The size being added to a bio from an iov is aligned to a block size
after the pages were gotten. If the new aligned size truncates the last
page, its reference was being leaked. Ensure all pages that were not
added to the bio have their reference released.

Since this essentially requires doing the same that bio_put_pages(), and
there was only one caller for that function, this patch makes the
put_page() loop common for everyone.

Fixes: b1a000d3b8ec5 ("block: relax direct io memory alignment")
Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Link: https://lore.kernel.org/r/20220712153256.2202024-3-kbusch@fb.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/bio.c