block: advance iterator after copy-in for SG_DXFER_TO_FROM_DEV
PATCH 1/1 block: advance iterator after copy-in for SG_DXFER_TO_FROM_DEV
When a passthrough request uses transfer direction SG_DXFER_TO_FROM_DEV, bio_copy_user_iov() sets up a temporary iterator iter2 with data_source = ITER_SOURCE to copy user data into the bio pages before execution.
bio_copy_from_iter(bio, &iter2) copies the data and advances iter2, but the original iter is never advanced. Consequently, iov_iter_count(&i) remains non-zero in the caller loop in blk_rq_map_user_iov():
i = *iter;
do {
if (copy)
ret = bio_copy_user_iov(rq, map_data, &i, gfp_mask);
...
} while (iov_iter_count(&i));Because i is never advanced, blk_rq_map_user_iov() loops indefinitely, continually allocating bios and consuming map_data pages until it exhausts pages and fails with -EINVAL.
Fix this by calling iov_iter_advance(iter, bio->bi_iter.bi_size) in the map_data && map_data->from_user branch after bio_copy_from_iter().
--- block/blk-map.c | 1 + 1 file changed, 1 insertion(+)
block/blk-map.c +1 -0
@@ -236,6 +236,7 @@ static int bio_copy_user_iov(struct request *rq, struct rq_map_data *map_data, ret =bio_copy_from_iter (bio, &iter2);if (ret) goto cleanup; +iov_iter_advance (iter, bio->bi_iter.bi_size); }else {if (bmd->is_our_pages)zero_fill_bio (bio);
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
Quoted 3 lines · TJ Adams
When a passthrough request uses transfer direction
SG_DXFER_TO_FROM_DEV,bio_copy_user_iov()sets up a temporary iterator iter2 with
...
Quoted 9 lines
ret = bio_copy_from_iter(bio, &iter2); if (ret) goto cleanup; + iov_iter_advance(iter, bio->bi_iter.bi_size); } else { if (bmd->is_our_pages) zero_fill_bio(bio);--
2.56.0.rc1.315.gc6ed9934b7-goog
Gentle ping on this fix. Please let me know if you have any questions or feedback.
Thanks,
TJ Adams
Hi,
Quoted 16 lines · TJ Adams
When a passthrough request uses transfer direction
SG_DXFER_TO_FROM_DEV,bio_copy_user_iov()sets up a temporary iterator iter2 withdata_source=ITER_SOURCEto copy user data into the bio pages before execution.
bio_copy_from_iter(bio, &iter2)copies the data and advances iter2, but the original iter is never advanced. Consequently,iov_iter_count(&i)remains non-zero in the caller loop inblk_rq_map_user_iov():i = *iter; do { if (copy) ret = bio_copy_user_iov(rq, map_data, &i, gfp_mask); ... } while (iov_iter_count(&i));
Quoted 6 lines
Because i is never advanced,
blk_rq_map_user_iov()loops indefinitely, continually allocating bios and consumingmap_datapages until it exhausts pages and fails with-EINVAL.Fix this by calling
iov_iter_advance(iter, bio->bi_iter.bi_size)in themap_data&&map_data->from_userbranch afterbio_copy_from_iter().
Sorry for being lazy on this (and for messing it up).
Thanks,
Christian
Quoted 24 lines
Fixes 13f3956eb568 ("block: Fix WARNING in _copy_from_iter")Signed-off-by Terrence Adams <[email protected]>Assisted-by LLM--- block/blk-map.c | 1 + 1 file changed, 1 insertion(+)block/blk-map.c +1
-0@@ -236,6 +236,7 @@ static int bio_copy_user_iov(struct request *rq, struct rq_map_data *map_data, ret =bio_copy_from_iter (bio, &iter2);if (ret) goto cleanup; +iov_iter_advance (iter, bio->bi_iter.bi_size); }else {if (bmd->is_our_pages)zero_fill_bio (bio);Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog
Quoted 10 lines · TJ Adams
When a passthrough request uses transfer direction
SG_DXFER_TO_FROM_DEV,bio_copy_user_iov()sets up a temporary iterator iter2 withdata_source=ITER_SOURCEto copy user data into the bio pages before execution.
bio_copy_from_iter(bio, &iter2)copies the data and advances iter2, but the original iter is never advanced. Consequently,iov_iter_count(&i)remains non-zero in the caller loop inblk_rq_map_user_iov():[...]
Applied, thanks!
[1/1] block: advance iterator after copy-in for SG_DXFER_TO_FROM_DEV
commit: 82e72ea18d0af724914c31a1f274c1aef452aad0
Best regards,
Signature · 1 line
Jens Axboe