Skip to contentSkip to conversation

virtio_blk: Fix signedness bug in virtblk_prep_rq()

PATCH In review Rafael Mendonca 5 participants 5 messages Oct 21, 2022 – Nov 7, 2022

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

PATCH 1/1 virtio_blk: Fix signedness bug in virtblk_prep_rq()

The virtblk_map_data() function returns negative error codes, however, the 'nents' field of vbr->sg_table is an unsigned int, which causes the error handling not to work correctly.

Fixes 0e9911fa768f ("virtio-blk: support mq_ops->queue_rqs()")
---
 drivers/block/virtio_blk.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/block/virtio_blk.c +4 -2
index 19da5defd734..291f705e61a8 100644
@@ -321,16 +321,18 @@ static blk_status_t virtblk_prep_rq(struct blk_mq_hw_ctx *hctx,
 					struct virtblk_req *vbr)
 {
 	blk_status_t status;
+	int num;
 
 	status = virtblk_setup_cmd(vblk->vdev, req, vbr);
 	if (unlikely(status))
 		return status;
 
-	vbr->sg_table.nents = virtblk_map_data(hctx, req, vbr);
-	if (unlikely(vbr->sg_table.nents < 0)) {
+	num = virtblk_map_data(hctx, req, vbr);
+	if (unlikely(num < 0)) {
 		virtblk_cleanup_cmd(req);
 		return BLK_STS_RESOURCE;
 	}
+	vbr->sg_table.nents = num;
 
 	blk_mq_start_request(req);
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Rafael Mendonca

The virtblk_map_data() function returns negative error codes, however, the 'nents' field of vbr->sg_table is an unsigned int, which causes the error handling not to work correctly.

Fixes 0e9911fa768f ("virtio-blk: support mq_ops->queue_rqs()")

---
drivers/block/virtio_blk.c | 6 ++++--

1 file changed, 4 insertions(+), 2 deletions(-)

Good catch!

Quoted 29 lines
drivers/block/virtio_blk.c +4 -2
index 19da5defd734..291f705e61a8 100644
@@ -321,16 +321,18 @@ static blk_status_t virtblk_prep_rq(struct blk_mq_hw_ctx *hctx,
 					struct virtblk_req *vbr)
 {
 	blk_status_t status;
+	int num;
 
 	status = virtblk_setup_cmd(vblk->vdev, req, vbr);
 	if (unlikely(status))
 		return status;
 
-	vbr->sg_table.nents = virtblk_map_data(hctx, req, vbr);
-	if (unlikely(vbr->sg_table.nents < 0)) {
+	num = virtblk_map_data(hctx, req, vbr);
+	if (unlikely(num < 0)) {
 		virtblk_cleanup_cmd(req);
 		return BLK_STS_RESOURCE;
 	}
+	vbr->sg_table.nents = num;
 
 	blk_mq_start_request(req);
 
Signature · 1 line
2.34.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Rafael Mendonca
Quoted 9 lines · Rafael Mendonca

The virtblk_map_data() function returns negative error codes, however, the 'nents' field of vbr->sg_table is an unsigned int, which causes the error handling not to work correctly.

Fixes 0e9911fa768f ("virtio-blk: support mq_ops->queue_rqs()")
---
 drivers/block/virtio_blk.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Reviewed-by on v1 1/1
#3 lore raw
In reply to Rafael Mendonca
Quoted 37 lines · Rafael Mendonca

The virtblk_map_data() function returns negative error codes, however, the 'nents' field of vbr->sg_table is an unsigned int, which causes the error handling not to work correctly.

Fixes 0e9911fa768f ("virtio-blk: support mq_ops->queue_rqs()")
---
 drivers/block/virtio_blk.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/block/virtio_blk.c +4 -3
index 19da5defd734..291f705e61a8 100644
@@ -321,16 +321,18 @@ static blk_status_t virtblk_prep_rq(struct blk_mq_hw_ctx *hctx,
                                        struct virtblk_req *vbr)
 {
        blk_status_t status;
+       int num;
 
        status = virtblk_setup_cmd(vblk->vdev, req, vbr);
        if (unlikely(status))
                return status;
 
-       vbr->sg_table.nents = virtblk_map_data(hctx, req, vbr);
-       if (unlikely(vbr->sg_table.nents < 0)) {
+       num = virtblk_map_data(hctx, req, vbr);
+       if (unlikely(num < 0)) {
                virtblk_cleanup_cmd(req);
                return BLK_STS_RESOURCE;
        }
+       vbr->sg_table.nents = num;
 
        blk_mq_start_request(req);
 
--
Quoted 2 lines

2.34.1

Looks good to me!

Acked-by on v1 1/1
#4 lore raw
In reply to Rafael Mendonca
Quoted 7 lines · Rafael Mendonca

The virtblk_map_data() function returns negative error codes, however, the 'nents' field of vbr->sg_table is an unsigned int, which causes the error handling not to work correctly.

Fixes 0e9911fa768f ("virtio-blk: support mq_ops->queue_rqs()")

Do we need to cc the stable?

Thanks

Quoted 30 lines
---
 drivers/block/virtio_blk.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/block/virtio_blk.c +4 -3
index 19da5defd734..291f705e61a8 100644
@@ -321,16 +321,18 @@ static blk_status_t virtblk_prep_rq(struct blk_mq_hw_ctx *hctx,
                                        struct virtblk_req *vbr)
 {
        blk_status_t status;
+       int num;
 
        status = virtblk_setup_cmd(vblk->vdev, req, vbr);
        if (unlikely(status))
                return status;
 
-       vbr->sg_table.nents = virtblk_map_data(hctx, req, vbr);
-       if (unlikely(vbr->sg_table.nents < 0)) {
+       num = virtblk_map_data(hctx, req, vbr);
+       if (unlikely(num < 0)) {
                virtblk_cleanup_cmd(req);
                return BLK_STS_RESOURCE;
        }
+       vbr->sg_table.nents = num;
 
        blk_mq_start_request(req);
 
--
Quoted 2 lines

2.34.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization