Skip to content

Commit e587101

Browse files
Christian A. Ehrhardtgregkh
Christian A. Ehrhardt
authored andcommitted
block: Fix WARNING in _copy_from_iter
[ Upstream commit 13f3956 ] 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. Reported-by: [email protected] Closes: https://lore.kernel.org/lkml/[email protected]/t/ Reported-by: [email protected] Closes: https://lore.kernel.org/lkml/[email protected]/T/ Signed-off-by: Christian A. Ehrhardt <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 0eb02fc commit e587101

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

block/blk-map.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,19 @@ static int bio_copy_user_iov(struct request *rq, struct rq_map_data *map_data,
205205
/*
206206
* success
207207
*/
208-
if ((iov_iter_rw(iter) == WRITE &&
209-
(!map_data || !map_data->null_mapped)) ||
210-
(map_data && map_data->from_user)) {
208+
if (iov_iter_rw(iter) == WRITE &&
209+
(!map_data || !map_data->null_mapped)) {
211210
ret = bio_copy_from_iter(bio, iter);
212211
if (ret)
213212
goto cleanup;
213+
} else if (map_data && map_data->from_user) {
214+
struct iov_iter iter2 = *iter;
215+
216+
/* This is the copy-in part of SG_DXFER_TO_FROM_DEV. */
217+
iter2.data_source = ITER_SOURCE;
218+
ret = bio_copy_from_iter(bio, &iter2);
219+
if (ret)
220+
goto cleanup;
214221
} else {
215222
if (bmd->is_our_pages)
216223
zero_fill_bio(bio);

0 commit comments

Comments
 (0)