Skip to contentSkip to conversation

libxc: fix out of range shift in populate_acpi_pages

PATCH Superseded Wei Liu 2 participants 3 messages Sep 28, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH 1/1 libxc: fix out of range shift in populate_acpi_pages

"unsigned int" is only 4-byte long and "4" is treated as int. The shift would overflow. Use "unsigned long" (to match the type of idx) and "4UL" instead.

Caught by clang compilation test.

---
Cc: Ian Jackson <[email protected]>
Cc: Boris Ostrovsky <[email protected]>

---
 tools/libxc/xc_dom_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxc/xc_dom_core.c +1 -1
index 87b450c..b3feb42 100644
@@ -1048,7 +1048,7 @@ static int populate_acpi_pages(struct xc_dom_image *dom,
     xc_interface *xch = dom->xch;
     uint32_t domid = dom->guest_domid;
     unsigned long idx;
-    unsigned int first_high_idx = (4 << 30) >> PAGE_SHIFT; /* 4GB */
+    unsigned long first_high_idx = (4UL << 30) >> PAGE_SHIFT; /* 4GB */
 
     for ( ; num_pages; num_pages--, extents++ )
     {
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Wei Liu

"unsigned int" is only 4-byte long and "4" is treated as int. The shift would overflow. Use "unsigned long" (to match the type of idx) and "4UL" instead.

Caught by clang compilation test.

Quoted 12 lines

---
Cc: Ian Jackson <[email protected]>
Cc: Boris Ostrovsky <[email protected]>

---
 tools/libxc/xc_dom_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxc/xc_dom_core.c +0 -0
index 87b450c..b3feb42 100644

tools/libxc/xc_dom_core.c static int populate_acpi_pages(struct xc_dom_image *dom, · line 1054

Quoted 8 lines
tools/libxc/xc_dom_core.c +1 -1
@@ -1048,7 +1048,7 @@ static int populate_acpi_pages(struct xc_dom_image *dom,
     xc_interface *xch = dom->xch;
     uint32_t domid = dom->guest_domid;
     unsigned long idx;
-    unsigned int first_high_idx = (4 << 30) >> PAGE_SHIFT; /* 4GB */
+    unsigned long first_high_idx = (4UL << 30) >> PAGE_SHIFT; /* 4GB */
 
     for ( ; num_pages; num_pages--, extents++ )
     {

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#2 lore raw
Quoted 18 lines · Boris Ostrovsky
Quoted 7 lines · Wei Liu

"unsigned int" is only 4-byte long and "4" is treated as int. The shift would overflow. Use "unsigned long" (to match the type of idx) and "4UL" instead.

Caught by clang compilation test.

Quoted 7 lines

---
Cc: Ian Jackson <[email protected]>
Cc: Boris Ostrovsky <[email protected]>

---
 tools/libxc/xc_dom_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 11 lines

tools/libxc/xc_dom_core.c static int populate_acpi_pages(struct xc_dom_image *dom, · line 1052

Quoted 11 lines
tools/libxc/xc_dom_core.c +1 -1
index 87b450c..b3feb42 100644
@@ -1048,7 +1048,7 @@ static int populate_acpi_pages(struct xc_dom_image *dom,
     xc_interface *xch = dom->xch;
     uint32_t domid = dom->guest_domid;
     unsigned long idx;
-    unsigned int first_high_idx = (4 << 30) >> PAGE_SHIFT; /* 4GB */
+    unsigned long first_high_idx = (4UL << 30) >> PAGE_SHIFT; /* 4GB */
 

Actually, Ian pointed out on IRC unsigned long is 32 bit on i386, so this patch is not enough.

Will try again.

Wei.

Quoted 3 lines

tools/libxc/xc_dom_core.c static int populate_acpi_pages(struct xc_dom_image *dom, · line 1054

Quoted 2 lines
tools/libxc/xc_dom_core.c +0 -0
     for ( ; num_pages; num_pages--, extents++ )
     {

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel