peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0006-megasas-do-not-read-sense-length-more-than-once-from.patch

335584
From: Paolo Bonzini <pbonzini@redhat.com>
335584
Date: Thu, 1 Jun 2017 17:18:39 +0200
335584
Subject: [PATCH] megasas: do not read sense length more than once from frame
335584
335584
Avoid TOC-TOU bugs depending on how the compiler behaves.
335584
335584
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
335584
(cherry picked from commit 134550bf81a026e18cf58b81e2c2cceaf516f92e)
335584
---
335584
 hw/scsi/megasas.c | 6 ++++--
335584
 1 file changed, 4 insertions(+), 2 deletions(-)
335584
335584
diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
335584
index 804122ab05..1888118e5f 100644
335584
--- a/hw/scsi/megasas.c
335584
+++ b/hw/scsi/megasas.c
335584
@@ -309,9 +309,11 @@ static int megasas_build_sense(MegasasCmd *cmd, uint8_t *sense_ptr,
335584
     PCIDevice *pcid = PCI_DEVICE(cmd->state);
335584
     uint32_t pa_hi = 0, pa_lo;
335584
     hwaddr pa;
335584
+    int frame_sense_len;
335584
 
335584
-    if (sense_len > cmd->frame->header.sense_len) {
335584
-        sense_len = cmd->frame->header.sense_len;
335584
+    frame_sense_len = cmd->frame->header.sense_len;
335584
+    if (sense_len > frame_sense_len) {
335584
+        sense_len = frame_sense_len;
335584
     }
335584
     if (sense_len) {
335584
         pa_lo = le32_to_cpu(cmd->frame->pass.sense_addr_lo);