summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2017-06-01 17:18:39 +0200
committerMichael Roth <mdroth@linux.vnet.ibm.com>2017-08-31 11:51:16 -0500
commit20fd62d374659269977426cacd9a655c022ff774 (patch)
treea2634bdf9f59e738749bc948877318d385e4776b /hw
parent7442018a001c8e626a46d19488f470c1fdb162cf (diff)
downloadqemu-20fd62d374659269977426cacd9a655c022ff774.tar.gz
megasas: do not read sense length more than once from frame
Avoid TOC-TOU bugs depending on how the compiler behaves. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> (cherry picked from commit 134550bf81a026e18cf58b81e2c2cceaf516f92e) Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/scsi/megasas.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
index 804122ab05..1888118e5f 100644
--- a/hw/scsi/megasas.c
+++ b/hw/scsi/megasas.c
@@ -309,9 +309,11 @@ static int megasas_build_sense(MegasasCmd *cmd, uint8_t *sense_ptr,
PCIDevice *pcid = PCI_DEVICE(cmd->state);
uint32_t pa_hi = 0, pa_lo;
hwaddr pa;
+ int frame_sense_len;
- if (sense_len > cmd->frame->header.sense_len) {
- sense_len = cmd->frame->header.sense_len;
+ frame_sense_len = cmd->frame->header.sense_len;
+ if (sense_len > frame_sense_len) {
+ sense_len = frame_sense_len;
}
if (sense_len) {
pa_lo = le32_to_cpu(cmd->frame->pass.sense_addr_lo);