* [Qemu-devel] [PATCH v4] scsi: esp: check length before dma read
@ 2016-06-15 17:36 P J P
2016-06-17 4:19 ` Amit Shah
0 siblings, 1 reply; 5+ messages in thread
From: P J P @ 2016-06-15 17:36 UTC (permalink / raw)
To: Qemu Developers; +Cc: Paolo Bonzini, Li Qiang, Laszlo Ersek, Prasad J Pandit
From: Prasad J Pandit <pjp@fedoraproject.org>
While doing DMA read into ESP command buffer 's->cmdbuf', it could
write past the 's->cmdbuf' area, if it was partially filled;
ie. 's->cmdlen' wasn't set at the start of the buffer.
Check 'len' to avoid OOB access. Also increase the command buffer
size to 32, which is maximum when 's->do_cmd' is set.
Reported-by: Li Qiang <liqiang6-s@360.cn>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
hw/scsi/esp.c | 6 ++++--
include/hw/scsi/esp.h | 3 ++-
2 files changed, 6 insertions(+), 3 deletions(-)
Update as per
-> https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg04269.html
diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
index 4b94bbc..cc74ba8 100644
--- a/hw/scsi/esp.c
+++ b/hw/scsi/esp.c
@@ -249,6 +249,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);
s->ti_size = 0;
s->cmdlen = 0;
@@ -348,7 +350,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
@@ -452,7 +454,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();
diff --git a/include/hw/scsi/esp.h b/include/hw/scsi/esp.h
index 6c79527..d2c4886 100644
--- a/include/hw/scsi/esp.h
+++ b/include/hw/scsi/esp.h
@@ -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;
@@ -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;
--
2.5.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v4] scsi: esp: check length before dma read
2016-06-15 17:36 [Qemu-devel] [PATCH v4] scsi: esp: check length before dma read P J P
@ 2016-06-17 4:19 ` Amit Shah
2016-06-17 8:16 ` P J P
2016-06-17 8:21 ` Paolo Bonzini
0 siblings, 2 replies; 5+ messages in thread
From: Amit Shah @ 2016-06-17 4:19 UTC (permalink / raw)
To: P J P
Cc: Qemu Developers, Paolo Bonzini, Li Qiang, Prasad J Pandit, Laszlo Ersek
Hi,
On (Wed) 15 Jun 2016 [23:06:19], P J P wrote:
> From: Prasad J Pandit <pjp@fedoraproject.org>
>
> While doing DMA read into ESP command buffer 's->cmdbuf', it could
> write past the 's->cmdbuf' area, if it was partially filled;
> ie. 's->cmdlen' wasn't set at the start of the buffer.
> Check 'len' to avoid OOB access. Also increase the command buffer
> size to 32, which is maximum when 's->do_cmd' is set.
>
> Reported-by: Li Qiang <liqiang6-s@360.cn>
> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
[...]
> diff --git a/include/hw/scsi/esp.h b/include/hw/scsi/esp.h
> index 6c79527..d2c4886 100644
> --- a/include/hw/scsi/esp.h
> +++ b/include/hw/scsi/esp.h
> @@ -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;
>
> @@ -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];
This was flagged as an incompatibility in the vmstate by a nightly run
of the vmstate checker:
Section "esp" Description "esp" Field "cmdbuf" size mismatch: 16 , 32
Section "dc390" Description "esp" Field "cmdbuf" size mismatch: 16 , 32
Section "am53c974" Description "esp" Field "cmdbuf" size mismatch: 16 , 32
Amit
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v4] scsi: esp: check length before dma read
2016-06-17 4:19 ` Amit Shah
@ 2016-06-17 8:16 ` P J P
2016-06-17 8:26 ` Paolo Bonzini
2016-06-17 8:21 ` Paolo Bonzini
1 sibling, 1 reply; 5+ messages in thread
From: P J P @ 2016-06-17 8:16 UTC (permalink / raw)
To: Amit Shah; +Cc: Qemu Developers, Paolo Bonzini, Li Qiang, Laszlo Ersek
+-- On Fri, 17 Jun 2016, Amit Shah wrote --+
| This was flagged as an incompatibility in the vmstate by a nightly run
| of the vmstate checker:
|
| Section "esp" Description "esp" Field "cmdbuf" size mismatch: 16 , 32
| Section "dc390" Description "esp" Field "cmdbuf" size mismatch: 16 , 32
| Section "am53c974" Description "esp" Field "cmdbuf" size mismatch: 16 , 32
Probably vmstate file needs to be regenerated?
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v4] scsi: esp: check length before dma read
2016-06-17 4:19 ` Amit Shah
2016-06-17 8:16 ` P J P
@ 2016-06-17 8:21 ` Paolo Bonzini
1 sibling, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2016-06-17 8:21 UTC (permalink / raw)
To: Amit Shah, P J P; +Cc: Li Qiang, Qemu Developers, Laszlo Ersek, Prasad J Pandit
On 17/06/2016 06:19, Amit Shah wrote:
> Hi,
>
> On (Wed) 15 Jun 2016 [23:06:19], P J P wrote:
>> From: Prasad J Pandit <pjp@fedoraproject.org>
>>
>> While doing DMA read into ESP command buffer 's->cmdbuf', it could
>> write past the 's->cmdbuf' area, if it was partially filled;
>> ie. 's->cmdlen' wasn't set at the start of the buffer.
>> Check 'len' to avoid OOB access. Also increase the command buffer
>> size to 32, which is maximum when 's->do_cmd' is set.
>>
>> Reported-by: Li Qiang <liqiang6-s@360.cn>
>> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
>
> [...]
>
>> diff --git a/include/hw/scsi/esp.h b/include/hw/scsi/esp.h
>> index 6c79527..d2c4886 100644
>> --- a/include/hw/scsi/esp.h
>> +++ b/include/hw/scsi/esp.h
>> @@ -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;
>>
>> @@ -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];
>
> This was flagged as an incompatibility in the vmstate by a nightly run
> of the vmstate checker:
>
> Section "esp" Description "esp" Field "cmdbuf" size mismatch: 16 , 32
> Section "dc390" Description "esp" Field "cmdbuf" size mismatch: 16 , 32
> Section "am53c974" Description "esp" Field "cmdbuf" size mismatch: 16 , 32
Oh, good catch. But from reading the spec the implementation was
completely busted. Let's just drop handle_satn_stop, cmdbuf, cmdlen and
do_cmd.
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v4] scsi: esp: check length before dma read
2016-06-17 8:16 ` P J P
@ 2016-06-17 8:26 ` Paolo Bonzini
0 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2016-06-17 8:26 UTC (permalink / raw)
To: P J P, Amit Shah; +Cc: Li Qiang, Qemu Developers, Laszlo Ersek
On 17/06/2016 10:16, P J P wrote:
> +-- On Fri, 17 Jun 2016, Amit Shah wrote --+
> | This was flagged as an incompatibility in the vmstate by a nightly run
> | of the vmstate checker:
> |
> | Section "esp" Description "esp" Field "cmdbuf" size mismatch: 16 , 32
> | Section "dc390" Description "esp" Field "cmdbuf" size mismatch: 16 , 32
> | Section "am53c974" Description "esp" Field "cmdbuf" size mismatch: 16 , 32
>
> Probably vmstate file needs to be regenerated?
No, that's not what that means. It means that your patch broke
migration compatibility. I've posted a patch to just remove the code
(which also has the effect of reverting your patch and mine).
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-06-17 8:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-15 17:36 [Qemu-devel] [PATCH v4] scsi: esp: check length before dma read P J P
2016-06-17 4:19 ` Amit Shah
2016-06-17 8:16 ` P J P
2016-06-17 8:26 ` Paolo Bonzini
2016-06-17 8:21 ` Paolo Bonzini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.