Skip to content

Commit 116358c

Browse files
Ming Leikawasaki
authored andcommitted
ublk: use unchecked copy helpers for bio page data
Bio pages may originate from slab caches that lack a usercopy region (e.g. jbd2 frozen metadata buffers allocated via jbd2_alloc()). When CONFIG_HARDENED_USERCOPY is enabled, copy_to_iter() calls check_copy_size() which rejects these slab pages, triggering a kernel BUG in usercopy_abort(). This is a false positive: the data is ordinary block I/O content — the same data the loop/nbd driver writes to its backing file via vfs_iter_write(). The bvec length is always trusted, so the size check in check_copy_size() is not needed either. Switch to _copy_to_iter()/_copy_from_iter() which skip the check_copy_size() wrapper while the underlying copy_to_user() remains unchanged. Fixes: 2299cee ("ublk: use copy_{to,from}_iter() for user copy") Signed-off-by: Ming Lei <[email protected]> Acked-by: Caleb Sander Mateos <[email protected]>
1 parent 8f17195 commit 116358c

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

drivers/block/ublk_drv.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,10 +1281,18 @@ static bool ublk_copy_user_bvec(const struct bio_vec *bv, unsigned *offset,
12811281

12821282
len = bv->bv_len - *offset;
12831283
bv_buf = kmap_local_page(bv->bv_page) + bv->bv_offset + *offset;
1284+
/*
1285+
* Bio pages may originate from slab caches without a usercopy region
1286+
* (e.g. jbd2 frozen metadata buffers). This is the same data that
1287+
* the loop driver writes to its backing file — no exposure risk.
1288+
* The bvec length is always trusted, so the size check in
1289+
* check_copy_size() is not needed either. Use the unchecked
1290+
* helpers to avoid false positives on slab pages.
1291+
*/
12841292
if (dir == ITER_DEST)
1285-
copied = copy_to_iter(bv_buf, len, uiter);
1293+
copied = _copy_to_iter(bv_buf, len, uiter);
12861294
else
1287-
copied = copy_from_iter(bv_buf, len, uiter);
1295+
copied = _copy_from_iter(bv_buf, len, uiter);
12881296

12891297
kunmap_local(bv_buf);
12901298

0 commit comments

Comments
 (0)