From: Tim Deegan Subject: Re: Xen Security Advisory 27 (CVE-2012-5511) - several HVM operations do not validate the range of their inputs Date: Mon, 14 Jan 2013 12:19:24 +0000 Message-ID: <20130114121924.GA65620@ocelot.phlegethon.org> References: <20130112153524.GA15043@u109add4315675089e695.ant.amazon.com> <1358159014.13029.11.camel@zakaz.uk.xensource.com> <50F3F17302000078000B53AA@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <50F3F17302000078000B53AA@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jan Beulich Cc: Steven Noonan , Ian Campbell , Matt Wilson , "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org At 10:52 +0000 on 14 Jan (1358160739), Jan Beulich wrote: > >>> On 14.01.13 at 11:23, Ian Campbell wrote: > > On Sat, 2013-01-12 at 15:35 +0000, Matt Wilson wrote: > >> > diff -r 5639047d6c9f xen/arch/x86/mm/paging.c > >> > --- a/xen/arch/x86/mm/paging.c Mon Nov 19 09:43:48 2012 +0100 > >> > +++ b/xen/arch/x86/mm/paging.c Mon Nov 19 16:00:33 2012 +0000 > >> > @@ -529,13 +529,18 @@ int paging_log_dirty_range(struct domain > >> > > >> > if ( !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) ) > >> > + { > >> > + 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). > > 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.