[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 22/22] scsi: Guard against buflen exceeding req->cmd
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 22/22] scsi: Guard against buflen exceeding req->cmd.xfer in scsi_disk_emulate_command |
Date: |
Thu, 26 Jan 2012 17:38:16 +0100 |
From: Thomas Higdon <address@hidden>
Limit the return value (corresponding to the length of the buffer to be
DMAed back to the intiator) to the value in req->cmd.xfer, which is the
amount of data that the initiator expects. Eliminate now-duplicate code
that does this guarding in the functions for individual commands.
Without this, the SCRIPTS code in the emulated LSI device eventually
raises a DMA interrupt for a data overrun when an INQUIRY command whose
buflen exceeds req->cmd.xfer is processed. It's the responsibility of
the client to provide a request buffer and allocation length that are
large enough for the result of the command.
Signed-off-by: Thomas Higdon <address@hidden>
Reviewed-by: Paolo Bonzini <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
hw/scsi-disk.c | 10 +---------
1 files changed, 1 insertions(+), 9 deletions(-)
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 5d8bf53..11cfe73 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -391,9 +391,6 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req,
uint8_t *outbuf)
}
l = strlen(s->serial);
- if (l > req->cmd.xfer) {
- l = req->cmd.xfer;
- }
if (l > 20) {
l = 20;
}
@@ -1002,9 +999,6 @@ static int scsi_disk_emulate_mode_sense(SCSIDiskReq *r,
uint8_t *outbuf)
outbuf[0] = ((buflen - 2) >> 8) & 0xff;
outbuf[1] = (buflen - 2) & 0xff;
}
- if (buflen > r->req.cmd.xfer) {
- buflen = r->req.cmd.xfer;
- }
return buflen;
}
@@ -1038,9 +1032,6 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req,
uint8_t *outbuf)
default:
return -1;
}
- if (toclen > req->cmd.xfer) {
- toclen = req->cmd.xfer;
- }
return toclen;
}
@@ -1251,6 +1242,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r)
scsi_check_condition(r, SENSE_CODE(INVALID_OPCODE));
return -1;
}
+ buflen = MIN(buflen, req->cmd.xfer);
return buflen;
not_ready:
--
1.7.6.5
- [Qemu-devel] [PATCH 15/22] add QERR_BASE_NOT_FOUND, (continued)
- [Qemu-devel] [PATCH 15/22] add QERR_BASE_NOT_FOUND, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 11/22] qmp: add block_job_cancel command, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 19/22] block/vdi: Zero unused parts when allocating a new block (fix #919242), Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 13/22] blockdev: make image streaming safe across hotplug, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 18/22] virtio-blk: add virtio_blk_handle_read trace event, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 17/22] docs: describe live block operations, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 14/22] block: add bdrv_find_backing_image, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 21/22] qcow: Use bdrv functions to replace file operation, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 20/22] qcow: Return real error code in qcow_open, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 16/22] block: add support for partial streaming, Kevin Wolf, 2012/01/26
- [Qemu-devel] [PATCH 22/22] scsi: Guard against buflen exceeding req->cmd.xfer in scsi_disk_emulate_command,
Kevin Wolf <=
- Re: [Qemu-devel] [PULL 00/22] Block patches, Anthony Liguori, 2012/01/27