Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp610659ybx; Wed, 6 Nov 2019 23:42:36 -0800 (PST) X-Google-Smtp-Source: APXvYqzOMyQxMJQDoIBALien2hYcx68dD7Lb4OpxsrtRDkYBuPPWyNDaUtB7ou0+bqYcITmxUEek X-Received: by 2002:a50:cd14:: with SMTP id z20mr2001361edi.226.1573112556641; Wed, 06 Nov 2019 23:42:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573112556; cv=none; d=google.com; s=arc-20160816; b=IVMRaFa0VWtEOwJfZ+Nkso1N57I2JSpw0ZRqMENXXtAqLTT0nFbXsFP6myqdxkEfwa lniD86zh/XyW7iwvQh1EptmNY6mEq+kDko4d7ijfpIdEs0ZveEI9/eSmD6Cz8YrW4rwn PWudr56K4KeN4tUB9j36916MhKBSOFqXVwc8zXQvOxJ29C1h1R89MPujQCF510NMLtBk CdH1U1UwTTMFU/5MXWYx0on/TJy2I87wfd7aQwrPCt5uAzH6lNSEXQZeW4HRdCIceyzM oYiTQmfqSLFZGq5uAX/tk9OROBjBTNiiu0D/K6NvQr94iSC7mhJ+OQuLAARY3ZOlI5io 62LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=W3S3obImohaKpPWpIep8GHMvBRfvgY3Ifax+xRIz6sk=; b=OCNED27yztb+HFoZyUhrK+j0rh59WnBs2GrDd3EPM/ELyLDsDMb2z8MF7J/+nx1Er3 kYPHeI9obdzbweeG7HdIoS3+weZcjMQlD0KUUMK+jb7gsOlpd2kJ0vUDFv+MG86C4j56 TSe3TYpXjKg+POGjJlxe6waztz7gVZYaIemrFUXt4dAv72vtTH1hFWK+4lp3eThDraIb 7g1EJJfehUQ9qNkJ/Cjq0ZPsciC5DXVypTR0D482eXfVFhH6ShAh/pV2TncnhCLYgE37 60TCVk4oh+hBLE/w+0W3NqYocsu/Ddd9E38BYm4n/7Hu2ilyXpzMUpOGbEwrlFbhYrZm Rwag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VIsH2seR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e10si928469ejq.413.2019.11.06.23.42.13; Wed, 06 Nov 2019 23:42:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VIsH2seR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727142AbfKGHkc (ORCPT + 99 others); Thu, 7 Nov 2019 02:40:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:59050 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726498AbfKGHkc (ORCPT ); Thu, 7 Nov 2019 02:40:32 -0500 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 89A1F21882; Thu, 7 Nov 2019 07:40:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573112431; bh=2BS/rZTDi9unuwVB4ZB/ZFB0VRPqy6bNAF0+4AEjkB4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VIsH2seRUopDCpGxze0tP8nLOavOd8Olsk/SzRo+wyGTV878I/91nbOenJQnfGE21 8qvEcbbZyqSAIPrJ0WqpT2v8eD0nzmQAOtNsa5ALw5lU/y36328yxfz6BZPVx74Qyl hLDwB+7OeuYNFgnYzDQGpQOb+qyBhGZA/PhBktqM= Date: Thu, 7 Nov 2019 08:40:28 +0100 From: Greg Kroah-Hartman To: Eric Richter Cc: linuxppc-dev@ozlabs.org, linux-efi@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Ard Biesheuvel , Jeremy Kerr , Matthew Garret , Mimi Zohar , Claudio Carvalho , George Wilson , Elaine Palmer , Oliver O'Halloran , Nayna Jain Subject: Re: [PATCH v7 2/4] powerpc: expose secure variables to userspace via sysfs Message-ID: <20191107074028.GA1118867@kroah.com> References: <20191107042205.13710-1-erichte@linux.ibm.com> <20191107042205.13710-3-erichte@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191107042205.13710-3-erichte@linux.ibm.com> User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 06, 2019 at 10:22:03PM -0600, Eric Richter wrote: > From: Nayna Jain > > PowerNV secure variables, which store the keys used for OS kernel > verification, are managed by the firmware. These secure variables need to > be accessed by the userspace for addition/deletion of the certificates. > > This patch adds the sysfs interface to expose secure variables for PowerNV > secureboot. The users shall use this interface for manipulating > the keys stored in the secure variables. > > Signed-off-by: Nayna Jain > Reviewed-by: Greg Kroah-Hartman > Signed-off-by: Eric Richter > --- > Documentation/ABI/testing/sysfs-secvar | 46 +++++ > arch/powerpc/Kconfig | 11 ++ > arch/powerpc/kernel/Makefile | 1 + > arch/powerpc/kernel/secvar-sysfs.c | 247 +++++++++++++++++++++++++ > 4 files changed, 305 insertions(+) > create mode 100644 Documentation/ABI/testing/sysfs-secvar > create mode 100644 arch/powerpc/kernel/secvar-sysfs.c > > diff --git a/Documentation/ABI/testing/sysfs-secvar b/Documentation/ABI/testing/sysfs-secvar > new file mode 100644 > index 000000000000..911b89cc6957 > --- /dev/null > +++ b/Documentation/ABI/testing/sysfs-secvar > @@ -0,0 +1,46 @@ > +What: /sys/firmware/secvar > +Date: August 2019 > +Contact: Nayna Jain > +Description: This directory is created if the POWER firmware supports OS > + secureboot, thereby secure variables. It exposes interface > + for reading/writing the secure variables > + > +What: /sys/firmware/secvar/vars > +Date: August 2019 > +Contact: Nayna Jain > +Description: This directory lists all the secure variables that are supported > + by the firmware. > + > +What: /sys/firmware/secvar/backend > +Date: August 2019 > +Contact: Nayna Jain > +Description: A string indicating which backend is in use by the firmware. > + This determines the format of the variable and the accepted > + format of variable updates. > + > +What: /sys/firmware/secvar/vars/ > +Date: August 2019 > +Contact: Nayna Jain > +Description: Each secure variable is represented as a directory named as > + . The variable name is unique and is in ASCII > + representation. The data and size can be determined by reading > + their respective attribute files. > + > +What: /sys/firmware/secvar/vars//size > +Date: August 2019 > +Contact: Nayna Jain > +Description: An integer representation of the size of the content of the > + variable. In other words, it represents the size of the data. > + > +What: /sys/firmware/secvar/vars//data > +Date: August 2019 > +Contact: Nayna Jain h > +Description: A read-only file containing the value of the variable. The size > + of the file represents the maximum size of the variable data. > + > +What: /sys/firmware/secvar/vars//update > +Date: August 2019 > +Contact: Nayna Jain > +Description: A write-only file that is used to submit the new value for the > + variable. The size of the file represents the maximum size of > + the variable data that can be written. > diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig > index c795039bdc73..cabc091f3fe1 100644 > --- a/arch/powerpc/Kconfig > +++ b/arch/powerpc/Kconfig > @@ -945,6 +945,17 @@ config PPC_SECURE_BOOT > to enable OS secure boot on systems that have firmware support for > it. If in doubt say N. > > +config PPC_SECVAR_SYSFS > + bool "Enable sysfs interface for POWER secure variables" > + default y > + depends on PPC_SECURE_BOOT > + depends on SYSFS > + help > + POWER secure variables are managed and controlled by firmware. > + These variables are exposed to userspace via sysfs to enable > + read/write operations on these variables. Say Y if you have > + secure boot enabled and want to expose variables to userspace. > + > endmenu > > config ISA_DMA_API > diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile > index 3cf26427334f..b216e9f316ee 100644 > --- a/arch/powerpc/kernel/Makefile > +++ b/arch/powerpc/kernel/Makefile > @@ -162,6 +162,7 @@ obj-y += ucall.o > endif > > obj-$(CONFIG_PPC_SECURE_BOOT) += secure_boot.o ima_arch.o secvar-ops.o > +obj-$(CONFIG_PPC_SECVAR_SYSFS) += secvar-sysfs.o > > # Disable GCOV, KCOV & sanitizers in odd or sensitive code > GCOV_PROFILE_prom_init.o := n > diff --git a/arch/powerpc/kernel/secvar-sysfs.c b/arch/powerpc/kernel/secvar-sysfs.c > new file mode 100644 > index 000000000000..a3ba58ee4285 > --- /dev/null > +++ b/arch/powerpc/kernel/secvar-sysfs.c > @@ -0,0 +1,247 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Copyright (C) 2019 IBM Corporation > + * > + * This code exposes secure variables to user via sysfs > + */ > + > +#define pr_fmt(fmt) "secvar-sysfs: "fmt > + > +#include > +#include > +#include > +#include > +#include > + > +#define NAME_MAX_SIZE 1024 > + > +static struct kobject *secvar_kobj; > +static struct kset *secvar_kset; > + > +static ssize_t backend_show(struct kobject *kobj, struct kobj_attribute *attr, > + char *buf) > +{ > + ssize_t ret = 0; > + struct device_node *node; > + const char *compatible; > + > + node = of_find_node_by_name(NULL, "secvar"); > + if (!of_device_is_available(node)) > + return -ENODEV; > + > + ret = of_property_read_string(node, "compatible", &compatible); > + if (ret) > + return ret; > + > + ret = sprintf(buf, "%s\n", compatible); > + > + of_node_put(node); > + > + return ret; > +} > + > + > +static ssize_t size_show(struct kobject *kobj, struct kobj_attribute *attr, > + char *buf) > +{ > + uint64_t dsize; > + int rc; > + > + rc = secvar_ops->get(kobj->name, strlen(kobj->name) + 1, NULL, &dsize); > + if (rc) { > + pr_err("Error retrieving variable size %d\n", rc); For this, and the other errors in the show/store functions, you might want to print the kobject name as well, so that userspace has a hint as to what variable is the one having problems. thanks, greg k-h