scsi: do not overwrite memory on REQUEST SENSE commands with a large buffer
PATCH 1/1 scsi: do not overwrite memory on REQUEST SENSE commands with a large buffer
Other scsi_target_reqops commands were careful about not using r->cmd.xfer directly, and instead always cap it to a fixed length. This was not done for REQUEST SENSE, and this patch fixes it.
---
The way you called REQUEST SENSE from OpenBIOS is correct, the bug is clearly in QEMU. However, I would like to stress that you do not need to call it. Sense data is automatically overwritten by the next command, but it is only reported after a command returned CHECK CONDITION. So, REQUEST SENSE always gets you information too late. That's why in your case what you want is TEST UNIT READY. If you want, after each failed TEST UNIT READY command you _can_ REQUEST SENSE and check that indeed you're getting a unit attention and not another sense key, but that's not really necessary.
hw/scsi-bus.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
hw/scsi-bus.c +2 -1
@@ -292,7 +292,8 @@ static int32_t scsi_target_send_command(SCSIRequest *req, uint8_t *buf)if (req->cmd.xfer <4 ) { goto illegal_request; } - r->len =scsi_device_get_sense (r->req.dev, r->buf, req->cmd.xfer, + r->len =scsi_device_get_sense (r->req.dev, r->buf, +MIN (req->cmd.xfer,sizeof r->buf), (req->cmd.buf[1 ] &1 ) ==0 );break ;default :
Signature · 1 line
1.7.6
Blue Swirl
AppliedThanks, applied.
Quoted 39 lines · Paolo Bonzini
Other
scsi_target_reqopscommands were careful about not usingr->cmd.xferdirectly, and instead always cap it to a fixed length. This was not done for REQUEST SENSE, and this patch fixes it.Reported-by Blue Swirl <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>---
The way you called REQUEST SENSE from OpenBIOS is correct, the bug is clearly in QEMU. However, I would like to stress that you do not need to call it. Sense data is automatically overwritten by the next command, but it is only reported after a command returned CHECK CONDITION. So, REQUEST SENSE always gets you information too late. That's why in your case what you want is TEST UNIT READY. If you want, after each failed TEST UNIT READY command you _can_ REQUEST SENSE and check that indeed you're getting a unit attention and not another sense key, but that's not really necessary.hw/scsi-bus.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)hw/scsi-bus.c +2
-1@@ -292,7 +292,8 @@ static int32_t scsi_target_send_command(SCSIRequest *req, uint8_t *buf) if (req->cmd.xfer < 4) { goto illegal_request; } - r->len = scsi_device_get_sense(r->req.dev, r->buf, req->cmd.xfer, + r->len = scsi_device_get_sense(r->req.dev, r->buf, + MIN(req->cmd.xfer, sizeof r->buf), (req->cmd.buf[1] & 1) == 0); break;default:
--
1.7.6