Blame 0007-megasas-do-not-read-iovec-count-more-than-once-from-.patch

335584
From: Paolo Bonzini <pbonzini@redhat.com>
335584
Date: Thu, 1 Jun 2017 17:18:57 +0200
335584
Subject: [PATCH] megasas: do not read iovec count 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 24c0c77af515acbf0f9705e8096f33ef24d37430)
335584
---
335584
 hw/scsi/megasas.c | 9 +++++----
335584
 1 file changed, 5 insertions(+), 4 deletions(-)
335584
335584
diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
335584
index 1888118e5f..c353118882 100644
335584
--- a/hw/scsi/megasas.c
335584
+++ b/hw/scsi/megasas.c
335584
@@ -675,15 +675,16 @@ out:
335584
 static int megasas_map_dcmd(MegasasState *s, MegasasCmd *cmd)
335584
 {
335584
     dma_addr_t iov_pa, iov_size;
335584
+    int iov_count;
335584
 
335584
     cmd->flags = le16_to_cpu(cmd->frame->header.flags);
335584
-    if (!cmd->frame->header.sge_count) {
335584
+    iov_count = cmd->frame->header.sge_count;
335584
+    if (!iov_count) {
335584
         trace_megasas_dcmd_zero_sge(cmd->index);
335584
         cmd->iov_size = 0;
335584
         return 0;
335584
-    } else if (cmd->frame->header.sge_count > 1) {
335584
-        trace_megasas_dcmd_invalid_sge(cmd->index,
335584
-                                       cmd->frame->header.sge_count);
335584
+    } else if (iov_count > 1) {
335584
+        trace_megasas_dcmd_invalid_sge(cmd->index, iov_count);
335584
         cmd->iov_size = 0;
335584
         return -EINVAL;
335584
     }