block: Fix WARNING in _copy_from_iter
PATCH 1/1 block: Fix WARNING in _copy_from_iter
Syzkaller reports a warning in _copy_from_iter because an iov_iter is supposedly used in the wrong direction. The reason is that syzcaller managed to generate a request with a transfer direction of SG_DXFER_TO_FROM_DEV. This instructs the kernel to copy user buffers into the kernel, read into the copied buffers and then copy the data back to user space.
Thus the iovec is used in both directions.
Detect this situation in the block layer and construct a new iterator with the correct direction for the copy-in.
--- block/blk-map.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
block/blk-map.c +10 -3
@@ -205,12 +205,19 @@ static int bio_copy_user_iov(struct request *rq, struct rq_map_data *map_data,/* * success */ -if ((iov_iter_rw (iter) ==WRITE && - (!map_data || !map_data->null_mapped)) || - (map_data && map_data->from_user)) { +if (iov_iter_rw (iter) ==WRITE && + (!map_data || !map_data->null_mapped)) { ret =bio_copy_from_iter (bio, iter);if (ret) goto cleanup; + }else if (map_data && map_data->from_user) { +struct iov_iter iter2 = *iter; + +/* This is the copy-in part of SG_DXFER_TO_FROM_DEV. */ + iter2.data_source =ITER_SOURCE ; + ret =bio_copy_from_iter (bio, &iter2); +if (ret) + goto cleanup; }else {if (bmd->is_our_pages)zero_fill_bio (bio);
Signature · 1 line
2.40.1
Looks good:
(although I really wish we could kill the whole map-data crap..)
Quoted 8 lines · Christian A. Ehrhardt
Syzkaller reports a warning in
_copy_from_iterbecause aniov_iteris supposedly used in the wrong direction. The reason is that syzcaller managed to generate a request with a transfer direction ofSG_DXFER_TO_FROM_DEV. This instructs the kernel to copy user buffers into the kernel, read into the copied buffers and then copy the data back to user space.[...]
Applied, thanks!
[1/1] block: Fix WARNING in _copy_from_iter
commit: 13f3956eb5681a4045a8dfdef48df5dc4d9f58a6
Best regards,
Signature · 1 line
Jens Axboe