Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp480142pxu; Tue, 1 Dec 2020 16:46:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJyzSID/hKl4ybfpdAFMo4CYxamKrQ4EpzZNcK+bcE3griQUEV+0C/DPRh6mZMLwQ28slKmX X-Received: by 2002:a50:a40a:: with SMTP id u10mr244667edb.16.1606869964202; Tue, 01 Dec 2020 16:46:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606869964; cv=none; d=google.com; s=arc-20160816; b=wIN9idX+nSwtXDcm1s2OKIXuZp60O/jWgCnZ+ka6E0oyoCoYLrMkGyF1rIaHt05bal te2nHfyn4dV/LUZHHBe82J+VOYXqPSGdqHZRoJdH/L0FaSBI7WpRg4p2uZeE1JRtQMIz Mp2sWuYRYHs1lLaajS0rvlfBFPv0suR5xeNWsTfW0SbPZywxVM088VyPTufCO1sWvH1I 3Q2Y6j3VovieTAjHpmYBRYaU47UWYpC6tyX1GbhFA3Mmvb7tpLyGVTGYlk+KJa1KRNMW VgcqxDkAFt6zfL/1wnIEkikQKg2psvJue4z12BlJQJRih2OrYyvBaErUJNfq3PKHGHsu 7CNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=+QnGX543wIkXyLX+8yfaBqOqLwRBEAofgYjBOnar1Sw=; b=VXzyl01wEzfjNdKy8hl66ADWcCSV0sCYVMt9jrjXRL6n77ZRsKPFu2TmEgzQ/IEbVC yFcLjUlm7KF5bSgAog3MjK7Upbqo+2LRcyrryWxMzCh1dEu0KmAOYVCk3bxpDQRK7mRn h1PhueSP2GHYkAXb+lSy1rQqbdxJqDsp3Cu2vxYjosVCPvPxrlhP1qn+jrGUQKEKW5S2 Q4DdMmiW5EaYrQrk3K77+CNVkOaQcXX78i9JyL0lfJGinNmR4Do3YR5jniEjO0ig3Oub SMdf0AP6zxNlxEw+evOvyBguCjcyAiW/TWdqaiAACt2GxWPsJ09WMVurLQQLSwKJj4sb edqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=RoxUDqoP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m8si891374eja.18.2020.12.01.16.45.40; Tue, 01 Dec 2020 16:46:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=RoxUDqoP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727461AbgLBAna (ORCPT + 99 others); Tue, 1 Dec 2020 19:43:30 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:41056 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726166AbgLBAna (ORCPT ); Tue, 1 Dec 2020 19:43:30 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B20e0bj031883; Wed, 2 Dec 2020 00:42:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=+QnGX543wIkXyLX+8yfaBqOqLwRBEAofgYjBOnar1Sw=; b=RoxUDqoPGYBjQqoW73RstcFbtrD6mhwgA8QUKF+7kSIG+146ln7VyZE1I5Tj2weHzWOc JRvnDpQDpsnAkItn5NBE1214FSE4FYNkvJkBmlRJxy6lhH4ecau0heGUGqhmIeYy135G xqiLHWBOU0L2tFqrYyn3gAnRr6KCumOPmrKUSVzebH/8wbMiws0aOKmuPJ+vqdwh/iKz M8tP5RglcBIEftfeL9FA7drsqtjuO24aI3Qau7Ouc4Wcv7S0GrTdpWqp2UL+e7HzMfx5 7GuH4arrLMWZyBrMXU8oF1pBrgPviEzBE0/QOhv8P6/UENYFBJOYBRwvulGY/SXq3OfL gg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 353dyqnhyd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 02 Dec 2020 00:42:12 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B20adfw193756; Wed, 2 Dec 2020 00:40:12 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 35404njyv3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 02 Dec 2020 00:40:11 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0B20e9QE001999; Wed, 2 Dec 2020 00:40:09 GMT Received: from [10.159.145.103] (/10.159.145.103) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Dec 2020 16:40:09 -0800 Subject: Re: [PATCH RFC 03/39] KVM: x86/xen: register shared_info page To: David Woodhouse , Joao Martins , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Boris Ostrovsky , Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org References: <20190220201609.28290-1-joao.m.martins@oracle.com> <20190220201609.28290-4-joao.m.martins@oracle.com> From: Ankur Arora Message-ID: <2d4df59d-f945-32dc-6999-a6f711e972ea@oracle.com> Date: Tue, 1 Dec 2020 16:40:07 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 bulkscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012020001 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9822 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 clxscore=1011 mlxscore=0 spamscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012020001 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-12-01 5:07 a.m., David Woodhouse wrote: > On Wed, 2019-02-20 at 20:15 +0000, Joao Martins wrote: >> +static int kvm_xen_shared_info_init(struct kvm *kvm, gfn_t gfn) >> +{ >> + struct shared_info *shared_info; >> + struct page *page; >> + >> + page = gfn_to_page(kvm, gfn); >> + if (is_error_page(page)) >> + return -EINVAL; >> + >> + kvm->arch.xen.shinfo_addr = gfn; >> + >> + shared_info = page_to_virt(page); >> + memset(shared_info, 0, sizeof(struct shared_info)); >> + kvm->arch.xen.shinfo = shared_info; >> + return 0; >> +} >> + > > Hm. > > How come we get to pin the page and directly dereference it every time, > while kvm_setup_pvclock_page() has to use kvm_write_guest_cached() > instead? So looking at my WIP trees from the time, this is something that we went back and forth on as well with using just a pinned page or a persistent kvm_vcpu_map(). I remember distinguishing shared_info/vcpu_info from kvm_setup_pvclock_page() as shared_info is created early and is not expected to change during the lifetime of the guest which didn't seem true for MSR_KVM_SYSTEM_TIME (or MSR_KVM_STEAL_TIME) so that would either need to do a kvm_vcpu_map() kvm_vcpu_unmap() dance or do some kind of synchronization. That said, I don't think this code explicitly disallows any updates to shared_info. > > If that was allowed, wouldn't it have been a much simpler fix for > CVE-2019-3016? What am I missing? Agreed. Perhaps, Paolo can chime in with why KVM never uses pinned page and always prefers to do cached mappings instead? > > Should I rework these to use kvm_write_guest_cached()? kvm_vcpu_map() would be better. The event channel logic does RMW operations on shared_info->vcpu_info. Ankur > >