Skip to contentSkip to conversation

libxl: fix unsafe subtraction in libxl_set_memory_target

PATCH Applied Stefano Stabellini 2 participants 2 messages Feb 1, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: fix unsafe subtraction in libxl_set_memory_target

The current libxl_set_memory_target function subtracts a negative amount from an uint32_t variable without checking if the operation wraps around.

This patch fixes this bug (that I previously believed to be an hypervisor issue):
http://bugzilla.xensource.com/bugzilla/show_bug.cgi?id=1729

tools/libxl/libxl.c +6 -3
diff -r a69965e61ae9 tools/libxl/libxl.c
@@ -2059,9 +2059,12 @@ retry_transaction:
         goto out;
     }
 
-    if (relative)
-        new_target_memkb = current_target_memkb + target_memkb;
-    else
+    if (relative) {
+        if (target_memkb < 0 && abs(target_memkb) > current_target_memkb)
+            new_target_memkb = 0;
+        else
+            new_target_memkb = current_target_memkb + target_memkb;
+    } else
         new_target_memkb = target_memkb;
     if (new_target_memkb > memorykb) {
         LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
Applied
#1 lore raw

Stefano Stabellini writes ("[Xen-devel] [PATCH] libxl: fix unsafe subtraction in libxl_set_memory_target"):

Quoted 7 lines

The current libxl_set_memory_target function subtracts a negative amount from an uint32_t variable without checking if the operation wraps around.

This patch fixes this bug (that I previously believed to be an hypervisor issue):
http://bugzilla.xensource.com/bugzilla/show_bug.cgi?id=1729

Applied, thanks.

Ian.