Skip to contentSkip to conversation

x86/MTRR: fix range check in mtrr_add_page()

PATCH In review Jan Beulich 3 participants 3 messages Aug 13, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/MTRR: fix range check in mtrr_add_page()

Extracted from Yinghai Lu's Linux commit d5c78673 ("x86: Fix /proc/mtrr with base/size more than 44bits").

xen/arch/x86/cpu/mtrr/main.c +1 -1
@@ -340,7 +340,7 @@ int mtrr_add_page(unsigned long base, un
 		return -EINVAL;
 	}
 
-	if (base & size_or_mask || size & size_or_mask) {
+	if ((base | (base + size - 1)) >> (paddr_bits - PAGE_SHIFT)) {
 		printk(KERN_WARNING "mtrr: base or size exceeds the MTRR width\n");
 		return -EINVAL;
 	}

x86/MTRR: fix range check in mtrr_add_page()

Extracted from Yinghai Lu's Linux commit d5c78673 ("x86: Fix /proc/mtrr with base/size more than 44bits").

xen/arch/x86/cpu/mtrr/main.c +1 -1
@@ -340,7 +340,7 @@ int mtrr_add_page(unsigned long base, un
 		return -EINVAL;
 	}
 
-	if (base & size_or_mask || size & size_or_mask) {
+	if ((base | (base + size - 1)) >> (paddr_bits - PAGE_SHIFT)) {
 		printk(KERN_WARNING "mtrr: base or size exceeds the MTRR width\n");
 		return -EINVAL;
 	}

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

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

Extracted from Yinghai Lu's Linux commit d5c78673 ("x86: Fix /proc/mtrr with base/size more than 44bits").

Quoted 17 lines
xen/arch/x86/cpu/mtrr/main.c +1 -1
@@ -340,7 +340,7 @@ int mtrr_add_page(unsigned long base, un
 		return -EINVAL;
 	}
 
-	if (base & size_or_mask || size & size_or_mask) {
+	if ((base | (base + size - 1)) >> (paddr_bits - PAGE_SHIFT)) {
 		printk(KERN_WARNING "mtrr: base or size exceeds the MTRR width\n");
 		return -EINVAL;
 	}
Quoted 4 lines

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

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

Acked-by on v1 1/1
#2 lore raw
In reply to Jan Beulich
Quoted 4 lines · Jan Beulich

Extracted from Yinghai Lu's Linux commit d5c78673 ("x86: Fix /proc/mtrr with base/size more than 44bits").

Quoted 14 lines
xen/arch/x86/cpu/mtrr/main.c +1 -1
@@ -340,7 +340,7 @@ int mtrr_add_page(unsigned long base, un
 return -EINVAL;
 }
 
- if (base & size_or_mask || size & size_or_mask) {
+ if ((base | (base + size - 1)) >> (paddr_bits - PAGE_SHIFT)) {
 printk(KERN_WARNING "mtrr: base or size exceeds the MTRR width\n");
 return -EINVAL;
 }