vfio/igd: Fix potential overflow in igd_gtt_memory_size()
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
--- hw/vfio/igd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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; } }
Signature · 1 line
2.47.1
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")Signed-off-by Cédric Le Goater <[email protected]>--- hw/vfio/igd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/vfio/igd.c +0
-0
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; } }
Cédric Le Goater
AppliedQuoted 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")Signed-off-by Cédric Le Goater <[email protected]>
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@@ -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; } }