Skip to contentSkip to conversation

vfio/igd: Fix potential overflow in igd_gtt_memory_size()

PATCH Applied Cédric Le Goater 2 participants 3 messages Jan 7, 2025 – Jan 16, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfio/igd: Fix potential overflow in igd_gtt_memory_size()

The risk is mainly theoretical since the applied bit mask will keep the 'ggms' shift value below 3. Nevertheless, let's use a 64 bit integer type and resolve the coverity issue.

Resolves: Coverity CID 1585908

Fixes 1e1eac5f3dcd ("vfio/igd: canonicalize memory size calculations")
---
 hw/vfio/igd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/igd.c +1 -1
index 0740a5dd8cc9346a92c4613194faa8dea42e1d98..b5303ea565d6a344d0a43273f288bbb4a7f48327 100644
@@ -133,7 +133,7 @@ static uint64_t igd_gtt_memory_size(int gen, uint16_t gmch)
     } else {
         ggms = (gmch >> IGD_GMCH_GEN8_GGMS_SHIFT) & IGD_GMCH_GEN8_GGMS_MASK;
         if (ggms != 0) {
-            ggms = 1 << ggms;
+            ggms = 1ULL << ggms;
         }
     }
 
Signature · 1 line
2.47.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · On Tue, 7 Jan 2025 14:06:04 +0100 Cédric Le Goater <[email protected]> wrote:

The risk is mainly theoretical since the applied bit mask will keep the 'ggms' shift value below 3. Nevertheless, let's use a 64 bit integer type and resolve the coverity issue.

Resolves: Coverity CID 1585908

Fixes 1e1eac5f3dcd ("vfio/igd: canonicalize memory size calculations")
---
 hw/vfio/igd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/igd.c +0 -0
index 0740a5dd8cc9346a92c4613194faa8dea42e1d98..b5303ea565d6a344d0a43273f288bbb4a7f48327 100644

hw/vfio/igd.c static uint64_t igd_gtt_memory_size(int gen, uint16_t gmch) · line 139

Quoted 8 lines
hw/vfio/igd.c +1 -1
@@ -133,7 +133,7 @@ static uint64_t igd_gtt_memory_size(int gen, uint16_t gmch)
     } else {
         ggms = (gmch >> IGD_GMCH_GEN8_GGMS_SHIFT) & IGD_GMCH_GEN8_GGMS_MASK;
         if (ggms != 0) {
-            ggms = 1 << ggms;
+            ggms = 1ULL << ggms;
         }
     }
 
author Applied
#2 lore raw
In reply to Cédric Le Goater
Quoted 7 lines · Cédric Le Goater

The risk is mainly theoretical since the applied bit mask will keep the 'ggms' shift value below 3. Nevertheless, let's use a 64 bit integer type and resolve the coverity issue.

Resolves: Coverity CID 1585908

Fixes 1e1eac5f3dcd ("vfio/igd: canonicalize memory size calculations")

Applied to vfio-next.

Thanks,

C.

Quoted 17 lines
---
  hw/vfio/igd.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/igd.c +1 -1
index 0740a5dd8cc9346a92c4613194faa8dea42e1d98..b5303ea565d6a344d0a43273f288bbb4a7f48327 100644
@@ -133,7 +133,7 @@ static uint64_t igd_gtt_memory_size(int gen, uint16_t gmch)
      } else {
          ggms = (gmch >> IGD_GMCH_GEN8_GGMS_SHIFT) & IGD_GMCH_GEN8_GGMS_MASK;
          if (ggms != 0) {
-            ggms = 1 << ggms;
+            ggms = 1ULL << ggms;
          }
      }