Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp297873imj; Wed, 13 Feb 2019 08:30:25 -0800 (PST) X-Google-Smtp-Source: AHgI3IZj7ToulU48RHwS1IrLW6q3k6iOif+OnwsPDRJDMooTmfmMGPqphWQveEjjiBsUGJZQaHKv X-Received: by 2002:a62:3a92:: with SMTP id v18mr1300305pfj.43.1550075425357; Wed, 13 Feb 2019 08:30:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550075425; cv=none; d=google.com; s=arc-20160816; b=cNMgejKwZPKq2RQGG1oUsl/tv1zbYLkNNqGJUhT+D/sFztGIQN+rJMFBHFcXfxEHaC sExlmiOvPAC4EM5gJsr1ipqJxFirtbpzIobR4jRy3evMmMhgw3lDzhy4XoV5TlxF/Cal HP2XpUI9qaCs73KMhkGD50ATPwwA2f+BVhSPDOUR3VKbCEDoNIOOOAlTseJhiJtaG09Q brQOuVzRisfDJM+8KVS6LyGW8kaw8hMnuJSlR8qVIq9GuvqqF/3RIXVZpXAFxek71lmg NVWRGtzSvRsvNzdP9ujMd4dxu7EyzDAUGMlif5QwUO4dqe3JZpzT9eR5LdToRAF+V0/l XyHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=wx7Y2TIha6dVGdshZaOcrv7Qrw7Uy9yBsRD4sYdzn5c=; b=gXrX7b7+K/HWZ5h9LL5LZz9a6wEItcI6wg+SsrzkeUQ1sr/EAYckeUet26ThVsoDCT x3qFm18GQyy6rhExkz6x43TLv1aHjt8KVXXiqvLouS56e+Z0EIXAfbgSK7HqwhUOLf2Y BD5TnPhRle8x57ZVc3A2C7mQx3eIrFKpO7gKtACpMVSgu1VSnzDGIEWqgzr/h3RHQnLc 5DbEXjvcOmRyPbPXOZ9wF0Oqqrrrt1qsl7TkV4Ngj7raVDylG19620yyqg9y0avuZ0td I/dNHb/JfSICGNayYOfoNX6UDsCdbSyDBxqOOn2BcdOPJ7OBLul84mEX+Fw57zQtJrSV RagQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=Iu0VoZYx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id h189si16448080pfc.211.2019.02.13.08.30.08; Wed, 13 Feb 2019 08:30:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=Iu0VoZYx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S2392697AbfBMQ2q (ORCPT + 99 others); Wed, 13 Feb 2019 11:28:46 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:39264 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728150AbfBMQ2q (ORCPT ); Wed, 13 Feb 2019 11:28:46 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x1DGIaSZ103986; Wed, 13 Feb 2019 16:28:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2018-07-02; bh=wx7Y2TIha6dVGdshZaOcrv7Qrw7Uy9yBsRD4sYdzn5c=; b=Iu0VoZYx8milwuwMJPaZOk2fhda7NXlgfjEWv/1iDZvTYU/2GkRrZOtVTBjpJ7qBbXdN c9uXnkTTaBah3dGzhEeqRgY/XHxr01x1LQFl/muYNv0d65MZlRrCiSCin6FlVLmLnpJb 3czi6j2/v6DCz4YOqdF/NDK2na0bcHfFx7jlSAoQyipbYYhUeKmRbIy5Z/3zej8Y+qo8 szvKNu6BatfIKkyYyRWBq9IyJaAzO2zuqR57muWkUZ8csSfTqtAHjlFTzB/dWqWstRcy TBjnGf4Ke0LSxZpSO8mKl1X8LXjlzY7dFMt9ts6NVqqlvMQD6pSVcaRLvee0iRyzOwTE pQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2qhrekk26u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Feb 2019 16:28:25 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x1DGSPOY029844 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Feb 2019 16:28:25 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x1DGSPdr013578; Wed, 13 Feb 2019 16:28:25 GMT Received: from char.us.oracle.com (/10.152.32.25) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 13 Feb 2019 08:28:24 -0800 Received: by char.us.oracle.com (Postfix, from userid 1000) id 1E99D6A0133; Wed, 13 Feb 2019 11:28:21 -0500 (EST) Date: Wed, 13 Feb 2019 11:28:21 -0500 From: Konrad Rzeszutek Wilk To: Eric Auger Cc: eric.auger.pro@gmail.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, alex.williamson@redhat.com Subject: Re: [PATCH] vfio_pci: Enable memory accesses before calling pci_map_rom Message-ID: <20190213162821.GC22883@char.us.oracle.com> References: <20190213101406.3934-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190213101406.3934-1-eric.auger@redhat.com> User-Agent: Mutt/1.9.1 (2017-09-22) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9165 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=791 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902130117 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 13, 2019 at 11:14:06AM +0100, Eric Auger wrote: > pci_map_rom/pci_get_rom_size() performs memory access in the ROM. > In case the Memory Space accesses were disabled, readw() is likely to > crash the host with a synchronous external abort (aarch64). Ouch. Is there an CVE for this? Also I think this can cause x86 machines to blow up. See https://xenbits.xen.org/xsa/advisory-120.html > > In case memory accesses were disabled, re-enable them before the call > and disable them back again just after. > > Signed-off-by: Eric Auger > --- > drivers/vfio/pci/vfio_pci.c | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c > index ff60bd1ea587..96b8bbd909d7 100644 > --- a/drivers/vfio/pci/vfio_pci.c > +++ b/drivers/vfio/pci/vfio_pci.c > @@ -706,8 +706,10 @@ static long vfio_pci_ioctl(void *device_data, > break; > case VFIO_PCI_ROM_REGION_INDEX: > { > + bool mem_access_disabled; > void __iomem *io; > size_t size; > + u16 cmd; > > info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index); > info.flags = 0; > @@ -723,6 +725,13 @@ static long vfio_pci_ioctl(void *device_data, > break; > } > > + pci_read_config_word(pdev, PCI_COMMAND, &cmd); > + mem_access_disabled = !(cmd & PCI_COMMAND_MEMORY); > + if (mem_access_disabled) { > + cmd |= PCI_COMMAND_MEMORY; > + pci_write_config_word(pdev, PCI_COMMAND, cmd); > + } > + > /* Is it really there? */ > io = pci_map_rom(pdev, &size); > if (!io || !size) { > @@ -731,6 +740,11 @@ static long vfio_pci_ioctl(void *device_data, > } > pci_unmap_rom(pdev, io); > > + if (mem_access_disabled) { > + cmd &= ~PCI_COMMAND_MEMORY; > + pci_write_config_word(pdev, PCI_COMMAND, cmd); > + } > + > info.flags = VFIO_REGION_INFO_FLAG_READ; > break; > } > -- > 2.20.1 >