Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp283392ybg; Wed, 10 Jun 2020 00:15:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWuo3lsKUrsR8pHfxEhkdzO14MKL9kBhppdV6Mlw4woLOTM0FqB7PdGYTs3c4imushldI9 X-Received: by 2002:a50:fd01:: with SMTP id i1mr1407206eds.32.1591773332236; Wed, 10 Jun 2020 00:15:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591773332; cv=none; d=google.com; s=arc-20160816; b=iB7ZFfnVGJ24lD+saIlDvtA7WTlgfFLyGqqBQkvIOUsvQ8ZW3NJX6PGO5bPQheeQlU wpdBnqVwTSNFKub7L/AOx9iq2XvB76IaJBC7rDWjjPzWYoqEeW1incgp8LKenhZZPD6M FHbE3wDTPUnKQOeEiNiUelsw0MxnMc15/h7usAqg2z+dMmrvzSw+hdJTYJjuRIr+VMbt qNdGthzS6LVfCU4w+HAVWkh9N0K1492wpYovY8vvcJ3DCdOvgnP+6OQdsj/xghwbv5AW 7YBixJd7GfdM/Dn85S3Om1M59w2x7Mojk+NUfIRBXFZactpZnqxf5ePPzZRVYtbpkEOy bgFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=r+l2Gk9j+IwRTPuGkd/szxX88BHaWpMfOiJfHyGe3fA=; b=qdLtGV83fSthdL94dXLN9OAi/26wIjXQwfTD1g7y5fo+fAbYLDSMQa5FdspGWfc0eC mAEFpUqpnx8G0ZFNMopfpjfViKozV1b9cVyyCzTo63DkJzPWr+vgSXQGvyWnCHNrlcAM 1lmgAEB0Nav3B0xaxGcDaaQDQktUIUCY1gGkE9b7xzQG01Xk/G6bUKJe/zlrD+jcGhyE gt/A/5XBt/EgEKTNANwEVTJf8q9Zf9Eth2cyMrKO+MrX8WfDYVQOIO9O14DWsqRInMeQ mzItvH2gkqojhnvBGRMW24cdz64jKqSFgaxkOz9ltKfm0unFfOtXuuaukw1Jfxvc91X6 rFSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="nyf/eaZL"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g11si6245982edk.96.2020.06.10.00.15.08; Wed, 10 Jun 2020 00:15:32 -0700 (PDT) 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=@kernel.org header.s=default header.b="nyf/eaZL"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726330AbgFJHMp (ORCPT + 99 others); Wed, 10 Jun 2020 03:12:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:52278 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726276AbgFJHMm (ORCPT ); Wed, 10 Jun 2020 03:12:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 32D712081A; Wed, 10 Jun 2020 07:12:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591773161; bh=pd2SzRJOzTRtTej8TfH3UhWrXB1jr/uVuRtkc+0eAOU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nyf/eaZLnteXhDufaX0guURN6YQMM5b4xLIKTqUyDX+XZpu7kzrS0c7MBd3ngO68k oAxc3ugpBuJAZ/sFm9TRa9PtPBCPFrvl6H/I+GdzF+zL3SDt5XEYjnYTmlTTQESjGM h/C2gY/gyXKnf02ev6qeBwVP9ZMYkbze0nAhUb7U= Date: Wed, 10 Jun 2020 09:12:39 +0200 From: Greg Kroah-Hartman To: Bjorn Helgaas Cc: Rajat Jain , Rajat Jain , "Raj, Ashok" , "Krishnakumar, Lalithambika" , Bjorn Helgaas , linux-pci , Mika Westerberg , Jean-Philippe Brucker , Prashant Malani , Benson Leung , Todd Broch , Alex Levin , Mattias Nissler , Zubin Mithra , Bernie Keany , Aaron Durbin , Diego Rivas , Duncan Laurie , Furquan Shaikh , Jesse Barnes , Christian Kellner , Alex Williamson , Joerg Roedel , Linux Kernel Mailing List Subject: Re: [RFC] Restrict the untrusted devices, to bind to only a set of "whitelisted" drivers Message-ID: <20200610071239.GC1923109@kroah.com> References: <20200607113632.GA49147@kroah.com> <20200609210400.GA1461839@bjorn-Precision-5520> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200609210400.GA1461839@bjorn-Precision-5520> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 09, 2020 at 04:04:00PM -0500, Bjorn Helgaas wrote: > On Sun, Jun 07, 2020 at 01:36:32PM +0200, Greg Kroah-Hartman wrote: > > > Your "problem" I think can be summed up a bit more concise: > > - you don't trust kernel drivers to be "secure" for untrusted > > devices > > - you only want to bind kernel drivers to "internal" devices > > automatically as you "trust" drivers in that situation. > > - you want to only bind specific kernel drivers that you somehow > > feel are "secure" to untrusted devices "outside" of a system > > when those devices are added to the system. > > > > Is that correct? > > > > If so, fine, you can do that today with the bind/unbind ability of > > drivers, right? After boot with your "trusted" drivers bound to > > "internal" devices, turn off autobind of drivers to devices and then > > manually bind them when you see new devices show up, as those "must" be > > from external devices (see the bind/unbind files that all drivers export > > for how to do this, and old lwn.net articles, this feature has been > > around for a very long time.) > > > > I know for USB you can do this, odds are PCI you can turn off > > autobinding as well, as I think this is a per-bus flag somewhere. If > > that's not exported to userspace, should be trivial to do so, should be > > somewere in the driver model already... > > > > Ah, yes, look at the "drivers_autoprobe" and "drivers_probe" files in > > sysfs for all busses. Do those not work for you? > > > > My other points are the fact that you don't want to put policy in the > > kernel, and I think that you can do everything you want in userspace > > today, except maybe the fact that trying to determine what is "inside" > > and "outside" is not always easy given that most hardware does not > > export this information properly, if at all. Go work with the firmware > > people on that issue please, that would be most helpful for everyone > > involved to get that finally straightened out. > > To sketch this out, my understanding of how this would work is: > > - Expose the PCI pdev->untrusted bit in sysfs. We don't expose this > today, but doing so would be trivial. I think I would prefer a > sysfs name like "external" so it's more descriptive and less of a > judgment. > > This comes from either the DT "external-facing" property or the > ACPI "ExternalFacingPort" property. Good idea, but as people have pointed out, even these don't always work so userspace will need to be able to override that somehow :( > - All devices present at boot are enumerated. Any statically built > drivers will bind to them before any userspace code runs. > > If you want to keep statically built drivers from binding, you'd > need to invent some mechanism so pci_driver_init() could clear > drivers_autoprobe after registering pci_bus_type. > > - Early userspace code prevents modular drivers from automatically > binding to PCI devices: > > echo 0 > /sys/bus/pci/drivers_autoprobe > > This prevents modular drivers from binding to all devices, whether > present at boot or hot-added. > > - Userspace code uses the sysfs "bind" file to control which drivers > are loaded and can bind to each device, e.g., > > echo 0000:02:00.0 > /sys/bus/pci/drivers/nvme/bind Seems good to me, and also matches what the current USB tools do for this type of thing. thanks, greg k-h