Message ID | acbaead9-0f6c-3606-e809-57dafe9b3f01@suse.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | x86: XSA-298 follow-up | expand |
On Wed, May 20, 2020 at 09:53:50AM +0200, Jan Beulich wrote: > It is wrong for us to check frames beyond the guest specified limit > (in the compat case another loop bound is already correct). > > Signed-off-by: Jan Beulich <jbeulich@suse.com> Reviewed-by: Roger Pau Monné <roger.pau@citrix.com> Thanks, Roger.
On 20/05/2020 08:53, Jan Beulich wrote: > It is wrong for us to check frames beyond the guest specified limit > (in the compat case another loop bound is already correct). > > Signed-off-by: Jan Beulich <jbeulich@suse.com> I'm still not overly convinced this is a good idea, because all it will allow people to do is write lazy code which breaks on older Xen. However, if you still insist, Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
On 22.05.2020 15:27, Andrew Cooper wrote: > On 20/05/2020 08:53, Jan Beulich wrote: >> It is wrong for us to check frames beyond the guest specified limit >> (in the compat case another loop bound is already correct). >> >> Signed-off-by: Jan Beulich <jbeulich@suse.com> > > I'm still not overly convinced this is a good idea, because all it will > allow people to do is write lazy code which breaks on older Xen. Sounds a little like keeping bugs for the sake of keeping things broken. The range of misbehaving versions could be shrunk by backporting this change; I didn't intend to though, so far. > However, if you still insist, Acked-by: Andrew Cooper > <andrew.cooper3@citrix.com> Thanks! Jan
--- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -840,6 +840,7 @@ int arch_set_info_guest( #ifdef CONFIG_PV mfn_t cr3_mfn; struct page_info *cr3_page = NULL; + unsigned int nr_gdt_frames; int rc = 0; #endif @@ -957,6 +958,10 @@ int arch_set_info_guest( /* Ensure real hardware interrupts are enabled. */ v->arch.user_regs.eflags |= X86_EFLAGS_IF; + nr_gdt_frames = DIV_ROUND_UP(c(gdt_ents), 512); + if ( nr_gdt_frames > ARRAY_SIZE(v->arch.pv.gdt_frames) ) + return -EINVAL; + if ( !v->is_initialised ) { if ( !compat && !(flags & VGCF_in_kernel) && !c.nat->ctrlreg[1] ) @@ -988,9 +993,9 @@ int arch_set_info_guest( fail = compat_pfn_to_cr3(pfn) != c.cmp->ctrlreg[3]; } - for ( i = 0; i < ARRAY_SIZE(v->arch.pv.gdt_frames); ++i ) - fail |= v->arch.pv.gdt_frames[i] != c(gdt_frames[i]); fail |= v->arch.pv.gdt_ents != c(gdt_ents); + for ( i = 0; !fail && i < nr_gdt_frames; ++i ) + fail = v->arch.pv.gdt_frames[i] != c(gdt_frames[i]); fail |= v->arch.pv.ldt_base != c(ldt_base); fail |= v->arch.pv.ldt_ents != c(ldt_ents); @@ -1095,12 +1100,8 @@ int arch_set_info_guest( else { unsigned long gdt_frames[ARRAY_SIZE(v->arch.pv.gdt_frames)]; - unsigned int nr_frames = DIV_ROUND_UP(c.cmp->gdt_ents, 512); - - if ( nr_frames > ARRAY_SIZE(v->arch.pv.gdt_frames) ) - return -EINVAL; - for ( i = 0; i < nr_frames; ++i ) + for ( i = 0; i < nr_gdt_frames; ++i ) gdt_frames[i] = c.cmp->gdt_frames[i]; rc = (int)pv_set_gdt(v, gdt_frames, c.cmp->gdt_ents);
It is wrong for us to check frames beyond the guest specified limit (in the compat case another loop bound is already correct). Signed-off-by: Jan Beulich <jbeulich@suse.com> --- v3: Move nr_gdt_frames range check earlier. Avoid |= where not really needed.