Xen Security Advisory 27 (CVE-2012-5511) - several HVM operations do not validate the range of their inputs
A message that is not in the archive (sent off-list or not yet received): [email protected]
All,
This advisory required two different CVE IDs - not one - because the stack-based buffer overflow was fixed in a different version than the other issues. CVE assigns different IDs when bugs are not present in the same exact set of versions.
CVE-2012-5511 - use this, but only for the stack-based buffer overflow that was fixed in 4.2.
CVE-2012-6333 - new ID for the other "large input" validation issues that lead to the physical CPU hang, which were NOT fixed in 4.2.
- Steve
On Mon, Dec 03, 2012 at 05:51:44PM +0000, Xen.org security team wrote:
[...]
Quoted 10 lines
ISSUE DESCRIPTION
=================Several HVM control operations do not check the size of their inputs and can tie up a physical CPU for extended periods of time.
In addition dirty video RAM tracking involves clearing the bitmap provided by the domain controlling the guest (e.g. dom0 or a stubdom). If the size of that bitmap is overly large, an intermediate variable on the hypervisor stack may overflow that stack.
Part of the xsa27-4.1.patch, quoted below, might have a bug.
Quoted 11 lines
x86/paging: Don't allocate user-controlled amounts of stack memory.
This is XSA-27 / CVE-2012-5511.
Signed-off-by Tim Deegan <[email protected]>Acked-by Jan Beulich <[email protected]>v2: Provide definition of GB to fix x86-32 compile.
Signed-off-by Jan Beulich <[email protected]>Acked-by Ian Jackson <[email protected]>
[...]
Quoted 14 lines
diff -r
5639047d6c9fxen/arch/x86/mm/paging.cxen/arch/x86/mm/paging.c +4
-3@@ -529,13 +529,18 @@ int paging_log_dirty_range(struct domainif ( !d->arch.paging.log_dirty.fault_count && !d->arch.paging.log_dirty.dirty_count ) { -int size = (nr +BITS_PER_LONG -1 ) /BITS_PER_LONG ; -unsigned long zeroes[size]; -memset (zeroes,0x00 , size *BYTES_PER_LONG ); +static uint8_t zeroes[PAGE_SIZE ]; +int off, size; + + size = ((nr +BITS_PER_LONG -1 ) /BITS_PER_LONG ) *sizeof (long );
xen/arch/x86/mm/paging.c int paging_log_dirty_range(struct domain · line 542
Quoted 10 lines
xen/arch/x86/mm/paging.c +6
-3rv =0 ; -if (copy_to_guest_offset (dirty_bitmap,0 , (uint8_t *) zeroes, - size *BYTES_PER_LONG ) !=0 ) - rv = -EFAULT ; +for ( off =0 ; !rv && off < size; off +=sizeof (zeroes) ) + { +int todo =min (size - off, (int )PAGE_SIZE ); +if (copy_to_guest_offset (dirty_bitmap, off, zeroes, todo) ) + rv = -EFAULT ; + off += todo;
off is incremented twice, once as part of the for loop and once inside. Was that intended?
Credit to Steven Noonan for pointing this out.
Matt
Quoted 4 lines
xen/arch/x86/mm/paging.c +1
-0+ } goto out; } d->arch.paging.log_dirty.fault_count =0 ;
Quoted 19 lines · Matt Wilson
Quoted 19 lines
diff -r
5639047d6c9fxen/arch/x86/mm/paging.cxen/arch/x86/mm/paging.c +5
-6@@ -529,13 +529,18 @@ int paging_log_dirty_range(struct domainif ( !d->arch.paging.log_dirty.fault_count && !d->arch.paging.log_dirty.dirty_count ) { -int size = (nr +BITS_PER_LONG -1 ) /BITS_PER_LONG ; -unsigned long zeroes[size]; -memset (zeroes,0x00 , size *BYTES_PER_LONG ); +static uint8_t zeroes[PAGE_SIZE ]; +int off, size; + + size = ((nr +BITS_PER_LONG -1 ) /BITS_PER_LONG ) *sizeof (long ); rv =0 ; -if (copy_to_guest_offset (dirty_bitmap,0 , (uint8_t *) zeroes, - size *BYTES_PER_LONG ) !=0 ) - rv = -EFAULT ; +for ( off =0 ; !rv && off < size; off +=sizeof (zeroes) )
Quoted 8 lines
xen/arch/x86/mm/paging.c int paging_log_dirty_range(struct domain · line 542
Quoted 5 lines
xen/arch/x86/mm/paging.c +5
-0+ { +int todo =min (size - off, (int )PAGE_SIZE ); +if (copy_to_guest_offset (dirty_bitmap, off, zeroes, todo) ) + rv = -EFAULT ; + off += todo;off is incremented twice, once as part of the for loop and once inside. Was that intended?
It certainly does seem wrong (or too clever for me).
I think either could correctly be removed but the more logical one would be the one in the for loop, I think, since the one inside the body is more accurate (although it only matters for the final iteration and either would cause the loop to exit).
Ian.
Quoted 30 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 19 lines · Matt Wilson
Quoted 19 lines
diff -r
5639047d6c9fxen/arch/x86/mm/paging.cxen/arch/x86/mm/paging.c +5
-6@@ -529,13 +529,18 @@ int paging_log_dirty_range(struct domainif ( !d->arch.paging.log_dirty.fault_count && !d->arch.paging.log_dirty.dirty_count ) { -int size = (nr +BITS_PER_LONG -1 ) /BITS_PER_LONG ; -unsigned long zeroes[size]; -memset (zeroes,0x00 , size *BYTES_PER_LONG ); +static uint8_t zeroes[PAGE_SIZE ]; +int off, size; + + size = ((nr +BITS_PER_LONG -1 ) /BITS_PER_LONG ) *sizeof (long ); rv =0 ; -if (copy_to_guest_offset (dirty_bitmap,0 , (uint8_t *) zeroes, - size *BYTES_PER_LONG ) !=0 ) - rv = -EFAULT ; +for ( off =0 ; !rv && off < size; off +=sizeof (zeroes) )Quoted 8 lines
xen/arch/x86/mm/paging.c int paging_log_dirty_range(struct domain · line 542
Quoted 5 lines
xen/arch/x86/mm/paging.c +5
-0+ { +int todo =min (size - off, (int )PAGE_SIZE ); +if (copy_to_guest_offset (dirty_bitmap, off, zeroes, todo) ) + rv = -EFAULT ; + off += todo;off is incremented twice, once as part of the for loop and once inside. Was that intended?
Quoted 6 lines
It certainly does seem wrong (or too clever for me).
I think either could correctly be removed but the more logical one would be the one in the for loop, I think, since the one inside the body is more accurate (although it only matters for the final iteration and either would cause the loop to exit).
I agree, but since it was Tim who had put this on-off together (as a smaller replacement to the fix that went into 4.2 before its release), I'd leave this to him.
Jan
Quoted 32 lines · Jan Beulich
Quoted 32 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 19 lines · Matt Wilson
Quoted 19 lines
diff -r
5639047d6c9fxen/arch/x86/mm/paging.cxen/arch/x86/mm/paging.c +5
-6@@ -529,13 +529,18 @@ int paging_log_dirty_range(struct domainif ( !d->arch.paging.log_dirty.fault_count && !d->arch.paging.log_dirty.dirty_count ) { -int size = (nr +BITS_PER_LONG -1 ) /BITS_PER_LONG ; -unsigned long zeroes[size]; -memset (zeroes,0x00 , size *BYTES_PER_LONG ); +static uint8_t zeroes[PAGE_SIZE ]; +int off, size; + + size = ((nr +BITS_PER_LONG -1 ) /BITS_PER_LONG ) *sizeof (long ); rv =0 ; -if (copy_to_guest_offset (dirty_bitmap,0 , (uint8_t *) zeroes, - size *BYTES_PER_LONG ) !=0 ) - rv = -EFAULT ; +for ( off =0 ; !rv && off < size; off +=sizeof (zeroes) )Quoted 8 lines
xen/arch/x86/mm/paging.c int paging_log_dirty_range(struct domain · line 542
Quoted 5 lines
xen/arch/x86/mm/paging.c +5
-0+ { +int todo =min (size - off, (int )PAGE_SIZE ); +if (copy_to_guest_offset (dirty_bitmap, off, zeroes, todo) ) + rv = -EFAULT ; + off += todo;off is incremented twice, once as part of the for loop and once inside. Was that intended?
It certainly does seem wrong (or too clever for me).
Quoted 8 lines
Quoted 4 lines
I think either could correctly be removed but the more logical one would be the one in the for loop, I think, since the one inside the body is more accurate (although it only matters for the final iteration and either would cause the loop to exit).
I agree, but since it was Tim who had put this on-off together (as a smaller replacement to the fix that went into 4.2 before its release), I'd leave this to him.
Yeah, the increment in the loop header shouldn't be there.
I can't get to xenbits for an up-to-date tree right now but I'll make a patch once I can.
Tim.
PATCH 1/1 x86/mm: Fix loop increment in paging_log_dirty_range()
# HG changeset patch
# User Tim Deegan <[email protected]>
# Date 1358421452 0
# Node ID 04368044ca5fb9800bfdacf14e883d39cad5c8a6 # Parent 8fe0e86c2ac27e22121aa9c70ddf5eacbb3051d0 x86/mm: Fix loop increment in paging_log_dirty_range()
In 23417:53ef1f35a0f8 (the fix for XSA-27 / CVE-2012-5511), the loop variable gets incremented twice, so the loop only clears every second page of the bitmap. This might cause the tools to think that pages are dirty when they are not.
xen/arch/x86/mm/paging.c +2 -1
@@ -534,7 +534,8 @@ int paging_log_dirty_range(struct domain size = ((nr +BITS_PER_LONG -1 ) /BITS_PER_LONG ) *sizeof (long ); rv =0 ; -for ( off =0 ; !rv && off < size; off +=sizeof zeroes ) + off =0 ; +while ( !rv && off < size ) {int todo =min (size - off, (int )PAGE_SIZE );if (copy_to_guest_offset (dirty_bitmap, off, zeroes, todo) )
Re: [PATCH 4.1-testing] x86/mm: Fix loop increment in paging_log_dirty_range()
Quoted 7 lines · Tim Deegan
# HG changeset patch
# User Tim Deegan <[email protected]>
# Date 1358421452 0
# Node ID04368044ca5fb9800bfdacf14e883d39cad5c8a6# Parent8fe0e86c2ac27e22121aa9c70ddf5eacbb3051d0x86/mm: Fix loop increment inpaging_log_dirty_range()
Quoted 8 lines
In 23417:53ef1f35a0f8 (the fix for XSA-27 / CVE-2012-5511), the loop variable gets incremented twice, so the loop only clears every second page of the bitmap. This might cause the tools to think that pages are dirty when they are not.
Reported-by Steven Noonan <[email protected]>Reported-by Matt Wilson <[email protected]>Signed-off-by Tim Deegan <[email protected]>
Quoted 18 lines
diff -r
8fe0e86c2ac2-r04368044ca5fxen/arch/x86/mm/paging.cxen/arch/x86/mm/paging.c +2
-1@@ -534,7 +534,8 @@ int paging_log_dirty_range(struct domain size = ((nr +BITS_PER_LONG -1 ) /BITS_PER_LONG ) *sizeof (long ); rv =0 ; -for ( off =0 ; !rv && off < size; off +=sizeof zeroes ) + off =0 ; +while ( !rv && off < size ) {int todo =min (size - off, (int )PAGE_SIZE );if (copy_to_guest_offset (dirty_bitmap, off, zeroes, todo) )_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel