[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH 06/12] libxenguest: guard against overflow from too large p2m when checkpointing
On 25/06/2021 14:20, Jan Beulich wrote: > struct xc_sr_record's length field has just 32 bits. The stream max record length is /* Somewhat arbitrary - 128MB */ #define REC_LENGTH_MAX (128U << 20) and is checked in the low level helpers, making the upper bound on the number of PFNs 0xFFFFFF once the record header is taken into account. There doesn't appear to have been any consideration made to what happens if this number gets too large. That said, the replication will totally fall apart if it ever gets to a fraction of this, because this is the list of pages the source side needs to send again in addition to whatever *it* dirtied, as it is the state we've lost on the destination side by permitting the VM to run live. The common case is that, when execution diverges, the dirtied pages on source and destination will be almost the same, so merging this on the source side shouldn't lead to many superfluous pages needing to be sent. > Fill it early and > check that the calculated value hasn't overflowed. Additionally check > for counter overflow early - there's no point even trying to allocate > any memory in such an event. > > While there also limit an induction variable's type to unsigned long: > There's no gain from it being uint64_t. > > Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx> > --- > Of course looping over test_bit() is pretty inefficient, but given that > I have no idea how to test this code I wanted to restrict changes to > what can sensibly be seen as no worse than before from just looking at > the changes. At this point, I'm not sure it can be tested. IIRC, COLO depends on some functionality which didn't make its way upstream into Qemu. > --- a/tools/libs/guest/xg_sr_restore.c > +++ b/tools/libs/guest/xg_sr_restore.c > @@ -450,7 +450,8 @@ static int send_checkpoint_dirty_pfn_lis > xc_interface *xch = ctx->xch; > int rc = -1; > unsigned int count, written; > - uint64_t i, *pfns = NULL; > + unsigned long i; > + uint64_t *pfns = NULL; > struct iovec *iov = NULL; > struct xc_sr_record rec = { > .type = REC_TYPE_CHECKPOINT_DIRTY_PFN_LIST, > @@ -469,16 +470,28 @@ static int send_checkpoint_dirty_pfn_lis > > for ( i = 0, count = 0; i < ctx->restore.p2m_size; i++ ) > { > - if ( test_bit(i, dirty_bitmap) ) > - count++; > + if ( test_bit(i, dirty_bitmap) && !++count ) This is far too opaque logic. Its also entirely unnecessary... All this loop is doing is calculating the size for the memory allocation below, and that can be done by using the stats output from xc_logdirty_control(), which means it doesn't want deleting in the earlier patch. ~Andrew
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |