From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D96BEC4332F for ; Fri, 18 Feb 2022 01:09:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231168AbiBRBJi (ORCPT ); Thu, 17 Feb 2022 20:09:38 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:37242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230107AbiBRBJg (ORCPT ); Thu, 17 Feb 2022 20:09:36 -0500 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D2883BA47; Thu, 17 Feb 2022 17:09:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645146561; x=1676682561; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=i/uHlQnpqnYhs2UtoI5OgAOBiOeNbQTVCxOGakFU9Us=; b=WDxa2hw2LT1oLushOA1x/8uZB+xePo/ogmkmdhsTBGzd1DDh4odVYxxO 7zB0NHw7aapm/ZlMSRe2xCVU4+am1gWUHJArBxwIfLuKrOCWvzZ14TmsN IkPqxaE4XvzotLDA2AU+KrkT+MP5JIOXqYmKQnZfBzd4+l8YSZ+w8b/KH shkq21xb8dNqsJ4thM5z6eGAFkiU6KBOncXz6LU5NidQJcVAv6CkCjF24 /5qNrnUa5BVEHkkd551yJXJJ1FfdSIuDHwu0xypENRWRgoVcgRvJgtRgw 7J241EHXwj1S20B2om/hTogaQo6gRw1GiaxUPb751H8moIzRZl3pBB6YC Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10261"; a="238423700" X-IronPort-AV: E=Sophos;i="5.88,377,1635231600"; d="scan'208";a="238423700" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2022 17:09:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,377,1635231600"; d="scan'208";a="682271178" Received: from allen-box.sh.intel.com (HELO [10.239.159.118]) ([10.239.159.118]) by fmsmga001.fm.intel.com with ESMTP; 17 Feb 2022 17:09:13 -0800 Message-ID: Date: Fri, 18 Feb 2022 09:07:51 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Cc: baolu.lu@linux.intel.com, Will Deacon , Robin Murphy , Dan Williams , rafael@kernel.org, Diana Craciun , Cornelia Huck , Eric Auger , Liu Yi L , Jacob jun Pan , Chaitanya Kulkarni , Stuart Yoder , Laurentiu Tudor , Thierry Reding , David Airlie , Daniel Vetter , Jonathan Hunter , Li Yang , Dmitry Osipenko , iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 00/14] Fix BUG_ON in vfio_iommu_group_notifier() Content-Language: en-US To: Greg Kroah-Hartman , Joerg Roedel , Alex Williamson , Bjorn Helgaas , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj References: <20220104015644.2294354-1-baolu.lu@linux.intel.com> From: Lu Baolu In-Reply-To: <20220104015644.2294354-1-baolu.lu@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/4/22 9:56 AM, Lu Baolu wrote: > Hi folks, > > The iommu group is the minimal isolation boundary for DMA. Devices in > a group can access each other's MMIO registers via peer to peer DMA > and also need share the same I/O address space. > > Once the I/O address space is assigned to user control it is no longer > available to the dma_map* API, which effectively makes the DMA API > non-working. > > Second, userspace can use DMA initiated by a device that it controls > to access the MMIO spaces of other devices in the group. This allows > userspace to indirectly attack any kernel owned device and it's driver. > > Therefore groups must either be entirely under kernel control or > userspace control, never a mixture. Unfortunately some systems have > problems with the granularity of groups and there are a couple of > important exceptions: > > - pci_stub allows the admin to block driver binding on a device and > make it permanently shared with userspace. Since PCI stub does not > do DMA it is safe, however the admin must understand that using > pci_stub allows userspace to attack whatever device it was bound > it. > > - PCI bridges are sometimes included in groups. Typically PCI bridges > do not use DMA, and generally do not have MMIO regions. > > Generally any device that does not have any MMIO registers is a > possible candidate for an exception. > > Currently vfio adopts a workaround to detect violations of the above > restrictions by monitoring the driver core BOUND event, and hardwiring > the above exceptions. Since there is no way for vfio to reject driver > binding at this point, BUG_ON() is triggered if a violation is > captured (kernel driver BOUND event on a group which already has some > devices assigned to userspace). Aside from the bad user experience > this opens a way for root userspace to crash the kernel, even in high > integrity configurations, by manipulating the module binding and > triggering the BUG_ON. > > This series solves this problem by making the user/kernel ownership a > core concept at the IOMMU layer. The driver core enforces kernel > ownership while drivers are bound and violations now result in a error > codes during probe, not BUG_ON failures. > > Patch partitions: > [PATCH 1-7]: Detect DMA ownership conflicts during driver binding; > [PATCH 8-10]: Add security context management for assigned devices; > [PATCH 11-14]: Various cleanups. > > This is also part one of three initial series for IOMMUFD: > * Move IOMMU Group security into the iommu layer > - Generic IOMMUFD implementation > - VFIO ability to consume IOMMUFD Thank you very much for your comments. A new version of this series has been posted here: https://lore.kernel.org/linux-iommu/20220218005521.172832-1-baolu.lu@linux.intel.com/ Best regards, baolu From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DDCDCC433F5 for ; Fri, 18 Feb 2022 01:09:27 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 5F26A83ED4; Fri, 18 Feb 2022 01:09:27 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nx5MfZHBB17r; Fri, 18 Feb 2022 01:09:23 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 4938283EC1; Fri, 18 Feb 2022 01:09:23 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E7DBCC0011; Fri, 18 Feb 2022 01:09:22 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id AA907C000B for ; Fri, 18 Feb 2022 01:09:21 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 84CEE83ECE for ; Fri, 18 Feb 2022 01:09:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HhcomBSDFP_G for ; Fri, 18 Feb 2022 01:09:20 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by smtp1.osuosl.org (Postfix) with ESMTPS id B7E5B83EC1 for ; Fri, 18 Feb 2022 01:09:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645146560; x=1676682560; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=i/uHlQnpqnYhs2UtoI5OgAOBiOeNbQTVCxOGakFU9Us=; b=iX8tY55fYyFjOty0vDgBP4E1h+DIpensVb3T6YomqUympybSPy5HwcU2 XHD5TwZZQmXsOUl3IU6gipo54C2tYNu4om3g4lTzIk6FRzIJzQ+KpkkOc g9e9iY3ulLERx8dJwCRqSeFpU/QkpThYPnKBPh5l4Dkwv/B3Gct09i967 gVD8dfcmd7/BweAXXtHsYDT9myWzP25mcTX+GgfGeA8g6EsWb4cC2Z4PZ yaOhrMNTocHDDNS/BbJcuYNsNSXBE9Y9O/p7KmX9ARPDnbUQH+baD0xBa CCK669QE0DFzqbwqOihi4dPmQF5rPBLzwKh08zYtlsWKgkTa+0r/BJEAm g==; X-IronPort-AV: E=McAfee;i="6200,9189,10261"; a="275615045" X-IronPort-AV: E=Sophos;i="5.88,377,1635231600"; d="scan'208";a="275615045" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2022 17:09:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,377,1635231600"; d="scan'208";a="682271178" Received: from allen-box.sh.intel.com (HELO [10.239.159.118]) ([10.239.159.118]) by fmsmga001.fm.intel.com with ESMTP; 17 Feb 2022 17:09:13 -0800 Message-ID: Date: Fri, 18 Feb 2022 09:07:51 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v5 00/14] Fix BUG_ON in vfio_iommu_group_notifier() Content-Language: en-US To: Greg Kroah-Hartman , Joerg Roedel , Alex Williamson , Bjorn Helgaas , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj References: <20220104015644.2294354-1-baolu.lu@linux.intel.com> From: Lu Baolu In-Reply-To: <20220104015644.2294354-1-baolu.lu@linux.intel.com> Cc: kvm@vger.kernel.org, rafael@kernel.org, David Airlie , linux-pci@vger.kernel.org, Thierry Reding , Diana Craciun , Dmitry Osipenko , Will Deacon , Stuart Yoder , Jonathan Hunter , Chaitanya Kulkarni , Dan Williams , Cornelia Huck , linux-kernel@vger.kernel.org, Li Yang , iommu@lists.linux-foundation.org, Jacob jun Pan , Daniel Vetter , Robin Murphy X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" On 1/4/22 9:56 AM, Lu Baolu wrote: > Hi folks, > > The iommu group is the minimal isolation boundary for DMA. Devices in > a group can access each other's MMIO registers via peer to peer DMA > and also need share the same I/O address space. > > Once the I/O address space is assigned to user control it is no longer > available to the dma_map* API, which effectively makes the DMA API > non-working. > > Second, userspace can use DMA initiated by a device that it controls > to access the MMIO spaces of other devices in the group. This allows > userspace to indirectly attack any kernel owned device and it's driver. > > Therefore groups must either be entirely under kernel control or > userspace control, never a mixture. Unfortunately some systems have > problems with the granularity of groups and there are a couple of > important exceptions: > > - pci_stub allows the admin to block driver binding on a device and > make it permanently shared with userspace. Since PCI stub does not > do DMA it is safe, however the admin must understand that using > pci_stub allows userspace to attack whatever device it was bound > it. > > - PCI bridges are sometimes included in groups. Typically PCI bridges > do not use DMA, and generally do not have MMIO regions. > > Generally any device that does not have any MMIO registers is a > possible candidate for an exception. > > Currently vfio adopts a workaround to detect violations of the above > restrictions by monitoring the driver core BOUND event, and hardwiring > the above exceptions. Since there is no way for vfio to reject driver > binding at this point, BUG_ON() is triggered if a violation is > captured (kernel driver BOUND event on a group which already has some > devices assigned to userspace). Aside from the bad user experience > this opens a way for root userspace to crash the kernel, even in high > integrity configurations, by manipulating the module binding and > triggering the BUG_ON. > > This series solves this problem by making the user/kernel ownership a > core concept at the IOMMU layer. The driver core enforces kernel > ownership while drivers are bound and violations now result in a error > codes during probe, not BUG_ON failures. > > Patch partitions: > [PATCH 1-7]: Detect DMA ownership conflicts during driver binding; > [PATCH 8-10]: Add security context management for assigned devices; > [PATCH 11-14]: Various cleanups. > > This is also part one of three initial series for IOMMUFD: > * Move IOMMU Group security into the iommu layer > - Generic IOMMUFD implementation > - VFIO ability to consume IOMMUFD Thank you very much for your comments. A new version of this series has been posted here: https://lore.kernel.org/linux-iommu/20220218005521.172832-1-baolu.lu@linux.intel.com/ Best regards, baolu _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu