yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-hw-arm-smmuv3-Fix-potential-integer-overflow-CID-143.patch

c687bc
From 69d71311d3d70282dec3d1f19f9e4b90c7b7c6b9 Mon Sep 17 00:00:00 2001
c687bc
From: eperezma <eperezma@redhat.com>
c687bc
Date: Tue, 12 Jan 2021 14:36:33 -0500
c687bc
Subject: [PATCH 09/17] hw/arm/smmuv3: Fix potential integer overflow (CID
c687bc
 1432363)
c687bc
MIME-Version: 1.0
c687bc
Content-Type: text/plain; charset=UTF-8
c687bc
Content-Transfer-Encoding: 8bit
c687bc
c687bc
RH-Author: eperezma <eperezma@redhat.com>
c687bc
Message-id: <20210112143638.374060-9-eperezma@redhat.com>
c687bc
Patchwork-id: 100601
c687bc
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH v2 08/13] hw/arm/smmuv3: Fix potential integer overflow (CID 1432363)
c687bc
Bugzilla: 1843852
c687bc
RH-Acked-by: Xiao Wang <jasowang@redhat.com>
c687bc
RH-Acked-by: Peter Xu <peterx@redhat.com>
c687bc
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
c687bc
c687bc
From: Philippe Mathieu-Daudé <philmd@redhat.com>
c687bc
c687bc
Use the BIT_ULL() macro to ensure we use 64-bit arithmetic.
c687bc
This fixes the following Coverity issue (OVERFLOW_BEFORE_WIDEN):
c687bc
c687bc
  CID 1432363 (#1 of 1): Unintentional integer overflow:
c687bc
c687bc
  overflow_before_widen:
c687bc
    Potentially overflowing expression 1 << scale with type int
c687bc
    (32 bits, signed) is evaluated using 32-bit arithmetic, and
c687bc
    then used in a context that expects an expression of type
c687bc
    hwaddr (64 bits, unsigned).
c687bc
c687bc
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
c687bc
Acked-by: Eric Auger <eric.auger@redhat.com>
c687bc
Message-id: 20201030144617.1535064-1-philmd@redhat.com
c687bc
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
c687bc
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
c687bc
(cherry picked from commit 744a790ec01a30033309e6a2155df4d61061e184)
c687bc
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
c687bc
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
c687bc
---
c687bc
 hw/arm/smmuv3.c | 3 ++-
c687bc
 1 file changed, 2 insertions(+), 1 deletion(-)
c687bc
c687bc
diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
c687bc
index f4d5d9d8222..a418fab2aa6 100644
c687bc
--- a/hw/arm/smmuv3.c
c687bc
+++ b/hw/arm/smmuv3.c
c687bc
@@ -17,6 +17,7 @@
c687bc
  */
c687bc
 
c687bc
 #include "qemu/osdep.h"
c687bc
+#include "qemu/bitops.h"
c687bc
 #include "hw/irq.h"
c687bc
 #include "hw/sysbus.h"
c687bc
 #include "migration/vmstate.h"
c687bc
@@ -847,7 +848,7 @@ static void smmuv3_s1_range_inval(SMMUState *s, Cmd *cmd)
c687bc
         scale = CMD_SCALE(cmd);
c687bc
         num = CMD_NUM(cmd);
c687bc
         ttl = CMD_TTL(cmd);
c687bc
-        num_pages = (num + 1) * (1 << (scale));
c687bc
+        num_pages = (num + 1) * BIT_ULL(scale);
c687bc
     }
c687bc
 
c687bc
     if (type == SMMU_CMD_TLBI_NH_VA) {
c687bc
-- 
c687bc
2.27.0
c687bc