Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: erofs: fix unexpected out-of-bound data access

Unexpected out-of-bound data will be read in erofs_read_raw_page
after commit 07173c3ec276 ("block: enable multipage bvecs") since
one iovec could have multiple pages.

Let's fix as what Ming's pointed out in the previous email [1].

[1] https://lore.kernel.org/lkml/20190411080953.GE421@ming.t460p/

Suggested-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Fixes: 07173c3ec276 ("block: enable multipage bvecs")
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Gao Xiang and committed by
Greg Kroah-Hartman
f4e97f5d 663d294b

+1 -1
+1 -1
drivers/staging/erofs/data.c
··· 298 298 *last_block = current_block; 299 299 300 300 /* shift in advance in case of it followed by too many gaps */ 301 - if (unlikely(bio->bi_vcnt >= bio->bi_max_vecs)) { 301 + if (bio->bi_iter.bi_size >= bio->bi_max_vecs * PAGE_SIZE) { 302 302 /* err should reassign to 0 after submitting */ 303 303 err = 0; 304 304 goto submit_bio_out;