From: "Jan Beulich" Subject: Re: [PATCH] xen: add assertions in default_vcpu0_location to protect against broken masks Date: Tue, 26 Jun 2012 14:54:11 +0100 Message-ID: <4FE9DB23020000780008BF61@nat28.tlf.novell.com> References: <1340704026-20406-1-git-send-email-ian.campbell@citrix.com> <4FE9A80D020000780008BE0B@nat28.tlf.novell.com> <1340716623.3832.96.camel@zakaz.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1340716623.3832.96.camel@zakaz.uk.xensource.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: "Keir (Xen.org)" , "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org >>> On 26.06.12 at 15:17, Ian Campbell wrote: > On Tue, 2012-06-26 at 11:16 +0100, Jan Beulich wrote: >> >>> On 26.06.12 at 11:47, Ian Campbell wrote: >> > When setting up the cpu sibling/etc masks on ARM I accidentally and >> > incorrectly omitted a CPU from it's own sibling mask which caused this >> > function to scribble over the heap. Add a couple of asserts to catch this > in >> > the future. >> > >> > Signed-off-by: Ian Campbell >> > Cc: Keir (Xen.org) >> > Cc: Jan Beulich >> > --- >> > xen/common/domctl.c | 2 ++ >> > 1 files changed, 2 insertions(+), 0 deletions(-) >> > >> > diff --git a/xen/common/domctl.c b/xen/common/domctl.c >> > index 9f1a9ad..c1acd1d 100644 >> > --- a/xen/common/domctl.c >> > +++ b/xen/common/domctl.c >> > @@ -190,10 +190,12 @@ static unsigned int default_vcpu0_location(cpumask_t >> > *online) >> > */ >> > cpumask_copy(&cpu_exclude_map, per_cpu(cpu_sibling_mask, 0)); >> > cpu = cpumask_first(&cpu_exclude_map); >> > + ASSERT(cpu < nr_cpus); >> > if ( cpumask_weight(&cpu_exclude_map) > 1 ) >> > cpu = cpumask_next(cpu, &cpu_exclude_map); >> >> You may want to add another ASSERT() here in case you care >> about the difference between nr_cpus and nr_cpu_ids. Or move >> the ASSERT() here if the difference is insignificant (as I would >> think), as cpumask_next() invokes cpumask_check() (see also >> below). > > It is possible to get through this code without calling > cpumask_next(cpu, ..) though, I think, due to the if. > > Perhaps > ASSERT(cpu < nr_cpu_ids); > after the if would be the best option? That's what I meant with "here" in my first response. >> > for_each_cpu(i, online) >> > { >> > + ASSERT(i < nr_cpus); >> >> This one is almost redundant with the one in cpumask_check() >> called from cpumask_test_cpu() (and the difference between >> using nr_cpu_ids and nr_cpus doesn't seem relevant here), so >> I'd recommend going with just the single earlier addition. > > If mask is invalid you can the first iteration with the bad i (from > cpumask_first, which doesn't have any checks), which may scribble off > the end of the cnt array. Immediately after the ASSERT() here there is an invocation of cpumask_test_cpu(), which itself uses cpumask_check(). That's what the added ASSERT() is redundant with. > I'm not sure why I wasn't hitting an assert from the subsequent > cpumask_next, but I wasn't. > > If you are still convinced this ASSERT isn't worth it I'll drop it, I've > found my bug now and it'd be a pretty uncommon one to repeat... Please do. Jan