bch2_direct_IO_read() checks the request offset and size for sector alignment and then falls through to a couple calculations to shrink the size of the request based on the inode size. The problem is that these checks round up to the fs block size, which runs the risk of underflowing iter->count if the block size happens to be large enough. This is triggered by fstest generic/361 with a 4k block size, which subsequently leads to a crash.
After some discussion, the original purpose of the shorten logic in this path is not totally clear. It appears to be intended as an optimization of limited value, so simplify things and avoid the underflow problem by removing it. Signed-off-by: Brian Foster <[email protected]> --- Note that I left the ret variable name alone because it seemed to bother me less after we realized it is actually the dio return value. Brian fs/bcachefs/fs-io-direct.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/fs/bcachefs/fs-io-direct.c b/fs/bcachefs/fs-io-direct.c index e3b219e19e10..53f6e8a939d5 100644 --- a/fs/bcachefs/fs-io-direct.c +++ b/fs/bcachefs/fs-io-direct.c @@ -72,7 +72,6 @@ static int bch2_direct_IO_read(struct kiocb *req, struct iov_iter *iter) struct bio *bio; loff_t offset = req->ki_pos; bool sync = is_sync_kiocb(req); - size_t shorten; ssize_t ret; bch2_inode_opts_get(&opts, c, &inode->ei_inode); @@ -87,9 +86,6 @@ static int bch2_direct_IO_read(struct kiocb *req, struct iov_iter *iter) if (!ret) return ret; - shorten = iov_iter_count(iter) - round_up(ret, block_bytes(c)); - iter->count -= shorten; - bio = bio_alloc_bioset(NULL, bio_iov_vecs_to_alloc(iter, BIO_MAX_VECS), REQ_OP_READ, @@ -158,8 +154,6 @@ static int bch2_direct_IO_read(struct kiocb *req, struct iov_iter *iter) bch2_read(c, rbio_init(bio, opts), inode_inum(inode)); } - iter->count += shorten; - if (sync) { closure_sync(&dio->cl); closure_debug_destroy(&dio->cl); -- 2.42.0
