Skip to contentSkip to conversation

ublk: remove WARN_ON_ONCE() in ublk_unmap_io()

PATCH In review Caleb Sander Mateos 2 participants 4 messages Jul 27 – Jul 29

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ublk: remove WARN_ON_ONCE() in ublk_unmap_io()

io->res is set from struct ublksrv_io_cmd's result field, which is controlled by the ublk server process, without any validation. It's thus possible for userspace to trigger the io->res > rq_bytes warning. ublk_copy_user_pages() already limits the copy length to the request data length, so drop the warning.

---
 drivers/block/ublk_drv.c | 2 --
 1 file changed, 2 deletions(-)
drivers/block/ublk_drv.c +0 -2
index 4ca6ec738c93..4f30644756df 100644
@@ -1492,12 +1492,10 @@ static unsigned int ublk_unmap_io(bool need_map,
 
 	if (ublk_need_unmap_req(req)) {
 		struct iov_iter iter;
 		const int dir = ITER_SOURCE;
 
-		WARN_ON_ONCE(io->res > rq_bytes);
-
 		import_ubuf(dir, u64_to_user_ptr(io->buf.addr), io->res, &iter);
 		return ublk_copy_user_pages(req, 0, &iter, dir);
 	}
 	return rq_bytes;
 }
Signature · 1 line
2.54.0
maintainer
#1 lore raw
Quoted 18 lines · Caleb Sander Mateos

io->res is set from struct ublksrv_io_cmd's result field, which is controlled by the ublk server process, without any validation. It's thus possible for userspace to trigger the io->res > rq_bytes warning. ublk_copy_user_pages() already limits the copy length to the request data length, so drop the warning.

---
 drivers/block/ublk_drv.c | 2 --
 1 file changed, 2 deletions(-)
drivers/block/ublk_drv.c +0 -0
index 4ca6ec738c93..4f30644756df 100644
@@ -1492,12 +1492,10 @@ static unsigned int ublk_unmap_io(bool need_map,
 

drivers/block/ublk_drv.c static unsigned int ublk_unmap_io(bool need_map, · line 1500

Quoted 10 lines
drivers/block/ublk_drv.c +0 -2
        if (ublk_need_unmap_req(req)) {
                struct iov_iter iter;
                const int dir = ITER_SOURCE;
 
-               WARN_ON_ONCE(io->res > rq_bytes);
-
                import_ubuf(dir, u64_to_user_ptr(io->buf.addr), io->res, &iter);
                return ublk_copy_user_pages(req, 0, &iter, dir);
        }
        return rq_bytes;

The change may be fine, however access_ok() still can fail from import_ubuf(), so can we consolidate ublk_unmap_io() a bit?

Thanks,
Ming Lei

#2 lore raw
Quoted 25 lines · Ming Lei
Quoted 22 lines · Caleb Sander Mateos

io->res is set from struct ublksrv_io_cmd's result field, which is controlled by the ublk server process, without any validation. It's thus possible for userspace to trigger the io->res > rq_bytes warning. ublk_copy_user_pages() already limits the copy length to the request data length, so drop the warning.

---
 drivers/block/ublk_drv.c | 2 --
 1 file changed, 2 deletions(-)
drivers/block/ublk_drv.c +0 -0
index 4ca6ec738c93..4f30644756df 100644
@@ -1492,12 +1492,10 @@ static unsigned int ublk_unmap_io(bool need_map,
 
        if (ublk_need_unmap_req(req)) {
                struct iov_iter iter;
                const int dir = ITER_SOURCE;
 
Quoted 9 lines

drivers/block/ublk_drv.c static unsigned int ublk_unmap_io(bool need_map, · line 1500

Quoted 6 lines
drivers/block/ublk_drv.c +0 -2
-               WARN_ON_ONCE(io->res > rq_bytes);
-
                import_ubuf(dir, u64_to_user_ptr(io->buf.addr), io->res, &iter);
                return ublk_copy_user_pages(req, 0, &iter, dir);
        }
        return rq_bytes;

The change may be fine, however access_ok() still can fail from import_ubuf(), so can we consolidate ublk_unmap_io() a bit?

Sorry, not quite sure what you mean by "consolidate". Are you saying there should be a check of the import_ubuf() return value in ublk_map_io() and ublk_unmap_io()?

Thanks,
Caleb

maintainer
#3 lore raw
Quoted 36 lines · Caleb Sander Mateos
Quoted 25 lines · Ming Lei
Quoted 22 lines · Caleb Sander Mateos

io->res is set from struct ublksrv_io_cmd's result field, which is controlled by the ublk server process, without any validation. It's thus possible for userspace to trigger the io->res > rq_bytes warning. ublk_copy_user_pages() already limits the copy length to the request data length, so drop the warning.

---
 drivers/block/ublk_drv.c | 2 --
 1 file changed, 2 deletions(-)
drivers/block/ublk_drv.c +0 -0
index 4ca6ec738c93..4f30644756df 100644
@@ -1492,12 +1492,10 @@ static unsigned int ublk_unmap_io(bool need_map,
 
        if (ublk_need_unmap_req(req)) {
                struct iov_iter iter;
                const int dir = ITER_SOURCE;
 
Quoted 9 lines

drivers/block/ublk_drv.c static unsigned int ublk_unmap_io(bool need_map, · line 1500

Quoted 6 lines
drivers/block/ublk_drv.c +0 -2
-               WARN_ON_ONCE(io->res > rq_bytes);
-
                import_ubuf(dir, u64_to_user_ptr(io->buf.addr), io->res, &iter);
                return ublk_copy_user_pages(req, 0, &iter, dir);
        }
        return rq_bytes;

The change may be fine, however access_ok() still can fail from import_ubuf(), so can we consolidate ublk_unmap_io() a bit?

Quoted 3 lines

Sorry, not quite sure what you mean by "consolidate". Are you saying there should be a check of the import_ubuf() return value in ublk_map_io() and ublk_unmap_io()?

Yeah.

Thanks,
Ming