Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp60102pxa; Fri, 31 Jul 2020 06:33:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDlU6gMwHEDPtElbFe5VwBvtpt4bhUISdj2I/d/VmeXC6f1pKN75sxCoyWXwtU2BDSdSb1 X-Received: by 2002:a17:906:2a41:: with SMTP id k1mr4075780eje.300.1596202434995; Fri, 31 Jul 2020 06:33:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596202434; cv=none; d=google.com; s=arc-20160816; b=FSpRHoD/vxlU025KQZ8eDPFnOuf6OKSW7jg+llvE4mQBOgtHKs5rHMjnfhicZ0U+Vc uYMjgm5pYRirpnMLKWbewHIdnrUapY/7WTxVlS6I7tH//aSennGWDa4ZWZq1jraHQl7B zJznaMfZCawTX1EyCna22u/ChsvVjSas3ipiga7zEqysxvI0uAbju77cuy4eTNTNn7l1 Vi7fwejtkzRYE8URGF/YFlUBq1eV+eDM7e9Qv4FSZEbDMbcZH7FTeVwpXe/xPJlpB7bJ TTRdTMMxYOCgg6AaPJzgAEZZfnO0NIuboTpwZaur1rkpBK5CnsL00MrOZBoI9FnZSdib hxuQ== 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=YpxMyTk2r3GnTBHt2TPDZETDoC2HGIyixCcVqPLa94Y=; b=jzmqDcaiYEUNbcE3g8DeQJHHY34edUVe8vVRIeDRaaZBc0Mcf+xZ6qtap9eg/qV08l isLGTlWpl2tCCHWCbh/tcDrVvULlQtfp9815Q6yWwxJJ0uT8UV81xVDTbpDw4Hf3vvH4 Vv9HBuMlsJAoqoLLzVIjgfrMtG2e0Tco3D6N42cnd4nZl2w2Ur8i4JnH9dipaxTBDeGS hUEQnRgPa6GRi7zFMoH0/oaJWULFJfRMIzWHJJlsXQC8IGai2T98eCRwtjx1LKh7E81A xfENYgEoQdllDpm46f6tEvYjvfdUEhTORI5SDLdCiBsDk9Ked2Wz5P2TPQpJHP7Gnhy8 WZ1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eclypsium.com header.s=google header.b=NXEUkEfC; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=eclypsium.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k19si1361182ejc.710.2020.07.31.06.33.32; Fri, 31 Jul 2020 06:33:54 -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=@eclypsium.com header.s=google header.b=NXEUkEfC; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=eclypsium.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732232AbgGaNa4 (ORCPT + 99 others); Fri, 31 Jul 2020 09:30:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731517AbgGaNaz (ORCPT ); Fri, 31 Jul 2020 09:30:55 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96185C061574 for ; Fri, 31 Jul 2020 06:30:55 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id b79so28670825qkg.9 for ; Fri, 31 Jul 2020 06:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eclypsium.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=YpxMyTk2r3GnTBHt2TPDZETDoC2HGIyixCcVqPLa94Y=; b=NXEUkEfCBBy35pIvT5pu2hpSGbSIeSDNRDa0JpZ9mMOCqdkXuQ1wRmkHCRP0D0DKqS 6fujgXFXLeQFkV1mgSN9Xlm8aNbgtd9Td/+M0jktnlNPrVzVJ2mDVe3aYBD/SZ5cv5Ot wxM6Jhg7jgs9fbcLxildjk9+tuiUjF4gDAVmvaooTnLRJhA5fn8dz2wA5j4Y/x9h8duE 1leeBwJWRbSiNPlqJY1u826O0QInJZ+6qU+fI68X+/vsi7P5zo/lKSUH95zmeWzky/b0 xqT3xqiTe/VniBcP7ZKeDel0t/gc+LeoAXhNR1d6z9ZxbYn5oupQ2fy3+U1St2Xb2Qr3 fIiA== 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=YpxMyTk2r3GnTBHt2TPDZETDoC2HGIyixCcVqPLa94Y=; b=nOH6N/N/ttac/Uz2kaWFKSqdx/f0KIppFzW41b/xuiafBtCHGI6QTJY6Yv9cLKZFho 8huSxXT/aciL0mxcIhltmzdkHhs7IuBJfUPXrvGIrc1pDlc9LjSC35SYg7b7LQ0KqS4V 75aH/V5HtFxKeTiwTQkl36eWU8tpmINT6HZDsuDum6KGjgpWBlMeUGBcEsKN5VC7SqJG wLkdvF/imx/IUi0UPmoCvyDTaieOjLqiRnUDLwwT0pcPgRB6iMPUdwInWl/0Squ/5Fcc vBGiOnOE0hiSDjGuImNnUBLBpHiJbAhRo/D/+Twy0ql3/qQzIennyVr5+jOaAVBBXZ2c RWng== X-Gm-Message-State: AOAM533F1FX/qbnRK7TlMPxFLYqZuJeRUf5gUtX4OKZ0oFj4BaIcOYr7 8tBNZlLs8a7gJLakRWT1OY1viqGb36V40/6mQijAwQ== X-Received: by 2002:a37:b6c5:: with SMTP id g188mr3751641qkf.1.1596202254597; Fri, 31 Jul 2020 06:30:54 -0700 (PDT) MIME-Version: 1.0 References: <20200730214136.5534-1-daniel.gutson@eclypsium.com> <20200731070053.GC1518178@kroah.com> In-Reply-To: <20200731070053.GC1518178@kroah.com> From: Daniel Gutson Date: Fri, 31 Jul 2020 10:30:43 -0300 Message-ID: Subject: Re: [PATCH] Platform lockdown information in SYSFS To: Greg Kroah-Hartman Cc: Derek Kiernan , Tudor Ambarus , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Mika Westerberg , Arnd Bergmann , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, Richard Hughes , Alex Bazhaniuk 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 Fri, Jul 31, 2020 at 4:01 AM Greg Kroah-Hartman wrote: > > On Thu, Jul 30, 2020 at 06:41:36PM -0300, Daniel Gutson wrote: > > This patch exports information about the platform lockdown > > firmware configuration in the sysfs filesystem. > > In this initial patch, I include some configuration attributes > > for the system SPI chip. > > > > This initial version exports the BIOS Write Enable (bioswe), > > BIOS Lock Enable (ble), and the SMM Bios Write Protect (SMM_BWP) > > fields of the Bios Control register. The idea is to keep adding more > > flags, not only from the BC but also from other registers in following > > versions. > > > > The goal is that the attributes are avilable to fwupd when SecureBoot > > is turned on. > > > > The patch provides a new misc driver, as proposed in the previous patch, > > that provides a registration function for HW Driver devices to register > > class_attributes. > > In this case, the intel SPI flash chip (intel-spi) registers three > > class_attributes corresponding to the fields mentioned above. > > Better, but you are abusing sysfs (note, no CAPS) a lot here... > > > > > > Signed-off-by: Daniel Gutson > > --- > > .../ABI/stable/sysfs-class-platform-lockdown | 23 +++++++ > > MAINTAINERS | 7 +++ > > drivers/misc/Kconfig | 9 +++ > > drivers/misc/Makefile | 1 + > > drivers/misc/platform-lockdown-attrs.c | 57 +++++++++++++++++ > > drivers/mtd/spi-nor/controllers/Kconfig | 1 + > > .../mtd/spi-nor/controllers/intel-spi-pci.c | 49 +++++++++++++++ > > drivers/mtd/spi-nor/controllers/intel-spi.c | 62 +++++++++++++++++++ > > .../platform_data/platform-lockdown-attrs.h | 19 ++++++ > > 9 files changed, 228 insertions(+) > > create mode 100644 Documentation/ABI/stable/sysfs-class-platform-lockdown > > create mode 100644 drivers/misc/platform-lockdown-attrs.c > > create mode 100644 include/linux/platform_data/platform-lockdown-attrs.h > > > > diff --git a/Documentation/ABI/stable/sysfs-class-platform-lockdown b/Documentation/ABI/stable/sysfs-class-platform-lockdown > > new file mode 100644 > > index 000000000000..6034d6cbefac > > --- /dev/null > > +++ b/Documentation/ABI/stable/sysfs-class-platform-lockdown > > @@ -0,0 +1,23 @@ > > +What: /sys/class/platform-lockdown/bioswe > > +Date: July 2020 > > +KernelVersion: 5.8.0 > > +Contact: Daniel Gutson > > +Description: If the system firmware set BIOS Write Enable. > > + 0: writes disabled, 1: writes enabled. > > +Users: https://github.com/fwupd/fwupd > > + > > +What: /sys/class/platform-lockdown/ble > > +Date: July 2020 > > +KernelVersion: 5.8.0 > > +Contact: Daniel Gutson > > +Description: If the system firmware set Bios Lock Enable. > > + 0: SMM lock disabled, 1: SMM lock enabled. > > +Users: https://github.com/fwupd/fwupd > > + > > +What: /sys/class/platform-lockdown/smm_bwp > > +Date: July 2020 > > +KernelVersion: 5.8.0 > > +Contact: Daniel Gutson > > +Description: If the system firmware set SMM Bios Write Protect. > > + 0: writes disabled unless in SMM, 1: writes enabled. > > +Users: https://github.com/fwupd/fwupd > > diff --git a/MAINTAINERS b/MAINTAINERS > > index f0569cf304ca..771ed1693d28 100644 > > --- a/MAINTAINERS > > +++ b/MAINTAINERS > > @@ -13608,6 +13608,13 @@ S: Maintained > > F: Documentation/devicetree/bindings/iio/chemical/plantower,pms7003.yaml > > F: drivers/iio/chemical/pms7003.c > > > > +PLATFORM LOCKDOWN ATTRIBUTES MODULE > > +M: Daniel Gutson > > +S: Supported > > +F: Documentation/ABI/sysfs-class-platform-lockdown > > +F: drivers/misc/platform-lockdown-attrs.c > > +F: include/linux/platform_data/platform-lockdown-attrs.h > > + > > PLX DMA DRIVER > > M: Logan Gunthorpe > > S: Maintained > > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig > > index e1b1ba5e2b92..058d4ba3cefd 100644 > > --- a/drivers/misc/Kconfig > > +++ b/drivers/misc/Kconfig > > @@ -456,6 +456,15 @@ config PVPANIC > > a paravirtualized device provided by QEMU; it lets a virtual machine > > (guest) communicate panic events to the host. > > > > +config PLATFORM_LOCKDOWN_ATTRS > > + tristate "Platform lockdown information in the SYSFS" > > "Platform lockdown information for some hardware information displayed > in sysfs" ? > > > + depends on SYSFS > > + help > > + This kernel module is a helper driver to provide information about > > + platform lockdown settings and configuration. > > Is that what this really is? > > > + This module is used by other device drivers -such as the intel-spi- > > + to publish the information in /sys/class/platform-lockdown. > > + > > source "drivers/misc/c2port/Kconfig" > > source "drivers/misc/eeprom/Kconfig" > > source "drivers/misc/cb710/Kconfig" > > diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile > > index c7bd01ac6291..e29b45c564f9 100644 > > --- a/drivers/misc/Makefile > > +++ b/drivers/misc/Makefile > > @@ -57,3 +57,4 @@ obj-$(CONFIG_PVPANIC) += pvpanic.o > > obj-$(CONFIG_HABANA_AI) += habanalabs/ > > obj-$(CONFIG_UACCE) += uacce/ > > obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o > > +obj-$(CONFIG_PLATFORM_LOCKDOWN_ATTRS) += platform-lockdown-attrs.o > > diff --git a/drivers/misc/platform-lockdown-attrs.c b/drivers/misc/platform-lockdown-attrs.c > > new file mode 100644 > > index 000000000000..d08b3d895064 > > --- /dev/null > > +++ b/drivers/misc/platform-lockdown-attrs.c > > @@ -0,0 +1,57 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Platform lockdown attributes kernel module > > + * > > + * Copyright (C) 2020 Daniel Gutson > > + * Copyright (C) 2020 Eclypsium Inc. > > + */ > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +static struct class platform_lockdown_class = { > > + .name = "platform-lockdown", > > + .owner = THIS_MODULE, > > +}; > > + > > +int register_platform_lockdown_attribute( > > + struct class_attribute *lockdown_attribute) > > +{ > > + /* attempt to create the file: */ > > + return class_create_file(&platform_lockdown_class, > > + lockdown_attribute); > > +} > > +EXPORT_SYMBOL_GPL(register_platform_lockdown_attribute); > > nit, global symbols should put the noun first: > platform_lockdown_attribute_register() > > But, this all is not ok. > > You are trying to create/remove random sysfs files that end up in a > single class. What you want to do is create a device that is associated > with this class, and make that device a child of the device you are > registering these attributes for. > > Think of this as an input device. You don't put the random input > attributes all in one place, you create a new device that represents the > input interface and register that. Then userspace can iterate over all > devices that are of the input class and see the individual attributes of > them. So I create the child device. And these attributes, will be class attributes or device attributes of the child device? > > Make more sense? > > So you need something like: > platform_lockdown_device_create() > > that returns a 'struct device' that is associated with the new class > device. > > thanks, > > greg k-h -- Daniel Gutson Argentina Site Director Enginieering Director Eclypsium Below The Surface: Get the latest threat research and insights on firmware and supply chain threats from the research team at Eclypsium. https://eclypsium.com/research/#threatreport