powerpc/pseries: add support for local secure storage called Platform KeyStore(PKS)
Subsystems (4)
v2 cover powerpc/pseries: add support for local secure storage called Platform KeyStore(PKS)
PowerVM provides an isolated Platform KeyStore(PKS)[1] storage allocation for each partition(LPAR) with individually managed access controls to store sensitive information securely. Linux Kernel can access this storage by interfacing with hypervisor using a new set of hypervisor calls.
PowerVM guest secure boot feature intend to use Platform KeyStore for the purpose of storing public keys. Secure boot requires public keys to be able to verify the grub and boot kernel. To allow authenticated
manipulation of keys, it supports variables to store key authorities
- PK/KEK. Other variables are used to store code signing keys - db/grubdb. It also supports denied list to disallow booting even if signed with valid key. This is done via denied list database - dbx or sbat. These variables would be stored in PKS, and are managed and controlled by firmware.
The purpose of this patchset is to add userspace interface to manage these variables.
For v1[2] version, we received following feedback
"Ok, this is like the 3rd or 4th different platform-specific proposal for this type of functionality. I think we need to give up on platform-specific user/kernel apis on this (random sysfs/securityfs files scattered around the tree), and come up with a standard place for all of this."
Currently, OpenPOWER exposes variables via sysfs, while EFI platforms have used sysfs and then moved to their own efivarfs filesystem. Recently, coco feature is using securityfs to expose their secrets. All of these environments are different both syntactically and semantically.
securityfs is meant for linux security subsystems to expose policies/logs or any other information, and do not interact with firmware for managing these variables. However, there are various firmware security features which expose their variables for user management via kernel as discussed above. There is currently no single place to expose these variables. Different platforms use sysfs/platform specific filesystem(efivarfs)/securityfs interface as find appropriate. This has resulted in interfaces scattered around the tree.
This resulted in demand of a need for a common single place for new platform interfaces to expose their variables for firmware security features. This would simplify the interface for users of these platforms. This patchset proposes firmware security filesystem(fwsecurityfs). Any platform can expose the variables which are required by firmware security features via this interface. Going forward, this would give a common place for exposing variables managed by firmware while still allowing platforms to implement their own underlying semantics.
This design consists of two parts:
1. firmware security filesystem(fwsecurityfs) that provides platforms with APIs to create their own underlying directory and file structure. It is recommended to establish a well known mount point:
i.e. /sys/firmware/security/
2. platform specific implementation for these variables which implements underlying semantics. Platforms can expose their variables as files allowing read/write/add/delete operations by defining their own inode and file operations.
This patchset defines:
1. pseries driver to access LPAR Platform Key Store(PLPKS)
2. firmware security filesystem named fwsecurityfs
3. Interface to expose secure variables stored in LPAR PKS via fwsecurityfs
[1] https://community.ibm.com/community/user/power/blogs/chris-engel1/2020/11/20/powervm-introduces-the-platform-keystore
[2] https://lore.kernel.org/linuxppc-dev/[email protected]/
Changelog:
v1:
* Defined unified interface(firmware security filesystem) for all platforms to expose their variables used for security features.
* Expose secvars using firmware security fileystem.
* Renamed PKS driver to PLPKS to avoid naming conflict as mentioned by Dave Hanson.
Nayna Jain (3):
powerpc/pseries: define driver for Platform KeyStore
fs: define a firmware security filesystem named fwsecurityfs powerpc/pseries: expose authenticated variables stored in LPAR PKS
arch/powerpc/include/asm/hvcall.h | 12 +- arch/powerpc/include/asm/plpks.h | 92 ++++ arch/powerpc/platforms/pseries/Kconfig | 27 + arch/powerpc/platforms/pseries/Makefile | 2 + arch/powerpc/platforms/pseries/plpks/Makefile | 9 + .../pseries/plpks/fwsecurityfs_arch.c | 16 + .../platforms/pseries/plpks/internal.h | 18 + arch/powerpc/platforms/pseries/plpks/plpks.c | 517 ++++++++++++++++++ .../powerpc/platforms/pseries/plpks/secvars.c | 239 ++++++++ fs/Kconfig | 1 + fs/Makefile | 1 + fs/fwsecurityfs/Kconfig | 14 + fs/fwsecurityfs/Makefile | 10 + fs/fwsecurityfs/inode.c | 159 ++++++ fs/fwsecurityfs/internal.h | 13 + fs/fwsecurityfs/super.c | 154 ++++++ include/linux/fwsecurityfs.h | 33 ++ include/uapi/linux/magic.h | 1 + 18 files changed, 1317 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/include/asm/plpks.h create mode 100644 arch/powerpc/platforms/pseries/plpks/Makefile create mode 100644 arch/powerpc/platforms/pseries/plpks/fwsecurityfs_arch.c create mode 100644 arch/powerpc/platforms/pseries/plpks/internal.h create mode 100644 arch/powerpc/platforms/pseries/plpks/plpks.c create mode 100644 arch/powerpc/platforms/pseries/plpks/secvars.c create mode 100644 fs/fwsecurityfs/Kconfig create mode 100644 fs/fwsecurityfs/Makefile create mode 100644 fs/fwsecurityfs/inode.c create mode 100644 fs/fwsecurityfs/internal.h create mode 100644 fs/fwsecurityfs/super.c create mode 100644 include/linux/fwsecurityfs.h
Signature · 1 line
2.27.0
RFC PATCH v2 1/3 powerpc/pseries: define driver for Platform KeyStore
PowerVM provides an isolated Platform Keystore(PKS) storage allocation for each LPAR with individually managed access controls to store sensitive information securely. It provides a new set of hypervisor calls for Linux kernel to access PKS storage.
Define PLPKS driver using H_CALL interface to access PKS storage.
--- arch/powerpc/include/asm/hvcall.h | 12 +- arch/powerpc/include/asm/plpks.h | 92 ++++ arch/powerpc/platforms/pseries/Kconfig | 10 + arch/powerpc/platforms/pseries/Makefile | 2 + arch/powerpc/platforms/pseries/plpks/Makefile | 7 + arch/powerpc/platforms/pseries/plpks/plpks.c | 517 ++++++++++++++++++ 6 files changed, 639 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/include/asm/plpks.h create mode 100644 arch/powerpc/platforms/pseries/plpks/Makefile create mode 100644 arch/powerpc/platforms/pseries/plpks/plpks.c
arch/powerpc/include/asm/hvcall.h +11 -1
@@ -97,6 +97,7 @@#define H_OP_MODE -73#define H_COP_HW -74#define H_STATE -75 +#define H_IN_USE -77#define H_UNSUPPORTED_FLAG_START -256#define H_UNSUPPORTED_FLAG_END -511#define H_MULTI_THREADS_ACTIVE -9005
@@ -321,10 +322,19 @@#define H_SCM_UNBIND_ALL 0x3FC#define H_SCM_HEALTH 0x400#define H_SCM_PERFORMANCE_STATS 0x418 +#define H_PKS_GET_CONFIG 0x41C +#define H_PKS_SET_PASSWORD 0x420 +#define H_PKS_GEN_PASSWORD 0x424 +#define H_PKS_WRITE_OBJECT 0x42C +#define H_PKS_GEN_KEY 0x430 +#define H_PKS_READ_OBJECT 0x434 +#define H_PKS_REMOVE_OBJECT 0x438 +#define H_PKS_CONFIRM_OBJECT_FLUSHED 0x43C#define H_RPT_INVALIDATE 0x448#define H_SCM_FLUSH 0x44C#define H_GET_ENERGY_SCALE_INFO 0x450 -#define MAX_HCALL_OPCODE H_GET_ENERGY_SCALE_INFO +#define H_PKS_SIGNED_UPDATE 0x454 +#define MAX_HCALL_OPCODE H_PKS_SIGNED_UPDATE/* Scope args for H_SCM_UNBIND_ALL */ #define H_UNBIND_SCOPE_ALL (0x1)
arch/powerpc/include/asm/plpks.h new file +92 -0
92 lines not on this page · raw message
arch/powerpc/platforms/pseries/Kconfig +10 -0
@@ -142,6 +142,16 @@ config IBMEBUS help Bus device driver for GX bus based adapters. +config PSERIES_PLPKS + depends on PPC_PSERIES + tristate "Support for the Platform Key Storage" + help + PowerVM provides an isolated Platform Keystore(PKS) storage + allocation for each LPAR with individually managed access + controls to store sensitive information securely. Select this + config to enable operating system interface to hypervisor to + access this space. + config PAPR_SCM depends on PPC_PSERIES && MEMORY_HOTPLUG && LIBNVDIMM tristate "Support for the PAPR Storage Class Memory interface"
arch/powerpc/platforms/pseries/Makefile +2 -0
@@ -37,3 +37,5 @@ obj-$(CONFIG_ARCH_HAS_CC_PLATFORM) += cc_platform.o # nothing that operates in real mode is safe for KASAN KASAN_SANITIZE_ras.o := n KASAN_SANITIZE_kexec.o := n + +obj-$(CONFIG_PSERIES_PLPKS) += plpks/
arch/powerpc/platforms/pseries/plpks/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 IBM Corporation +# Author: Nayna Jain <[email protected]> +# + +obj-$(CONFIG_PSERIES_PLPKS) += plpks.o
arch/powerpc/platforms/pseries/plpks/plpks.c new file +517 -0
517 lines not on this page · raw message
Signature · 1 line
2.27.0
RFC PATCH v2 2/3 fs: define a firmware security filesystem named fwsecurityfs
In reply to Nayna Jainsecurityfs is meant for linux security subsystems to expose policies/logs or any other information. However, there are various firmware security features which expose their variables for user management via kernel. There is currently no single place to expose these variables. Different platforms use sysfs/platform specific filesystem(efivarfs)/securityfs interface as find appropriate. Thus, there is a gap in kernel interfaces to expose variables for security features.
Define a firmware security filesystem (fwsecurityfs) to be used for exposing variables managed by firmware and to be used by firmware enabled security features. These variables are platform specific. Filesystem provides platforms to implement their own underlying semantics by defining own inode and file operations.
Similar to securityfs, the firmware security filesystem is recommended to be exposed on a well known mount point /sys/firmware/security. Platforms can define their own directory or file structure under this path.
Example:
# mount -t fwsecurityfs fwsecurityfs /sys/firmware/security
# cd /sys/firmware/security/
--- fs/Kconfig | 1 + fs/Makefile | 1 + fs/fwsecurityfs/Kconfig | 14 +++ fs/fwsecurityfs/Makefile | 10 +++ fs/fwsecurityfs/inode.c | 159 +++++++++++++++++++++++++++++++++++ fs/fwsecurityfs/internal.h | 13 +++ fs/fwsecurityfs/super.c | 154 +++++++++++++++++++++++++++++++++ include/linux/fwsecurityfs.h | 29 +++++++ include/uapi/linux/magic.h | 1 + 9 files changed, 382 insertions(+) create mode 100644 fs/fwsecurityfs/Kconfig create mode 100644 fs/fwsecurityfs/Makefile create mode 100644 fs/fwsecurityfs/inode.c create mode 100644 fs/fwsecurityfs/internal.h create mode 100644 fs/fwsecurityfs/super.c create mode 100644 include/linux/fwsecurityfs.h
fs/Kconfig +1 -0
@@ -276,6 +276,7 @@ config ARCH_HAS_GIGANTIC_PAGE source "fs/configfs/Kconfig" source "fs/efivarfs/Kconfig" +source "fs/fwsecurityfs/Kconfig" endmenu
fs/Makefile +1 -0
@@ -137,6 +137,7 @@ obj-$(CONFIG_F2FS_FS) += f2fs/ obj-$(CONFIG_CEPH_FS) += ceph/ obj-$(CONFIG_PSTORE) += pstore/ obj-$(CONFIG_EFIVAR_FS) += efivarfs/ +obj-$(CONFIG_FWSECURITYFS) += fwsecurityfs/ obj-$(CONFIG_EROFS_FS) += erofs/ obj-$(CONFIG_VBOXSF_FS) += vboxsf/ obj-$(CONFIG_ZONEFS_FS) += zonefs/
fs/fwsecurityfs/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 IBM Corporation +# Author: Nayna Jain <[email protected]> +# + +config FWSECURITYFS + bool "Enable the fwsecurityfs filesystem" + help + This will build the fwsecurityfs file system which is recommended + to be mounted on /sys/firmware/security. This can be used by + platforms to expose their variables which are managed by firmware. + + If you are unsure how to answer this question, answer N.
fs/fwsecurityfs/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 IBM Corporation +# Author: Nayna Jain <[email protected]> +# +# Makefile for the firmware security filesystem + +obj-$(CONFIG_FWSECURITYFS) += fwsecurityfs.o + +fwsecurityfs-objs := inode.o super.o
fs/fwsecurityfs/inode.c new file +159 -0
159 lines not on this page · raw message
fs/fwsecurityfs/internal.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2022 IBM Corporation +* Author: Nayna Jain <[email protected]> +*/ + +#ifndef __FWSECURITYFS_INTERNAL_H +#define __FWSECURITYFS_INTERNAL_H + +struct dentry *fwsecurityfs_alloc_dentry (struct dentry *parent, +const char *name); + +#endif
fs/fwsecurityfs/super.c new file +154 -0
154 lines not on this page · raw message
include/linux/fwsecurityfs.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2022 IBM Corporation +* Author: Nayna Jain <[email protected]> +*/ + +#ifndef _FWSECURITYFS_H_ +#define _FWSECURITYFS_H_ + +#include <linux/ctype.h> +#include <linux/fs.h> + +struct super_block *fwsecurityfs_get_superblock (void ); +int fwsecurityfs_create_file (const char *name,umode_t mode, +u16 filesize,struct dentry *parent, +struct dentry *dentry, +const struct file_operations *fops); +int fwsecurityfs_remove_file (struct dentry *dentry); +struct dentry *fwsecurityfs_create_dir (const char *name,umode_t mode, +struct dentry *parent, +const struct inode_operations *iops); +int fwsecurityfs_remove_dir (struct dentry *dentry); + +static int arch_fwsecurity_init (void ) +{ +return 0 ; +} + +#endif /* _FWSECURITYFS_H_ */
include/uapi/linux/magic.h +1 -0
@@ -53,6 +53,7 @@#define QNX4_SUPER_MAGIC 0x002f/* qnx4 fs detection */ #define QNX6_SUPER_MAGIC 0x68191122/* qnx6 fs detection */ #define AFS_FS_MAGIC 0x6B414653 +#define FWSECURITYFS_MAGIC 0x5345434e/* "SECM" */ #define REISERFS_SUPER_MAGIC 0x52654973/* used by gcc */
Signature · 1 line
2.27.0
Re: [RFC PATCH v2 2/3] fs: define a firmware security filesystem named fwsecurityfs
Quoted 7 lines · Nayna Jain
securityfs is meant for linux security subsystems to expose policies/logs or any other information. However, there are various firmware security features which expose their variables for user management via kernel. There is currently no single place to expose these variables. Different platforms use sysfs/platform specific filesystem(efivarfs)/securityfs interface as find appropriate. Thus, there is a gap in kernel interfaces to expose variables for security features.
Why not put the firmware entries under /sys/kernel/security/firmware?
Re: [RFC PATCH v2 2/3] fs: define a firmware security filesystem named fwsecurityfs
Quoted 10 lines · Casey Schaufler
Quoted 7 lines · Nayna Jain
securityfs is meant for linux security subsystems to expose policies/logs or any other information. However, there are various firmware security features which expose their variables for user management via kernel. There is currently no single place to expose these variables. Different platforms use sysfs/platform specific filesystem(efivarfs)/securityfs interface as find appropriate. Thus, there is a gap in kernel interfaces to expose variables for security features.
Why not put the firmware entries under
/sys/kernel/security/firmware?
From man 5 sysfs page:
/sys/firmware: This subdirectory contains interfaces for viewing and manipulating firmware-specific objects and attributes.
/sys/kernel: This subdirectory contains various files and subdirectories that provide information about the running kernel.
The security variables which are supposed to be exposed via fwsecurityfs are managed by firmware, stored in firmware managed space and also often consumed by firmware for enabling various security features.
From git commit b67dbf9d4c1987c370fd18fdc4cf9d8aaea604c2, the purpose of securityfs(/sys/kernel/security) is to provide a common place for all kernel LSMs to use a common place. The idea of fwsecurityfs(/sys/firmware/security) is to similarly provide a common place for all firmware security objects.
By having another firmware directory within /sys/kernel/security would mean scattering firmware objects at multiple places and confusing the purpose of /sys/kernel and /sys/firmware.
Thanks & Regards,
- Nayna
Re: [RFC PATCH v2 2/3] fs: define a firmware security filesystem named fwsecurityfs
In reply to Nayna JainQuoted 143 lines · Nayna Jain
securityfs is meant for linux security subsystems to expose policies/logs or any other information. However, there are various firmware security features which expose their variables for user management via kernel. There is currently no single place to expose these variables. Different platforms use sysfs/platform specific filesystem(efivarfs)/securityfs interface as find appropriate. Thus, there is a gap in kernel interfaces to expose variables for security features.
Define a firmware security filesystem (fwsecurityfs) to be used for exposing variables managed by firmware and to be used by firmware enabled security features. These variables are platform specific. Filesystem provides platforms to implement their own underlying semantics by defining own inode and file operations.
Similar to securityfs, the firmware security filesystem is recommended to be exposed on a well known mount point
/sys/firmware/security. Platforms can define their own directory or file structure under this path.Example:
# mount -t fwsecurityfs fwsecurityfs /sys/firmware/security# cd /sys/firmware/security/Signed-off-by Nayna Jain <[email protected]>--- fs/Kconfig | 1 + fs/Makefile | 1 + fs/fwsecurityfs/Kconfig | 14 +++ fs/fwsecurityfs/Makefile | 10 +++ fs/fwsecurityfs/inode.c | 159 +++++++++++++++++++++++++++++++++++ fs/fwsecurityfs/internal.h | 13 +++ fs/fwsecurityfs/super.c | 154 +++++++++++++++++++++++++++++++++ include/linux/fwsecurityfs.h | 29 +++++++ include/uapi/linux/magic.h | 1 + 9 files changed, 382 insertions(+) create mode 100644 fs/fwsecurityfs/Kconfig create mode 100644 fs/fwsecurityfs/Makefile create mode 100644 fs/fwsecurityfs/inode.c create mode 100644 fs/fwsecurityfs/internal.h create mode 100644 fs/fwsecurityfs/super.c create mode 100644 include/linux/fwsecurityfs.hfs/Kconfig +1
-0@@ -276,6 +276,7 @@ config ARCH_HAS_GIGANTIC_PAGE source "fs/configfs/Kconfig" source "fs/efivarfs/Kconfig" +source "fs/fwsecurityfs/Kconfig" endmenufs/Makefile +1
-0@@ -137,6 +137,7 @@ obj-$(CONFIG_F2FS_FS) += f2fs/ obj-$(CONFIG_CEPH_FS) += ceph/ obj-$(CONFIG_PSTORE) += pstore/ obj-$(CONFIG_EFIVAR_FS) += efivarfs/ +obj-$(CONFIG_FWSECURITYFS) += fwsecurityfs/ obj-$(CONFIG_EROFS_FS) += erofs/ obj-$(CONFIG_VBOXSF_FS) += vboxsf/ obj-$(CONFIG_ZONEFS_FS) += zonefs/fs/fwsecurityfs/Kconfig new file +14
-0@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 IBM Corporation +# Author: Nayna Jain <[email protected]> +# + +config FWSECURITYFS + bool "Enable the fwsecurityfs filesystem" + help + This will build the fwsecurityfs file system which is recommended + to be mounted on /sys/firmware/security. This can be used by + platforms to expose their variables which are managed by firmware. + + If you are unsure how to answer this question, answer N.fs/fwsecurityfs/Makefile new file +10
-0@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2022 IBM Corporation +# Author: Nayna Jain <[email protected]> +# +# Makefile for the firmware security filesystem + +obj-$(CONFIG_FWSECURITYFS) += fwsecurityfs.o + +fwsecurityfs-objs := inode.o super.ofs/fwsecurityfs/inode.c new file +34
-0@@ -0,0 +1,159 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2022 IBM Corporation +* Author: Nayna Jain <[email protected]> +*/ + +#include <linux/sysfs.h> +#include <linux/kobject.h> +#include <linux/fs.h> +#include <linux/fs_context.h> +#include <linux/mount.h> +#include <linux/pagemap.h> +#include <linux/init.h> +#include <linux/namei.h> +#include <linux/security.h> +#include <linux/lsm_hooks.h> +#include <linux/magic.h> +#include <linux/ctype.h> +#include <linux/fwsecurityfs.h> + +#include "internal.h" + +int fwsecurityfs_remove_file (struct dentry *dentry) +{ +drop_nlink (d_inode (dentry)); +dput (dentry); +return 0 ; +}; +EXPORT_SYMBOL_GPL (fwsecurityfs_remove_file); + +int fwsecurityfs_create_file (const char *name,umode_t mode, +u16 filesize,struct dentry *parent, +struct dentry *dentry, +const struct file_operations *fops)
fs/fwsecurityfs/inode.c line 44
Quoted 10 lines
fs/fwsecurityfs/inode.c new file +10
-0+{ +struct inode *inode; +int error; +struct inode *dir; + +if (!parent) +return -EINVAL ; + + dir =d_inode (parent); +pr_debug ("securityfs: creating file '%s'\n" , name);
Did you forget to call simple_pin_fs() here or anywhere else?
And this can be just one function with the directory creation file, just check the mode and you will be fine. Look at securityfs as an example of how to make this simpler.
fs/fwsecurityfs/super.c
Quoted 1 line
fs/fwsecurityfs/super.c +0
-0
super.c and inode.c can be in the same file, these are tiny, just make one file for the filesystem logic.
thanks,
greg k-h
Re: [RFC PATCH v2 2/3] fs: define a firmware security filesystem named fwsecurityfs
On Thu, 2022-06-23 at 10:54 +0200, Greg Kroah-Hartman wrote:
[...]
Quoted 55 lines
Quoted 42 lines
fs/fwsecurityfs/inode.c new file +32
-0@@ -0,0 +1,159 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2022 IBM Corporation +* Author: Nayna Jain <[email protected]> +*/ + +#include <linux/sysfs.h> +#include <linux/kobject.h> +#include <linux/fs.h> +#include <linux/fs_context.h> +#include <linux/mount.h> +#include <linux/pagemap.h> +#include <linux/init.h> +#include <linux/namei.h> +#include <linux/security.h> +#include <linux/lsm_hooks.h> +#include <linux/magic.h> +#include <linux/ctype.h> +#include <linux/fwsecurityfs.h> + +#include "internal.h" + +int fwsecurityfs_remove_file (struct dentry *dentry) +{ +drop_nlink (d_inode (dentry)); +dput (dentry); +return 0 ; +}; +EXPORT_SYMBOL_GPL (fwsecurityfs_remove_file); + +int fwsecurityfs_create_file (const char *name,umode_t mode, + u16 filesize, struct dentry*parent,
fs/fwsecurityfs/inode.c new file +2
-0+struct dentry *dentry, + const struct file_operations*fops)
fs/fwsecurityfs/inode.c line 44
Quoted 10 lines
fs/fwsecurityfs/inode.c new file +10
-0+{ +struct inode *inode; +int error; +struct inode *dir; + +if (!parent) +return -EINVAL ; + + dir =d_inode (parent); +pr_debug ("securityfs: creating file '%s'\n" , name);Did you forget to call
simple_pin_fs()here or anywhere else?
Quoted 3 lines
And this can be just one function with the directory creation file, just check the mode and you will be fine. Look at securityfs as an example of how to make this simpler.
Actually, before you go down this route can you consider the namespace ramifications. In fact we're just having to rework securityfs to pull out all the simple_pin_... calls because simple_pin_... is completely inimical to namespaces.
The first thing to consider is if you simply use securityfs you'll inherit all the simple_pin_... removal work and be namespace ready. It could be that creating a new filesystem that can't be namespaced is the right thing to do here, but at least ask the question: would we ever want any of these files to be presented selectively inside containers? If the answer is "yes" then simple_pin_... is the wrong interface.
James
Re: [RFC PATCH v2 2/3] fs: define a firmware security filesystem named fwsecurityfs
Quoted 66 lines · James Bottomley
On Thu, 2022-06-23 at 10:54 +0200, Greg Kroah-Hartman wrote:
[...]Quoted 55 lines
Quoted 42 lines
fs/fwsecurityfs/inode.c new file +32
-0@@ -0,0 +1,159 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2022 IBM Corporation +* Author: Nayna Jain <[email protected]> +*/ + +#include <linux/sysfs.h> +#include <linux/kobject.h> +#include <linux/fs.h> +#include <linux/fs_context.h> +#include <linux/mount.h> +#include <linux/pagemap.h> +#include <linux/init.h> +#include <linux/namei.h> +#include <linux/security.h> +#include <linux/lsm_hooks.h> +#include <linux/magic.h> +#include <linux/ctype.h> +#include <linux/fwsecurityfs.h> + +#include "internal.h" + +int fwsecurityfs_remove_file (struct dentry *dentry) +{ +drop_nlink (d_inode (dentry)); +dput (dentry); +return 0 ; +}; +EXPORT_SYMBOL_GPL (fwsecurityfs_remove_file); + +int fwsecurityfs_create_file (const char *name,umode_t mode, + u16 filesize, struct dentry*parent,
fs/fwsecurityfs/inode.c new file +2
-0+struct dentry *dentry, + const struct file_operations*fops)
fs/fwsecurityfs/inode.c line 44
Quoted 10 lines
fs/fwsecurityfs/inode.c new file +10
-0+{ +struct inode *inode; +int error; +struct inode *dir; + +if (!parent) +return -EINVAL ; + + dir =d_inode (parent); +pr_debug ("securityfs: creating file '%s'\n" , name);Did you forget to call
simple_pin_fs()here or anywhere else?Quoted 3 lines
And this can be just one function with the directory creation file, just check the mode and you will be fine. Look at securityfs as an example of how to make this simpler.
Actually, before you go down this route can you consider the namespace ramifications. In fact we're just having to rework securityfs to pull out all the
simple_pin_... calls becausesimple_pin_... is completely inimical to namespaces.
Quoted 6 lines
The first thing to consider is if you simply use securityfs you'll inherit all the
simple_pin_... removal work and be namespace ready. It could be that creating a new filesystem that can't be namespaced is the right thing to do here, but at least ask the question: would we ever want any of these files to be presented selectively inside containers? If the answer is "yes" thensimple_pin_... is the wrong interface.
Greg, the securityfs changes James is referring to are part of the IMA namespacing patch set:
https://lore.kernel.org/linux-integrity/[email protected]/
I'd really appreciate your reviewing the first two patches:
[PATCH v12 01/26] securityfs: rework dentry creation [PATCH v12 02/26] securityfs: Extend securityfs with namespacing support
thanks,
Mimi
Re: [RFC PATCH v2 2/3] fs: define a firmware security filesystem named fwsecurityfs
Quoted 74 lines · Mimi Zohar
Quoted 66 lines · James Bottomley
On Thu, 2022-06-23 at 10:54 +0200, Greg Kroah-Hartman wrote:
[...]Quoted 55 lines
Quoted 42 lines
fs/fwsecurityfs/inode.c new file +32
-0@@ -0,0 +1,159 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2022 IBM Corporation +* Author: Nayna Jain <[email protected]> +*/ + +#include <linux/sysfs.h> +#include <linux/kobject.h> +#include <linux/fs.h> +#include <linux/fs_context.h> +#include <linux/mount.h> +#include <linux/pagemap.h> +#include <linux/init.h> +#include <linux/namei.h> +#include <linux/security.h> +#include <linux/lsm_hooks.h> +#include <linux/magic.h> +#include <linux/ctype.h> +#include <linux/fwsecurityfs.h> + +#include "internal.h" + +int fwsecurityfs_remove_file (struct dentry *dentry) +{ +drop_nlink (d_inode (dentry)); +dput (dentry); +return 0 ; +}; +EXPORT_SYMBOL_GPL (fwsecurityfs_remove_file); + +int fwsecurityfs_create_file (const char *name,umode_t mode, + u16 filesize, struct dentry*parent,
fs/fwsecurityfs/inode.c new file +2
-0+struct dentry *dentry, + const struct file_operations*fops)
fs/fwsecurityfs/inode.c line 44
Quoted 10 lines
fs/fwsecurityfs/inode.c new file +10
-0+{ +struct inode *inode; +int error; +struct inode *dir; + +if (!parent) +return -EINVAL ; + + dir =d_inode (parent); +pr_debug ("securityfs: creating file '%s'\n" , name);Did you forget to call
simple_pin_fs()here or anywhere else?Quoted 3 lines
And this can be just one function with the directory creation file, just check the mode and you will be fine. Look at securityfs as an example of how to make this simpler.
Actually, before you go down this route can you consider the namespace ramifications. In fact we're just having to rework securityfs to pull out all the
simple_pin_... calls becausesimple_pin_... is completely inimical to namespaces.Quoted 6 lines
The first thing to consider is if you simply use securityfs you'll inherit all the
simple_pin_... removal work and be namespace ready. It could be that creating a new filesystem that can't be namespaced is the right thing to do here, but at least ask the question: would we ever want any of these files to be presented selectively inside containers? If the answer is "yes" thensimple_pin_... is the wrong interface.
Quoted 8 lines
Greg, the securityfs changes James is referring to are part of the IMA namespacing patch set:
https://lore.kernel.org/linux-integrity/[email protected]/I'd really appreciate your reviewing the first two patches:
[PATCH v12 01/26] securityfs: rework dentry creation [PATCH v12 02/26] securityfs: Extend securityfs with namespacing support
Looks like others have already reviewed them, they seem sane to me if they past testing.
thanks,
greg k-h
Christian Brauner
maintainerRe: [RFC PATCH v2 2/3] fs: define a firmware security filesystem named fwsecurityfs
Quoted 59 lines · Greg Kroah-Hartman
Quoted 58 lines · Mimi Zohar
Quoted 57 lines · James Bottomley
On Thu, 2022-06-23 at 10:54 +0200, Greg Kroah-Hartman wrote:
[...]Quoted 55 lines
Quoted 42 lines
fs/fwsecurityfs/inode.c new file +32
-0@@ -0,0 +1,159 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2022 IBM Corporation +* Author: Nayna Jain <[email protected]> +*/ + +#include <linux/sysfs.h> +#include <linux/kobject.h> +#include <linux/fs.h> +#include <linux/fs_context.h> +#include <linux/mount.h> +#include <linux/pagemap.h> +#include <linux/init.h> +#include <linux/namei.h> +#include <linux/security.h> +#include <linux/lsm_hooks.h> +#include <linux/magic.h> +#include <linux/ctype.h> +#include <linux/fwsecurityfs.h> + +#include "internal.h" + +int fwsecurityfs_remove_file (struct dentry *dentry) +{ +drop_nlink (d_inode (dentry)); +dput (dentry); +return 0 ; +}; +EXPORT_SYMBOL_GPL (fwsecurityfs_remove_file); + +int fwsecurityfs_create_file (const char *name,umode_t mode, + u16 filesize, struct dentry*parent,
fs/fwsecurityfs/inode.c new file +2
-0+struct dentry *dentry, + const struct file_operations*fops)
fs/fwsecurityfs/inode.c line 44
Quoted 10 lines
fs/fwsecurityfs/inode.c new file +10
-0+{ +struct inode *inode; +int error; +struct inode *dir; + +if (!parent) +return -EINVAL ; + + dir =d_inode (parent); +pr_debug ("securityfs: creating file '%s'\n" , name);Did you forget to call
simple_pin_fs()here or anywhere else?
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
And this can be just one function with the directory creation file, just check the mode and you will be fine. Look at securityfs as an example of how to make this simpler.
Actually, before you go down this route can you consider the namespace ramifications. In fact we're just having to rework securityfs to pull out all the
simple_pin_... calls becausesimple_pin_... is completely inimical to namespaces.
I described this at length in the securityfs namespacing thread at various points. simple_pin_*() should be avoided if possible. Ideally the filesystem will just be cleaned up on umount. There might be a reason to make it survive umounts if you have state that stays around and somehow is intimately tied to that filesystem.
Quoted 12 lines
Quoted 12 lines
Quoted 7 lines
The first thing to consider is if you simply use securityfs you'll inherit all the
simple_pin_... removal work and be namespace ready. It could be that creating a new filesystem that can't be namespaced is the right thing to do here, but at least ask the question: would we ever want any of these files to be presented selectively inside containers? If the answer is "yes" thensimple_pin_... is the wrong interface.Greg, the securityfs changes James is referring to are part of the IMA namespacing patch set:
https://lore.kernel.org/linux-integrity/[email protected]/
Quoted 7 lines
Quoted 4 lines
I'd really appreciate your reviewing the first two patches:
[PATCH v12 01/26] securityfs: rework dentry creation [PATCH v12 02/26] securityfs: Extend securityfs with namespacing supportLooks like others have already reviewed them, they seem sane to me if they past testing.
Thanks for taking a look.
kernel test robot
build botRe: [RFC PATCH v2 2/3] fs: define a firmware security filesystem named fwsecurityfs
In reply to Nayna Jain[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Nayna,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on powerpc/next]
[also build test ERROR on linus/master v5.19-rc3 next-20220623] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Nayna-Jain/powerpc-pseries-add-support-for-local-secure-storage-called-Platform-KeyStore-PKS/20220623-060048 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20220624/[email protected]/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 46be5faaf03466c3751f8a2882bef5a217e15926)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/02d7d8ac9272e2e56bac334a16100784450e8902
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Nayna-Jain/powerpc-pseries-add-support-for-local-secure-storage-called-Platform-KeyStore-PKS/20220623-060048 git checkout 02d7d8ac9272e2e56bac334a16100784450e8902
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
All errors (new ones prefixed by >>):
>> fs/fwsecurityfs/super.c:152:20: error: expected parameter declarator
MODULE_DESCRIPTION("Firmware Security Filesystem");
^
>> fs/fwsecurityfs/super.c:152:20: error: expected ')'
fs/fwsecurityfs/super.c:152:19: note: to match this '('
MODULE_DESCRIPTION("Firmware Security Filesystem");
^
>> fs/fwsecurityfs/super.c:152:1: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
MODULE_DESCRIPTION("Firmware Security Filesystem");
^
int
>> fs/fwsecurityfs/super.c:152:19: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
MODULE_DESCRIPTION("Firmware Security Filesystem");
^
void
fs/fwsecurityfs/super.c:153:15: error: expected parameter declarator
MODULE_AUTHOR("Nayna Jain");
^
fs/fwsecurityfs/super.c:153:15: error: expected ')'
fs/fwsecurityfs/super.c:153:14: note: to match this '('
MODULE_AUTHOR("Nayna Jain");
^
fs/fwsecurityfs/super.c:153:1: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
MODULE_AUTHOR("Nayna Jain");
^
int
fs/fwsecurityfs/super.c:153:14: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
MODULE_AUTHOR("Nayna Jain");
^
void
fs/fwsecurityfs/super.c:154:16: error: expected parameter declarator
MODULE_LICENSE("GPL");
^
fs/fwsecurityfs/super.c:154:16: error: expected ')'
fs/fwsecurityfs/super.c:154:15: note: to match this '('
MODULE_LICENSE("GPL");
^
fs/fwsecurityfs/super.c:154:1: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
MODULE_LICENSE("GPL");
^
int
fs/fwsecurityfs/super.c:154:15: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
MODULE_LICENSE("GPL");
^
void12 errors generated.
vim +152 fs/fwsecurityfs/super.c
134
135 static int __init fwsecurityfs_init(void)
136 {
137 int retval;
138
139 retval = sysfs_create_mount_point(firmware_kobj, "security");
140 if (retval)
141 return retval;
142
143 retval = register_filesystem(&fs_type);
144 if (retval) {
145 sysfs_remove_mount_point(firmware_kobj, "security");
146 return retval;
147 }
148
149 return 0;
150 }
151 core_initcall(fwsecurityfs_init);
> 152 MODULE_DESCRIPTION("Firmware Security Filesystem");Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
RFC PATCH v2 3/3 powerpc/pseries: expose authenticated variables stored in LPAR PKS
In reply to Nayna JainPowerVM Guest Secure boot feature need to expose firmware managed secure variables for user management. These variables store keys for grub/kernel verification and also corresponding denied list.
Expose these variables to the userpace via fwsecurityfs.
Example:
Example:
# cd /sys/firmware/security/secvars
# pwd /sys/firmware/security/secvars
# cat /tmp/PK.bin > PK
# ls -l total 0 -rw-r--r-- 1 root root 2497 Jun 22 08:34 PK
# hexdump -C PK 00000000 00 00 00 00 00 08 00 00 a1 59 c0 a5 e4 94 a7 4a |.........Y.....J| 00000010 87 b5 ab 15 5c 2b f0 72 3f 03 00 00 00 00 00 00 |....\+.r?.......| 00000020 23 03 00 00 ca 18 1d 1c 01 7d eb 11 9a 71 08 94 |#........}...q..| 00000030 ef 31 fb e4 30 82 03 0f 30 82 01 f7 a0 03 02 01 |.1..0...0.......| 00000040 02 02 14 22 ab 18 2f d5 aa dd c5 ba 98 27 60 26 |..."../......'`&| 00000050 f1 63 89 54 4c 52 d9 30 0d 06 09 2a 86 48 86 f7 |.c.TLR.0...*.H..| ...
--- arch/powerpc/platforms/pseries/Kconfig | 17 ++ arch/powerpc/platforms/pseries/plpks/Makefile | 2 + .../pseries/plpks/fwsecurityfs_arch.c | 16 ++ .../platforms/pseries/plpks/internal.h | 18 ++ .../powerpc/platforms/pseries/plpks/secvars.c | 239 ++++++++++++++++++ include/linux/fwsecurityfs.h | 4 + 6 files changed, 296 insertions(+) create mode 100644 arch/powerpc/platforms/pseries/plpks/fwsecurityfs_arch.c create mode 100644 arch/powerpc/platforms/pseries/plpks/internal.h create mode 100644 arch/powerpc/platforms/pseries/plpks/secvars.c
arch/powerpc/platforms/pseries/Kconfig +17 -0
@@ -152,6 +152,23 @@ config PSERIES_PLPKS config to enable operating system interface to hypervisor to access this space. +config PSERIES_FWSECURITYFS_ARCH + depends on FWSECURITYFS + bool "Support fwsecurityfs for pseries" + help + Enable fwsecuirtyfs arch specific code. This would initialize + the firmware security filesystem with initial platform specific + structure. + +config PSERIES_PLPKS_SECVARS + depends on PSERIES_PLPKS + select PSERIES_FWSECURITYFS_ARCH + tristate "Support for secvars" + help + This interface exposes authenticated variables stored in the LPAR + Platform KeyStore using fwsecurityfs interface. + If you are unsure how to use it, say N. + config PAPR_SCM depends on PPC_PSERIES && MEMORY_HOTPLUG && LIBNVDIMM tristate "Support for the PAPR Storage Class Memory interface"
arch/powerpc/platforms/pseries/plpks/Makefile +2 -0
@@ -5,3 +5,5 @@ # obj-$(CONFIG_PSERIES_PLPKS) += plpks.o +obj-$(CONFIG_PSERIES_FWSECURITYFS_ARCH) += fwsecurityfs_arch.o +obj-$(CONFIG_PSERIES_PLPKS_SECVARS) += secvars.o
arch/powerpc/platforms/pseries/plpks/fwsecurityfs_arch.c new file +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* POWER LPAR Platform KeyStore (PLPKS) +* Copyright (C) 2022 IBM Corporation +* Author: Nayna Jain <[email protected]> +* +*/ + +#include <linux/fwsecurityfs.h> + +#include "internal.h" + +int arch_fwsecurity_init (void ) +{ +return plpks_secvars_init (); +}
arch/powerpc/platforms/pseries/plpks/internal.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2022 IBM Corporation +* Author: Nayna Jain <[email protected]> +* +*/ +#ifndef PKS_FWSEC_INTERNAL +#define PKS_FWSEC_INTERNAL + +#ifdef CONFIG_PSERIES_PLPKS_SECVARS +int plpks_secvars_init (void ); +#else +int plpks_secvars_init (void ) +{ +return 0 ; +} +#endif +#endif
arch/powerpc/platforms/pseries/plpks/secvars.c new file +239 -0
239 lines not on this page · raw message
include/linux/fwsecurityfs.h +4 -0
@@ -21,9 +21,13 @@ struct dentry *fwsecurityfs_create_dir(const char *name, umode_t mode, const struct inode_operations *iops);int fwsecurityfs_remove_dir (struct dentry *dentry); +#ifdef CONFIG_PSERIES_FWSECURITYFS_ARCH +int arch_fwsecurity_init (void ); +#else static int arch_fwsecurity_init (void ) {return 0 ; } +#endif #endif /* _FWSECURITYFS_H_ */
Signature · 1 line
2.27.0
Re: [RFC PATCH v2 3/3] powerpc/pseries: expose authenticated variables stored in LPAR PKS
arch/powerpc/platforms/pseries/Kconfig config PSERIES_PLPKS · line 159
Quoted 13 lines · Nayna Jain
arch/powerpc/platforms/pseries/Kconfig +5
-0@@ -152,6 +152,23 @@ config PSERIES_PLPKS config to enable operating system interface to hypervisor to access this space. +config PSERIES_FWSECURITYFS_ARCH + depends on FWSECURITYFS + bool "Support fwsecurityfs for pseries" + help + Enable fwsecuirtyfs arch specific code. This would initialize
fwsecurityfs . This initializes
Quoted 11 lines
arch/powerpc/platforms/pseries/Kconfig +11
-0+ the firmware security filesystem with initial platform specific + structure. + +config PSERIES_PLPKS_SECVARS + depends on PSERIES_PLPKS + select PSERIES_FWSECURITYFS_ARCH + tristate "Support for secvars" + help + This interface exposes authenticated variables stored in the LPAR + Platform KeyStore using fwsecurityfs interface. + If you are unsure how to use it, say N.
Signature · 1 line
~Randy
Quoted 2 lines · Nayna Jain
* Renamed PKS driver to PLPKS to avoid naming conflict as mentioned by Dave Hanson.
Thank you for doing this! The new naming looks much less likely to cause confusion.