Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp58634pxb; Tue, 12 Apr 2022 16:45:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeBrfp7zoqojE5gq0rhRuc0w60zkcebu2e/Sh01Rv1/fLrX6LOYsKWBukLgEoRY//0aFut X-Received: by 2002:a17:90a:6501:b0:1ca:a7df:695c with SMTP id i1-20020a17090a650100b001caa7df695cmr7829238pjj.152.1649807134567; Tue, 12 Apr 2022 16:45:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649807134; cv=none; d=google.com; s=arc-20160816; b=rqYPEOowTnt/nzp3jxl5mUlU0BpgnSiug0GRdHVsB5ZxnQlEKG5pF9zXYDUgMWWjsq by3iioDgdbXJVSZffQecgignHyOIr/gdOyrTFYDc6rSUSLOtlMT/sNO0BtBhlImow24i C3lABoFO3JZGySRMKRpkIcyE2HR1n3Dt8kOXiA5mPJktQOrh2ec0bYdn11QuU7fPv3YF BoJUguyxv7Y62mM/Mv2EwAyV406V5o2cEir/QUFeRaqJ2yy5DXyXyX/H5bk8mt9nYrEg N1aUJOhH4XDf6jUYtqLq7zqD8Zuw4raKFwMF7NzEgOXH6yOuRr6ivPhYEFJvYZXMVJ5J 2rQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=cti+QiKgUA7/KRiupC2WZhWpfVA+aNRoGYHgdqzPkFM=; b=MvZce+hyuC4Q9xqDwjwKfjYb7IJYFBrrnSGGqXrUtcp4JSkGLPuJfZ2mJll0svFizA w1r9JktZqp8wUPIGXF4iICSsV7VzropYrMs4LpBHiOKpBbjYpb8ikwHlup/cKqLlr07V qHntBo32+kCyfE3JFvKqumrxk0H4akyi/uuquZMda0dBuYQ0bzI+51e50SU17J0Li+ji C1wMcoKLl6zdH1X06IYYw71wxRL1VJnIrqEm84g8F7fcjZ4evEdv1EDOocKwrvmJKv5N 6EEysrO0Hl0oe2P+pNEPFlvhO6ucdMMF2edROCl2NpCunAXhOuoql8sEKIMsOYDMW8JY kg4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ivrKqzVE; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id u4-20020a170902bf4400b00153b2d16499si12162118pls.161.2022.04.12.16.45.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 16:45:34 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ivrKqzVE; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C61721D2055; Tue, 12 Apr 2022 14:37:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343943AbiDLLJm (ORCPT + 99 others); Tue, 12 Apr 2022 07:09:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354093AbiDLLFC (ORCPT ); Tue, 12 Apr 2022 07:05:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64C7B26127; Tue, 12 Apr 2022 02:57:06 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 118B5B81B4A; Tue, 12 Apr 2022 09:57:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3359CC385A5; Tue, 12 Apr 2022 09:57:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649757423; bh=b7hWroRVFGxdaPJh2LV7JuwotH1TDJUBX9W/+RIyoWk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ivrKqzVE0io1e5T883EsAyQIP5ZlSqOfqIS9Vs+6TI9cfW8XWjpwTFTKnJjSk01DB L333L8+Gs6e6zG85yvY29ewnDdFlTBDZoxsDbm8EffSN1jdcherhAeU2KkIaautR2C M+gsb8BuPXk4RCvRmBSfP/HdH+qbHycW1kLcQluY= Date: Tue, 12 Apr 2022 11:57:00 +0200 From: Greg Kroah-Hartman To: David Stevens Cc: Pali =?iso-8859-1?Q?Roh=E1r?= , linux-pci@vger.kernel.org, Bjorn Helgaas , linux-kernel@vger.kernel.org Subject: Re: [RFC] PCI: sysfs: add bypass for config read admin check Message-ID: References: <20220406071131.2930035-1-stevensd@google.com> <20220406131300.7pgdcpdhexwvczsb@pali> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 12, 2022 at 04:51:06PM +0900, David Stevens wrote: > On Wed, Apr 6, 2022 at 10:13 PM Pali Roh?r wrote: > > > > On Wednesday 06 April 2022 10:09:33 Greg Kroah-Hartman wrote: > > > On Wed, Apr 06, 2022 at 04:11:31PM +0900, David Stevens wrote: > > > > From: David Stevens > > > > > > > > Add a moduleparam that can be set to bypass the check that limits users > > > > without CAP_SYS_ADMIN to only being able to read the first 64 bytes of > > > > the config space. This allows systems without problematic hardware to be > > > > configured to allow users without CAP_SYS_ADMIN to read PCI > > > > capabilities. > > > > > > > > Signed-off-by: David Stevens > > > > --- > > > > drivers/pci/pci-sysfs.c | 10 +++++++++- > > > > 1 file changed, 9 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c > > > > index 602f0fb0b007..162423b3c052 100644 > > > > --- a/drivers/pci/pci-sysfs.c > > > > +++ b/drivers/pci/pci-sysfs.c > > > > @@ -28,10 +28,17 @@ > > > > #include > > > > #include > > > > #include > > > > +#include > > > > #include "pci.h" > > > > > > > > static int sysfs_initialized; /* = 0 */ > > > > > > > > +static bool allow_unsafe_config_reads; > > > > +module_param_named(allow_unsafe_config_reads, > > > > + allow_unsafe_config_reads, bool, 0644); > > > > +MODULE_PARM_DESC(allow_unsafe_config_reads, > > > > + "Enable full read access to config space without CAP_SYS_ADMIN."); > > > > > > No, this is not the 1990's, please do not add system-wide module > > > parameters like this. Especially ones that circumvent security > > > protections. > > > > > > Also, where did you document this new option? > > > > > > Why not just add this to a LSM instead? > > > > > > > /* show configuration fields */ > > > > #define pci_config_attr(field, format_string) \ > > > > static ssize_t \ > > > > @@ -696,7 +703,8 @@ static ssize_t pci_read_config(struct file *filp, struct kobject *kobj, > > > > u8 *data = (u8 *) buf; > > > > > > > > /* Several chips lock up trying to read undefined config space */ > > > > - if (file_ns_capable(filp, &init_user_ns, CAP_SYS_ADMIN)) > > > > + if (allow_unsafe_config_reads || > > > > + file_ns_capable(filp, &init_user_ns, CAP_SYS_ADMIN)) > > > > > > This feels really dangerous. What benifit are you getting here by > > > allowing an unpriviliged user to read this information? > > > > Hello! This is really dangerous. > > > > Nowadays operating systems are in progress to completely disallow PCI > > config space access from userspace. So doing opposite thing and even > > enable it for unprivileged users in Linux is hazard. > > > > For example NT kernel in Windows 11 already completely disallowed access > > to PCI config space from userspace unless NT kernel is booted in mode > > for local debugging with disabled UEFI secure boot. And access in this > > case is only for highly privileged processes (debug privilege in access > > token). > > > > So... should not we move into same direction like other operating system > > and start disallowing access to PCI config space from userspace > > completely too? For example when kernel lockdown feature is enabled? > > > > In PCI config space of some devices are stored also non-PCI registers > > and accessing them was not really mean for userspace and for sure not > > for unprivileged users. On AMD x86 platforms is into PCI config space of > > some device mapped for example CPU MSR registers (at fixed offset, after > > linked listed of capabilities). Probably in Intel x86 is something > > similar too. On Synopsis Designware based PCIe HW is into PCI config > > space of Root Port mapped large range of IP configuration registers. > > > > So "This allows systems without problematic hardware" means that such > > system must be non-AMD, non-Designware and probably also non-Intel. > > It's interesting to hear that what seems to have been added 18 years > ago as a safeguard against faulty hardware (i.e. "Several chips lock > up trying to read undefined config space") has become a load bearing > security check. Evolution is a wonderful thing :) Security models are different today than they used to be back then, and we still have broken hardware that will lock up with accesses like this. > I guess because that check is there, it wasn't worth > adding a LOCKDOWN_PCI_ACCESS check to pci_read_config? That's up to the lockdown people to add, if they so desire. > Regardless, I've found that with a bit of work in userspace, vfio is > sufficient for my use case. That sounds crazy, and probably wrong. Good luck! :) greg k-h