From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 18C8AA0350; Wed, 24 Jun 2020 22:01:50 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DD0641DA1D; Wed, 24 Jun 2020 22:01:43 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id 5A7D91DA1C for ; Wed, 24 Jun 2020 22:01:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593028901; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=beN6CX8nwU7ztGagA9kvLxTa3bftdfAuqaRPb9RlyCE=; b=M6mgfZz+aNV4h111Qz41DFhB9xhVCXgSe3frk/GZ5Cuigf5Zl/Pg1fM9GIHgN8v3Tv7Yyl 4Xvw4f2aLLllbqONr3WJvhG3GvzUISZN9esllrYAmLHuJB9fBDTh0733aWkmKAt+BdLaDI MtgL7DgUuq5xmPPyVvY4lqVSQ0Nnt8Y= Received: from mail-vk1-f198.google.com (mail-vk1-f198.google.com [209.85.221.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-9-4cq4tXVwPqq1TN7dGDgu6A-1; Wed, 24 Jun 2020 16:01:37 -0400 X-MC-Unique: 4cq4tXVwPqq1TN7dGDgu6A-1 Received: by mail-vk1-f198.google.com with SMTP id y68so755626vkc.1 for ; Wed, 24 Jun 2020 13:01:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=beN6CX8nwU7ztGagA9kvLxTa3bftdfAuqaRPb9RlyCE=; b=LUusxOGAZ3wrgPrR0qnUJIURlvYZBF/P/52stHBg3Xeb61ET36BDXuS2FrJzAUXwj6 UJhfFmg98O8VExVdbCZJib0yM91CvOoGvamZUrEJ7b9tTflX3wbRfXuUaWZ+yiK8wuEG 7OOo6ElUzinkbmnrKeZ84dWybVHJT60zbxtMrBWUIQ1CPd2fmYVIz8K+XGwiBga266LY mBYqv/cAt/LjFYQ5hF7bpjXw+aQzdZm42uVgnLyOQXWhinubCNUy6lpm3sv3Z5cRBKtR 550SduwWa/z/ENmDog4P/4R/yBuHqBcb8TGEeGS9+HYW7zp5fg1k/mgP3PSuuruUd0jg OP+Q== X-Gm-Message-State: AOAM531QeW1wzdU0qk/xiT2tUXT66TV6o7o2jJstSWrtMqrNndhKTSVl Oa316MzfCF+X0XO1rzvjIRhmFEOzpISI+ySEXEUAx53EMZAGttdYpedNfcU6e2qIs8GaCWaSv96 Z4ExqApSLEgBALl+slLY= X-Received: by 2002:a9f:3fc8:: with SMTP id m8mr7113626uaj.53.1593028897300; Wed, 24 Jun 2020 13:01:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztWr1qVuA5cIMcpFJOY4BLEBhkhP30QzyRUpCmghjGH8+ZYAM6hZHJN/TIqUXOob3jdf+1bnCHzRpXiEkbbnM= X-Received: by 2002:a9f:3fc8:: with SMTP id m8mr7113523uaj.53.1593028896099; Wed, 24 Jun 2020 13:01:36 -0700 (PDT) MIME-Version: 1.0 References: <20200621174035.6858-1-haiyue.wang@intel.com> <20200622111351.101006-1-haiyue.wang@intel.com> In-Reply-To: <20200622111351.101006-1-haiyue.wang@intel.com> From: David Marchand Date: Wed, 24 Jun 2020 22:01:25 +0200 Message-ID: To: Haiyue Wang Cc: dev , "Burakov, Anatoly" , dpdk stable , Maxime Coquelin Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Subject: Re: [dpdk-dev] [PATCH v3] bus/pci: fix VF bus error for memory access X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Mon, Jun 22, 2020 at 1:23 PM Haiyue Wang wrote: > > To fix CVE-2020-12888, the linux vfio-pci module will invalidate mmaps > and block MMIO access on disabled memory, it will send a SIGBUS to the > application: > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=abafbc551fddede3e0a08dee1dcde08fc0eb8476 > > When the application opens the vfio PCI device, the vfio-pci module will > enable the bus memory space through PCI read/write access. According to > the PCIe specification, the 'Memory Space Enable' is always zero for VF: > > Table 9-13 Command Register Changes > > Bit Location | PF and VF Register Differences | PF | VF > | From Base | Attributes | Attributes > -------------+--------------------------------+------------+----------- > | Memory Space Enable - Does not | | > | apply to VFs. Must be hardwired| Base | 0b > 1 | to 0b for VFs. VF Memory Space | | > | is controlled by the VF MSE bit| | > | in the VF Control register. | | > -------------+--------------------------------+------------+----------- > > Afterwards the vfio-pci will initialize its own virtual PCI config space > data ('vconfig') by reading the VF's physical PCI config space, then the > 'Memory Space Enable' bit in vconfig will always be 0b value. This will > make the vfio-pci treat the BAR memory space as disabled, and the SIGBUS > will be triggerred if access these BARs. triggered > > By investigation, the VF PCI device *passthrough* into the Guest OS by > QEMU has the 'Memory Space Enable' with 1b value. That's because every > PCI driver will start to enable the memory space, and this action will > be hooked by vfio-pci virtual PCI read/write to set the 'Memory Space > Enable' in vconfig space to 1b. So VF runs in guest OS has 'Mem+', but > VF runs in host OS has 'Mem-'. > > Align with PCI working mode in Guest/QEMU/Host, in DPDK, enable the PCI > bus memory space explicitly to avoid access on disabled memory. > > Fixes: 33604c31354a ("vfio: refactor PCI BAR mapping") > Cc: stable@dpdk.org > > Signed-off-by: Haiyue Wang Ouch, we just hit it. Thanks for fixing! Tested-by: David Marchand -- David Marchand