Skip to contentSkip to conversation

x86/vpci: validate data first in register_vpci_mmcfg_handler

PATCH In review Wei Liu 3 participants 3 messages Mar 27, 2018

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH 1/1 x86/vpci: validate data first in register_vpci_mmcfg_handler

Avoid the need to deallocate memory when the data is invalid. It has the benefit to not fragment memory in Xen.

---
Found by code inspection. There shouldn't be any practical difference in our current setup because the function is hardware domain only. But ISTM the plan is to make this available to DomU in the future so we'd better be careful about buggy / malicious guests.

Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
Cc Paul Durrant <[email protected]>
Cc Roger Pau Monné <[email protected]>
---
 xen/arch/x86/hvm/io.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
xen/arch/x86/hvm/io.c +5 -7
index 556810c126..9af5e3fee6 100644
@@ -511,18 +511,16 @@ int register_vpci_mmcfg_handler(struct domain *d, paddr_t addr,
                                 unsigned int start_bus, unsigned int end_bus,
                                 unsigned int seg)
 {
-    struct hvm_mmcfg *mmcfg, *new = xmalloc(struct hvm_mmcfg);
+    struct hvm_mmcfg *mmcfg, *new;
 
     ASSERT(is_hardware_domain(d));
 
-    if ( !new )
-        return -ENOMEM;
-
     if ( start_bus > end_bus )
-    {
-        xfree(new);
         return -EINVAL;
-    }
+
+    new = xmalloc(struct hvm_mmcfg);
+    if ( !new )
+        return -ENOMEM;
 
     new->addr = addr + (start_bus << 20);
     new->start_bus = start_bus;
Signature · 7 lines
2.11.0


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

Avoid the need to deallocate memory when the data is invalid. It has the benefit to not fragment memory in Xen.

Quoted 5 lines

---
Found by code inspection. There shouldn't be any practical difference in our current setup because the function is hardware domain only. But ISTM the plan is to make this available to DomU in the future so we'd better be careful about buggy / malicious guests.

This function must be called by the toolstack, guests won't be allowed to register MCFG regions themselves anyway, so there should be no guest path that leads here.

Thanks, Roger.

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

Acked-by
#2 lore raw
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 27.03.18 at 13:09, <[email protected]> wrote:
Quoted 4 lines · Wei Liu

Avoid the need to deallocate memory when the data is invalid. It has the benefit to not fragment memory in Xen.

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