Skip to contentSkip to conversation

sysctl: use xmalloc_array() for XEN_SYSCTL_page_offline_op

PATCH In review Jan Beulich 3 participants 4 messages Feb 18, 2020 – Feb 19, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sysctl: use xmalloc_array() for XEN_SYSCTL_page_offline_op

This is more robust than the raw xmalloc_bytes().

Also add a sanity check on the input page range, to avoid returning the less applicable -ENOMEM in such cases (and trying the allocation in the first place).

---
v2: Expand a bit the description of the sanity check addition.

xen/common/sysctl.c +7 -3
@@ -187,13 +187,17 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xe
         uint32_t *status, *ptr;
         mfn_t mfn;
 
+        ret = -EINVAL;
+        if ( op->u.page_offline.end < op->u.page_offline.start )
+            break;
+
         ret = xsm_page_offline(XSM_HOOK, op->u.page_offline.cmd);
         if ( ret )
             break;
 
-        ptr = status = xmalloc_bytes( sizeof(uint32_t) *
-                                (op->u.page_offline.end -
-                                  op->u.page_offline.start + 1));
+        ptr = status = xmalloc_array(uint32_t,
+                                     (op->u.page_offline.end -
+                                      op->u.page_offline.start + 1));
         if ( !status )
         {
             dprintk(XENLOG_WARNING, "Out of memory for page offline op\n");

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

Acked-by on v2 1/1
#1 lore raw
Quoted 7 lines · Jan Beulich

This is more robust than the raw xmalloc_bytes().

Also add a sanity check on the input page range, to avoid returning the less applicable -ENOMEM in such cases (and trying the allocation in the first place).

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

#2 lore raw

Julien,

Quoted 10 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich

This is more robust than the raw xmalloc_bytes().

Also add a sanity check on the input page range, to avoid returning the less applicable -ENOMEM in such cases (and trying the allocation in the first place).

I notice you've committed this, but somehow you've lost Andrew's ack. I don't think it was intended by the recent check-in policy change for commits to go in without suitable acks (iirc I did notice a few others recently as well, albeit not ones committed by you).

Jan

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

#3 lore raw
Quoted 12 lines · Jan Beulich

Julien,

Quoted 9 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich

This is more robust than the raw xmalloc_bytes().

Also add a sanity check on the input page range, to avoid returning the less applicable -ENOMEM in such cases (and trying the allocation in the first place).

Quoted 7 lines
Quoted 1 line

I notice you've committed this, but somehow you've lost Andrew's ack. I don't think it was intended by the recent check-in policy change for commits to go in without suitable acks (iirc I did notice a few others recently as well, albeit not ones committed by you).

In this case, this was a lack of attention while committing the patch.

Mistakes can happen and this has nothing to do with a check-in policy.
You will never be able to fully prevent any mistakes until you remove the human from the equation. Please provide scripts that fully automate the committers job if you are concern about this.

Cheers,

Signature · 6 lines
Julien Grall

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