Skip to contentSkip to conversation

i386: Fix overflow in e820_all_mapped

PATCH In review Andi Kleen 4 participants 6 messages Apr 28, 2006

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 3/4 i386: Fix overflow in e820_all_mapped

The 32bit version of e820_all_mapped() needs to use u64 to avoid overflows on PAE systems. Pointed out by Jan Beulich

---
 arch/i386/kernel/setup.c |    2 +-
 include/asm-i386/e820.h  |    3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)
arch/i386/kernel/setup.c +1 -1
Index: linux/arch/i386/kernel/setup.c
===================================================================
@@ -970,7 +970,7 @@ efi_memory_present_wrapper(unsigned long
   * not-overlapping, which is the case
   */
 int __init
-e820_all_mapped(unsigned long start, unsigned long end, unsigned type)
+e820_all_mapped(u64 start, u64 end, unsigned type)
 {
 	int i;
 	for (i = 0; i < e820.nr_map; i++) {
include/asm-i386/e820.h +1 -2
Index: linux/include/asm-i386/e820.h
===================================================================
@@ -36,8 +36,7 @@ struct e820map {
 
 extern struct e820map e820;
 
-extern int e820_all_mapped(unsigned long start, unsigned long end,
-			   unsigned type);
+extern int e820_all_mapped(u64 start, u64 end, unsigned type);
 
 #endif/*!__ASSEMBLY__*/
 
#1 lore raw
Quoted 3 lines · Andi Kleen

The 32bit version of e820_all_mapped() needs to use u64 to avoid overflows on PAE systems. Pointed out by Jan Beulich

I don't think that's true.

It can't be called with 64-bit arguments anyway. If the base address doesn't fit in 32-bit, we'd be screwed in other places, afaik.

Linus

author
#2 lore raw
Quoted 10 lines · Linus Torvalds
Quoted 3 lines · Andi Kleen

The 32bit version of e820_all_mapped() needs to use u64 to avoid overflows on PAE systems. Pointed out by Jan Beulich

I don't think that's true.

It can't be called with 64-bit arguments anyway. If the base address doesn't fit in 32-bit, we'd be screwed in other places, afaik.

To quote Jan's original description (should have put that in) I think it's needed.

-Andi

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

It would seem to me that using 'unsigned long' for start and end is inappropriate on 32bits; at least start should

be

Quoted 1 line
Quoted 1 line

'unsigned long long' as it gets updated from ei->addr + ei->size, which may (truncated to 32 bits) happen to be

zero.

Quoted 2 lines

the current user has it 32 bit for sure; once another user appears we certainly can fix this...

The effect is not on the current user's parameter passing, but in the result the function may produce. If, say, for the PCI mmconfig and BIOS space, there is a (reserved) entry starting at E0000000 and being 20000000 in size, then as far as I can tell the function will return zero (rather than one).

<<<

#3 lore raw
Quoted 8 lines · Andi Kleen

Quoting jbeulich:

The effect is not on the current user's parameter passing, but in the result the function may produce. If, say, for the PCI mmconfig and BIOS space, there is a (reserved) entry starting at E0000000 and being 20000000 in size, then as far as I can tell the function will return zero (rather than one).

Well, but that has nothing to do with the _calling_ convention.

That looks to be a totally internal bug to within e820_all_mapped().

I agree that the calling convention change would avoid the overflow internally too, I just don't much like the explanation (and not necessarily that it affects the caller, who doesn't much care).

Linus

#4 lore raw
In reply to Linus Torvalds
Quoted 5 lines
Quoted 1 line
Quoted 1 line

Linus Torvalds <[email protected]> 28.04.06 07:39 >>>

Quoted 1 line · Andi Kleen
Quoted 7 lines
Quoted 2 lines

The 32bit version of e820_all_mapped() needs to use u64 to avoid overflows on PAE systems. Pointed out by Jan Beulich

I don't think that's true.

It can't be called with 64-bit arguments anyway. If the base address doesn't fit in 32-bit, we'd be screwed in other places, afaik.

The arguments don't necessarily need to be u64, but (at least some of) the calculations inside the function do. Otherwise, a region starting below 4G and extending to or beyond 4G would not be considered correctly.

Jan

#5 lore raw
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line

Linus Torvalds <[email protected]> 28.04.06 07:39 >>>

Quoted 3 lines · Andi Kleen

The 32bit version of e820_all_mapped() needs to use u64 to avoid overflows on PAE systems. Pointed out by Jan Beulich

I don't think that's true.

Quoted 7 lines
Quoted 2 lines

It can't be called with 64-bit arguments anyway. If the base address doesn't fit in 32-bit, we'd be screwed in other places, afaik.

The arguments don't necessarily need to be u64, but (at least some of) the calculations inside the function do. Otherwise, a region starting below 4G and extending to or beyond 4G would not be considered correctly.

since this is use-once __init code I rather keep it simple and safe (eg use u64) than do complex tricks to make it safe in another way.. and the 4G thing is a real potential problem that's easily fixed with the u64 thing.