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.2 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 42FFCC433DF for ; Thu, 28 May 2020 09:42:41 +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 1A079208DB for ; Thu, 28 May 2020 09:42:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1A079208DB 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 1jeF3U-0005WO-6M; Thu, 28 May 2020 09:42:28 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jeF3T-0005WJ-77 for xen-devel@lists.xenproject.org; Thu, 28 May 2020 09:42:27 +0000 X-Inumbo-ID: 89fce90e-a0c7-11ea-a7aa-12813bfff9fa Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 89fce90e-a0c7-11ea-a7aa-12813bfff9fa; Thu, 28 May 2020 09:42:26 +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 DEEE1AD63; Thu, 28 May 2020 09:42:24 +0000 (UTC) Subject: Re: [PATCH v6 4/5] common/domain: add a domain context record for shared_info... To: Paul Durrant References: <20200527173407.1398-1-paul@xen.org> <20200527173407.1398-5-paul@xen.org> From: Jan Beulich Message-ID: <5589a800-a40a-5534-d2e8-09df78072b02@suse.com> Date: Thu, 28 May 2020 11:42:24 +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: <20200527173407.1398-5-paul@xen.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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: Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , Paul Durrant , Ian Jackson , George Dunlap , xen-devel@lists.xenproject.org Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On 27.05.2020 19:34, Paul Durrant wrote: > @@ -1649,6 +1650,75 @@ int continue_hypercall_on_cpu( > return 0; > } > > +static int save_shared_info(const struct domain *d, struct domain_context *c, > + bool dry_run) > +{ > + struct domain_shared_info_context ctxt = { > +#ifdef CONFIG_COMPAT > + .flags = has_32bit_shinfo(d) ? DOMAIN_SAVE_32BIT_SHINFO : 0, > + .buffer_size = has_32bit_shinfo(d) ? > + sizeof(struct compat_shared_info) : > + sizeof(struct shared_info), > +#else > + .buffer_size = sizeof(struct shared_info), > +#endif To prevent disconnect between the types used here and the actual pointer copied from, I'd have preferred #ifdef CONFIG_COMPAT .flags = has_32bit_shinfo(d) ? DOMAIN_SAVE_32BIT_SHINFO : 0, .buffer_size = has_32bit_shinfo(d) ? sizeof(d->shared_info->compat) : sizeof(d->shared_info->native), #else .buffer_size = sizeof(*d->shared_info), #endif But this is secondary, as the types indeed are very unlikely to go out of sync. What's more important is ... > +static int load_shared_info(struct domain *d, struct domain_context *c) > +{ > + struct domain_shared_info_context ctxt; > + size_t hdr_size = offsetof(typeof(ctxt), buffer); > + unsigned int i; > + int rc; > + > + rc = DOMAIN_LOAD_BEGIN(SHARED_INFO, c, &i); > + if ( rc ) > + return rc; > + > + if ( i ) /* expect only a single instance */ > + return -ENXIO; > + > + rc = domain_load_data(c, &ctxt, hdr_size); > + if ( rc ) > + return rc; > + > + if ( ctxt.buffer_size > sizeof(shared_info_t) || > + (ctxt.flags & ~DOMAIN_SAVE_32BIT_SHINFO) ) > + return -EINVAL; > + > + if ( ctxt.flags & DOMAIN_SAVE_32BIT_SHINFO ) > +#ifdef CONFIG_COMPAT > + has_32bit_shinfo(d) = true; > +#else > + return -EINVAL; > +#endif > + > + rc = domain_load_data(c, d->shared_info, sizeof(shared_info_t)); > + if ( rc ) > + return rc; ... the still insufficient checking here. You shouldn't accept more than sizeof(d->shared_info->compat) worth of data in the compat case if you also don't accept more than sizeof(shared_info_t) in the native case. To save another round trip I'll offer to make the adjustments while committing, but patches 3 and 5 want Andrew's ack first anyway. Jan