Skip to contentSkip to conversation

libxc: fix unmap of ACPI guest memory region

PATCH Applied Roger Pau Monne 4 participants 5 messages Nov 8, 2016 – Nov 11, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxc: fix unmap of ACPI guest memory region

Commit fac7f7 changed the value of ptr so that it points to the right memory area, taking the page offset into account, but failed to remove this when doing the unmap, which caused the region to not be unmapped. Fix this by not modifying ptr and instead adding the page offset directly in the memcpy call.

---
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: Ian Jackson <[email protected]>

---
 tools/libxc/xc_dom_core.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
tools/libxc/xc_dom_core.c +3 -4
index ad819dd..36cd3c8 100644
@@ -1119,10 +1119,9 @@ static int xc_dom_load_acpi(struct xc_dom_image *dom)
             goto err;
         }
 
-        ptr = (uint8_t *)ptr +
-              (dom->acpi_modules[i].guest_addr_out & ~XC_PAGE_MASK);
-
-        memcpy(ptr, dom->acpi_modules[i].data, dom->acpi_modules[i].length);
+        memcpy((uint8_t *)ptr +
+               (dom->acpi_modules[i].guest_addr_out & ~XC_PAGE_MASK),
+               dom->acpi_modules[i].data, dom->acpi_modules[i].length);
         munmap(ptr, XC_PAGE_SIZE * num_pages);
 
         free(extents);
Signature · 7 lines
2.7.4 (Apple Git-66)


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

Commit fac7f7 changed the value of ptr so that it points to the right memory area, taking the page offset into account, but failed to remove this when doing the unmap, which caused the region to not be unmapped. Fix this by not modifying ptr and instead adding the page offset directly in the memcpy call.

---
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: Ian Jackson <[email protected]>

---
 tools/libxc/xc_dom_core.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
tools/libxc/xc_dom_core.c +0 -0
index ad819dd..36cd3c8 100644
@@ -1119,10 +1119,9 @@ static int xc_dom_load_acpi(struct xc_dom_image *dom)
             goto err;
         }
 

tools/libxc/xc_dom_core.c static int xc_dom_load_acpi(struct xc_dom_image *dom) · line 1127

Quoted 10 lines
tools/libxc/xc_dom_core.c +3 -4
-        ptr = (uint8_t *)ptr +
-              (dom->acpi_modules[i].guest_addr_out & ~XC_PAGE_MASK);
-
-        memcpy(ptr, dom->acpi_modules[i].data, dom->acpi_modules[i].length);
+        memcpy((uint8_t *)ptr +
+               (dom->acpi_modules[i].guest_addr_out & ~XC_PAGE_MASK),
+               dom->acpi_modules[i].data, dom->acpi_modules[i].length);
         munmap(ptr, XC_PAGE_SIZE * num_pages);
 
         free(extents);

(Although I don't think this would cause memory not to be unmapped: per Linux man page "All pages containing a part of the indicated range are unmapped ..." and ptr is offset from its original value by a fraction of a page.)

-boris

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

#2 lore raw
Quoted 43 lines · Boris Ostrovsky
Quoted 26 lines · Roger Pau Monne

Commit fac7f7 changed the value of ptr so that it points to the right memory area, taking the page offset into account, but failed to remove this when doing the unmap, which caused the region to not be unmapped. Fix this by not modifying ptr and instead adding the page offset directly in the memcpy call.

---
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: Ian Jackson <[email protected]>

---
 tools/libxc/xc_dom_core.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
tools/libxc/xc_dom_core.c +0 -0
index ad819dd..36cd3c8 100644
@@ -1119,10 +1119,9 @@ static int xc_dom_load_acpi(struct xc_dom_image *dom)
             goto err;
         }
 

tools/libxc/xc_dom_core.c static int xc_dom_load_acpi(struct xc_dom_image *dom) · line 1127

Quoted 10 lines
tools/libxc/xc_dom_core.c +3 -4
-        ptr = (uint8_t *)ptr +
-              (dom->acpi_modules[i].guest_addr_out & ~XC_PAGE_MASK);
-
-        memcpy(ptr, dom->acpi_modules[i].data, dom->acpi_modules[i].length);
+        memcpy((uint8_t *)ptr +
+               (dom->acpi_modules[i].guest_addr_out & ~XC_PAGE_MASK),
+               dom->acpi_modules[i].data, dom->acpi_modules[i].length);
         munmap(ptr, XC_PAGE_SIZE * num_pages);
 
         free(extents);
Quoted 4 lines

(Although I don't think this would cause memory not to be unmapped: per Linux man page "All pages containing a part of the indicated range are unmapped ..." and ptr is offset from its original value by a fraction of a page.)

Linux man page states:

"The implementation shall require that addr be a multiple of the page size {PAGESIZE}."

And on FreeBSD:

"The munmap() system call will fail if: The addr argument was not page aligned, [...]"

Roger.

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

Reviewed-by on v1 1/1
#3 lore raw
In reply to Roger Pau Monne
Quoted 5 lines · Roger Pau Monne

Commit fac7f7 changed the value of ptr so that it points to the right memory area, taking the page offset into account, but failed to remove this when doing the unmap, which caused the region to not be unmapped. Fix this by not modifying ptr and instead adding the page offset directly in the memcpy call.

Coverity-ID: 1394285

(Coverity scan has now run and found this issue, so we have a public ID to use).

Quoted 2 lines

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

Applied
#4 lore raw
In reply to Roger Pau Monne
Quoted 8 lines · Roger Pau Monne

Commit fac7f7 changed the value of ptr so that it points to the right memory area, taking the page offset into account, but failed to remove this when doing the unmap, which caused the region to not be unmapped. Fix this by not modifying ptr and instead adding the page offset directly in the memcpy call.

Applied.

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