Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43882C433DF for ; Tue, 19 May 2020 09:37:23 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 14799207D3 for ; Tue, 19 May 2020 09:37:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 14799207D3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jayg2-0002bE-0U; Tue, 19 May 2020 09:36:46 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jayfz-0002b9-TH for xen-devel@lists.xenproject.org; Tue, 19 May 2020 09:36:43 +0000 X-Inumbo-ID: 3f940236-99b4-11ea-b07b-bc764e2007e4 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 3f940236-99b4-11ea-b07b-bc764e2007e4; Tue, 19 May 2020 09:36:43 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id DFC8EAC5F; Tue, 19 May 2020 09:36:44 +0000 (UTC) Subject: Re: [PATCH v2 1/3] x86: relax GDT check in arch_set_info_guest() To: =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= References: <3f78d1dc-720d-6bf3-0911-c19da1a2ddbb@suse.com> <20200519084242.GZ54375@Air-de-Roger> From: Jan Beulich Message-ID: <3347c044-b4d2-cfeb-2bc7-1eccb956b47f@suse.com> Date: Tue, 19 May 2020 11:36:41 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200519084242.GZ54375@Air-de-Roger> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: "xen-devel@lists.xenproject.org" , Wei Liu , Andrew Cooper Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On 19.05.2020 10:42, Roger Pau Monné wrote: > On Fri, Dec 20, 2019 at 02:49:48PM +0100, Jan Beulich wrote: >> It is wrong for us to check frames beyond the guest specified limit >> (in the native case, other than in the compat one). > > Wouldn't this result in arch_set_info_guest failing if gdt_ents was > smaller than the maximum? Or all callers always pass gdt_ents set to > the maximum? Since the array is embedded in the struct, I suppose callers simply start out from a zero-initialized array, in which case the actual count given doesn't matter. Additionally I think it is uncommon for the function to get called on a vCPU with v->is_initialised already set. >> @@ -982,9 +985,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 doesn't need to be OR'ed anymore here, since you check for it in > the loop condition. Ah yes, changed. >> @@ -1089,12 +1092,11 @@ 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) ) >> + if ( nr_gdt_frames > ARRAY_SIZE(v->arch.pv.gdt_frames) ) >> return -EINVAL; > > Shouldn't this check be performed when nr_gdt_frames is initialized > instead of here? (as nr_gdt_frames is already used as a limit to > iterate over gdt_frames). Oh, yes, of course. Thanks for spotting. Jan