Skip to contentSkip to conversation

ublk: use unchecked copy helpers for bio page data

PATCH Applied Ming Lei 2 participants 2 messages Apr 15 – Apr 17

Subsystems (2)
lore
Share & tools
lore

Ming Lei

author maintainer
#0 lore raw

PATCH v3 1/1 ublk: use unchecked copy helpers for bio page data

From: Ming Lei <[email protected]>

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 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 2299ceec364e ("ublk: use copy_{to,from}_iter() for user copy")

---
V3:
- rebase & add acked-by tag
V2:
- update commit log (Caleb Sander Mateos)

 drivers/block/ublk_drv.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/block/ublk_drv.c +10 -2
index 603a98a30989..ef8a0705e68b 100644
@@ -1319,10 +1319,18 @@ static bool ublk_copy_user_bvec(const struct bio_vec *bv, unsigned *offset,
 
 	len = bv->bv_len - *offset;
 	bv_buf = kmap_local_page(bv->bv_page) + bv->bv_offset + *offset;
+	/*
+	 * Bio pages may originate from slab caches without a usercopy region
+	 * (e.g. jbd2 frozen metadata buffers).  This is the same data that
+	 * the loop driver writes to its backing file — no exposure risk.
+	 * The bvec length is always trusted, so the size check in
+	 * check_copy_size() is not needed either.  Use the unchecked
+	 * helpers to avoid false positives on slab pages.
+	 */
 	if (dir == ITER_DEST)
-		copied = copy_to_iter(bv_buf, len, uiter);
+		copied = _copy_to_iter(bv_buf, len, uiter);
 	else
-		copied = copy_from_iter(bv_buf, len, uiter);
+		copied = _copy_from_iter(bv_buf, len, uiter);
 
 	kunmap_local(bv_buf);
 
Signature · 1 line
2.53.0
maintainer Applied
#1 lore raw
Quoted 6 lines · Ming Lei

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().

Quoted 6 lines

This is a false positive: the data is ordinary block I/O content — the same data the loop 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.

[...]

Applied, thanks!

[1/1] ublk: use unchecked copy helpers for bio page data

      commit: a7c9fa7f6601c84d27cdd43bd96e8fcbacfb7479

Best regards,

Signature · 1 line
Jens Axboe