Skip to content

Commit

Permalink
scsi: esp: make cmdbuf big enough for maximum CDB size
Browse files Browse the repository at this point in the history
While doing DMA read into ESP command buffer 's->cmdbuf', it could
write past the 's->cmdbuf' area, if it was transferring more than 16
bytes.  Increase the command buffer size to 32, which is maximum when
's->do_cmd' is set, and add a check on 'len' to avoid OOB access.

Reported-by: Li Qiang <liqiang6-s@360.cn>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 926cde5)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
  • Loading branch information
Prasad J Pandit authored and mdroth committed Aug 9, 2016
1 parent 8c04a29 commit 27fa5e7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions hw/scsi/esp.c
Expand Up @@ -248,6 +248,8 @@ static void esp_do_dma(ESPState *s)
len = s->dma_left;
if (s->do_cmd) {
trace_esp_do_dma(s->cmdlen, len);
assert (s->cmdlen <= sizeof(s->cmdbuf) &&
len <= sizeof(s->cmdbuf) - s->cmdlen);
s->dma_memory_read(s->dma_opaque, &s->cmdbuf[s->cmdlen], len);
return;
}
Expand Down Expand Up @@ -345,7 +347,7 @@ static void handle_ti(ESPState *s)
s->dma_counter = dmalen;

if (s->do_cmd)
minlen = (dmalen < 32) ? dmalen : 32;
minlen = (dmalen < ESP_CMDBUF_SZ) ? dmalen : ESP_CMDBUF_SZ;
else if (s->ti_size < 0)
minlen = (dmalen < -s->ti_size) ? dmalen : -s->ti_size;
else
Expand Down Expand Up @@ -451,7 +453,7 @@ void esp_reg_write(ESPState *s, uint32_t saddr, uint64_t val)
break;
case ESP_FIFO:
if (s->do_cmd) {
if (s->cmdlen < TI_BUFSZ) {
if (s->cmdlen < ESP_CMDBUF_SZ) {
s->cmdbuf[s->cmdlen++] = val & 0xff;
} else {
trace_esp_error_fifo_overrun();
Expand Down
3 changes: 2 additions & 1 deletion include/hw/scsi/esp.h
Expand Up @@ -14,6 +14,7 @@ void esp_init(hwaddr espaddr, int it_shift,

#define ESP_REGS 16
#define TI_BUFSZ 16
#define ESP_CMDBUF_SZ 32

typedef struct ESPState ESPState;

Expand All @@ -31,7 +32,7 @@ struct ESPState {
SCSIBus bus;
SCSIDevice *current_dev;
SCSIRequest *current_req;
uint8_t cmdbuf[TI_BUFSZ];
uint8_t cmdbuf[ESP_CMDBUF_SZ];
uint32_t cmdlen;
uint32_t do_cmd;

Expand Down

0 comments on commit 27fa5e7

Please sign in to comment.