Skip to contentSkip to conversation

x86/HVM: fix PM timer I/O port range version check

PATCH In review Jan Beulich 2 participants 3 messages Jan 28, 2020 – Jan 30, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/HVM: fix PM timer I/O port range version check

XOR-ing two arbitrary non-equal values may produce 1 even if both values are different from both 0 and 1 (2 and 3 would fit, for example). Use OR instead, which together with the earlier bailing upon finding "version == old_version" achieves the intended effect.

Fixes f0ad21c499f7 ("x86 hvm: Introduce pmtimer_change_ioport and HVM_PARAM_ACPI_IOPORTS_LOCATION")
xen/arch/x86/hvm/pmtimer.c +1 -1
@@ -326,7 +326,7 @@ int pmtimer_change_ioport(struct domain
         return 0;
 
     /* Only allow changes between versions 0 and 1. */
-    if ( (version ^ old_version) != 1 )
+    if ( (version | old_version) != 1 )
         return -EINVAL;
 
     if ( version == 1 )

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

Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jan Beulich

XOR-ing two arbitrary non-equal values may produce 1 even if both values are different from both 0 and 1 (2 and 3 would fit, for example). Use OR instead, which together with the earlier bailing upon finding "version == old_version" achieves the intended effect.

Fixes f0ad21c499f7 ("x86 hvm: Introduce pmtimer_change_ioport and HVM_PARAM_ACPI_IOPORTS_LOCATION")

Thanks, Roger.

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

#2 lore raw
Quoted 10 lines · Roger Pau Monné
Quoted 7 lines · Jan Beulich

XOR-ing two arbitrary non-equal values may produce 1 even if both values are different from both 0 and 1 (2 and 3 would fit, for example). Use OR instead, which together with the earlier bailing upon finding "version == old_version" achieves the intended effect.

Fixes f0ad21c499f7 ("x86 hvm: Introduce pmtimer_change_ioport and HVM_PARAM_ACPI_IOPORTS_LOCATION")

Thanks, but I withdraw this patch. The code is correct as is, just a little less obviously correct than with the use of |. As long as there's no way for the value stored in Xen to be larger than 1, there's also no way for a larger value to pass the check in question.

Instead I notice the upper 32 bits of the value are silently ignored. I'll submit a new patch addressing that instead.

Jan

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