Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp100660ybg; Tue, 9 Jun 2020 17:35:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyMv4XJN+xxDXHDAWHuxXbU1uVllfdr+Fq5j6/O9cS6kgp19HgVkDjm57A55RjY2+HX0Bd X-Received: by 2002:a05:6402:1750:: with SMTP id v16mr320216edx.137.1591749305509; Tue, 09 Jun 2020 17:35:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591749305; cv=none; d=google.com; s=arc-20160816; b=GEVm/y0bISF3qMDPyc1la3gFtRY5a0BZzzMei3ZnBOvu8DoUHb4lLMKRktFXriY1v0 O7pIDVKSFjvqUZkEt1lChbTelFYRcOxc7qX1tO/sn7OjGIT8cYuRoRjHc2o5qSOTj2eg eNFC8J1RKW7CCuvjgMFk+/l1J/y126gc0E4vWW6NmgtaKUXDD3t234qnvAZS0g5kxl/s NCgtp0Jmr+YWkx7z4grJEXzcFCNJLydq+nceqstvU8WG19rHoY1vEHo2IvX9tOqNAlca wb/FVzcfBYa7rYr18kEzfOfkZjQJfIatuh/sxyM4rgbhKI7rmIkUPJ3MLQBHDrLhn77T AHcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=fufpFexVpmLTY4L8tFo3Vjk8lnR9s+NHiNpeUysolls=; b=kDLgrrDQ8F9EiG07Xj+Wfp5hLdSBfie4xilf7elD5xiIljZUJYYF7+rwFueuzaWptC mWG+4epH8vMf93+x5DYgXC1Ihue0SV4271lgOEDsUh+95D8JS5kgbJqFuZqMQUZKqdWA jDpctvQwmDI9wHoEMn9SKUDZ2xsFEhMdpvhn6Y/lHnjiwZewsO3vngmYxGHtueQEgDwk YVvPXKX0Q0y2RO6SSj44NtimNbdrSmO6Ei55EPa127vpxwjpCT+ZjnXdhNeLhORGRnHn iXVqMSYxIRhb3gwPj7bqAvygiFrZZVw4lJzmNjsQFcqeR+agUDvu8tZzojBf+TVfOq35 auYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ul3Kn7oE; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bf15si12367394edb.553.2020.06.09.17.34.43; Tue, 09 Jun 2020 17:35:05 -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=@google.com header.s=20161025 header.b=Ul3Kn7oE; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726068AbgFJAa6 (ORCPT + 99 others); Tue, 9 Jun 2020 20:30:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725948AbgFJAa4 (ORCPT ); Tue, 9 Jun 2020 20:30:56 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 011F0C03E96B for ; Tue, 9 Jun 2020 17:30:55 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id q19so314664lji.2 for ; Tue, 09 Jun 2020 17:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fufpFexVpmLTY4L8tFo3Vjk8lnR9s+NHiNpeUysolls=; b=Ul3Kn7oEjJ+TiA2pqfTe1kLWo8haWQ4EdIrWEOoLUcZqB1v5+Etym1PpbRykwdrFc/ iAvZiMia8BEQtCI23nGFox9x3pJ32ft7p7v+yGJpIsZylauMYMjm1bdqrxecJ+Bh2w7L xqjrS5+XDVplaBXmaXgQk+n1G3DRidRN6A2ZW5mnYdD6v2M6D86Us+cjITRGrKA+fcVQ qTwFZt6IHzcPFiyA1cnfFWD2sNzy1192NJEDLvc4U3gj6Rphyb5WtY0cDMjUBhSoxH8D nZq+FsEwWFKRvGEtLNV5LwvLDS8Fi/wSy7sK5fSVwveYFysFLoQNutyCfy8hjMCQh9R9 0eaw== 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=fufpFexVpmLTY4L8tFo3Vjk8lnR9s+NHiNpeUysolls=; b=T0EkajgnHPWMfNo/TLJR2JYrh3CRMisnbUTzlxRRbyCKoElL846bjxg3ScsFBf/IVO g+4k7p6+Le7DTTdZsusAe5tM2HfJ0Oz5nsaCXbHiuk6KFrXhQ+WhUzAa3T3YtW8nREe8 Z755YeJDVEdh5DOX5cGGH9Jf4Zg9q8lgVQwCFi0I47hq7kdOn/GVxFlu5kG1ibxxkfpC HK/e/QflXIcXJo0UdXDsjl0S5xRPyyREQLkO1nm4chJmDyLvnrD46MvgT+U6omwRLgz3 3Z1yLE1xYFv0RsidcoCOG6uT2rfGT+zOjeeDeDMaSUX3i0iZIcGY3hPNqfX0a1VTJWdA S86g== X-Gm-Message-State: AOAM532TQly6Aih2IkcvRamGieG0ykXPUGAjOdombuwt4aV3TKZlF1Vn +ycwW/+S3++vPg1psMnGUhJp7/eebEvMYFaU3A7XLg== X-Received: by 2002:a05:651c:1199:: with SMTP id w25mr391105ljo.301.1591749052049; Tue, 09 Jun 2020 17:30:52 -0700 (PDT) MIME-Version: 1.0 References: <20200610000400.GA1473845@bjorn-Precision-5520> In-Reply-To: <20200610000400.GA1473845@bjorn-Precision-5520> From: Rajat Jain Date: Tue, 9 Jun 2020 17:30:13 -0700 Message-ID: Subject: Re: [RFC] Restrict the untrusted devices, to bind to only a set of "whitelisted" drivers To: Bjorn Helgaas Cc: Greg Kroah-Hartman , 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 9, 2020 at 5:04 PM Bjorn Helgaas wrote: > > On Tue, Jun 09, 2020 at 04:23:54PM -0700, Rajat Jain wrote: > > Hi Bjorn, > > > > Thanks for sending out the summary, I was about to send it out but got lazy. > > > > On Tue, Jun 9, 2020 at 2:04 PM 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. > > > > Yes. I think we should probably semantically differentiate between > > "external" and "external facing" devices. Root ports and downstream > > ports can be "external facing" but are actually internal devices. > > Anything below an "external facing" device is "external". So the sysfs > > attribute "external" should be set only for devices that are truly > > external. > > Good point; we (maybe you? :)) should fix that edge case. Sure, happy to. I will start a fresh conversation about that (in a separate thread). > > > Just a suggestion: Do you think an enum attribute may be better > > instead, whose values could be "internal" / "external" / > > "external-facing" in case need arises later to distinguish between > > them? > > I don't see the need for an enum yet. Maybe we should add that > if/when we do need it? Sure, no problems. (I just wanted to slip the thought into the conversation as UAPI is hard to change later). > > > > - Early userspace code prevents modular drivers from automatically > > > binding to PCI devices: > > > > > > echo 0 > /sys/bus/pci/drivers_autoprobe > > > > Yes. > > I believe this setting will apply it equally to both modular and > > statically linked drivers? > > Yes. The test is in bus_probe_device(), and it does the same for both > modular and statically linked drivers. > > But for statically linked drivers, it only prevents them from binding > to *hot-added* devices. They will claim devices present at boot even > before userspace code can run. Yes, understood. > > > The one thing that still needs more thought is how about the > > "pcieport" driver that enumerates the PCI bridges. I'm unsure if it > > needs to be whitelisted for further enumeration downstream. What do > > you think? > > The pcieport driver is required for AER, PCIe native hotplug, PME, > etc., and it cannot be a module, so the whitelist wouldn't apply to > it. Not that I see the need, but slight clarification needed just to make sure I understand it clearly: Since pcieport driver is statically compiled in, AER, pciehp, PME, DPC etc will always be enabled for devices plugged in during boot. But I can still choose to choose to allow or deny for devices added *after boot* using the whitelist, right? Also, denying pcieport driver for hot-added PCIe bridges only disables these pcieport services on those bridges, but device enumeration further downstream those bridges is not an issue? > I assume you need hotplug support, so you would have pcieport > enabled and built in statically. > > If you're using ACPI hotplug, that doesn't require pcieport. Thank you, this was indeed a long and useful thread :-) Best Regards, Rajat