Extend PKWM to support user-created wrapping keys
Subsystems (8)
Srish Srinivasan
maintainerv3 cover Extend PKWM to support user-created wrapping keys
The PKWM trusted source currently uses a single default wrapping key per LPAR. This key is created during trusted source initialization, and all trusted keys backed by PKWM are sealed and unsealed using it.
Recent versions of PKWM allow users to create and manage their own wrapping keys through a set of lifecycle operations. This patch series brings these PKWM capabilities into the kernel, allowing users to create, manage, and select wrapping keys for sealing and unsealing their trusted keys, rather than requiring all trusted keys to use the default wrapping key.
This series extends PKWM to support user-created wrapping keys. It adds the required hcalls, allows users to select a wrapping key by label when creating PKWM-backed trusted keys, and introduces a sysfs interface for managing wrapping keys from userspace.
This patchset also includes three fixes: one aligning the PLPKS wrapping length types with the underlying hcall interfaces, another preserving the original error returned when default wrapping key generation fails, and a third clearing sensitive PKWM seal and unseal buffers before freeing them.
This series depends on the following PLPKS refactoring and hardening series and must be applied on top of it:
https://lore.kernel.org/all/[email protected]/
Changelog:
v2 -> v3:
- Moved most of the refactoring and hardening patches into a separate series:
https://lore.kernel.org/all/[email protected]/
- Added a fix to clear sensitive PKWM seal and unseal buffers before freeing them
- Retained Nageswara's Tested-by tag
- Refined error handling and documented default wrapping key restrictions
v1 -> v2:
- Addressed parameter validation issues reported by Nageswara
- Tweaked PLPKS_WRAPKEY_SYSFS Kconfig help text
- Added two preparatory bug-fix patches
- Cc'd [email protected] where applicable
Srish Srinivasan (6):
pseries/plpks: fix length types for wrapping operations keys/trusted_keys: propagate wrapping key generation errors keys/trusted_keys: clear sensitive PKWM buffers pseries/plpks: add HCALLs for PKWM wrapping key life cycle management keys/trusted_keys: enable PKWM wrapping key selection by label pseries/plpks/wrapkey: expose PKWM wrapping key management to
userspace via sysfs
.../ABI/testing/sysfs-firmware-plpks | 116 ++++ Documentation/arch/powerpc/papr_hcalls.rst | 33 ++ .../security/keys/trusted-encrypted.rst | 4 +- arch/powerpc/include/asm/hvcall.h | 5 +- arch/powerpc/include/asm/plpks.h | 40 +- arch/powerpc/platforms/pseries/Kconfig | 15 + arch/powerpc/platforms/pseries/Makefile | 1 + arch/powerpc/platforms/pseries/plpks-sysfs.c | 11 + .../platforms/pseries/plpks-wrapkey-sysfs.c | 399 ++++++++++++++ arch/powerpc/platforms/pseries/plpks.c | 502 ++++++++++++++++-- include/keys/trusted_pkwm.h | 3 + security/keys/trusted-keys/trusted_pkwm.c | 48 +- 12 files changed, 1126 insertions(+), 51 deletions(-) create mode 100644 arch/powerpc/platforms/pseries/plpks-wrapkey-sysfs.c
Signature · 1 line
2.52.0
Srish Srinivasan
maintainerPATCH v3 1/6 pseries/plpks: fix length types for wrapping operations
The object wrapping and unwrapping hcalls use 64-bit length values, but plpks_wrap_object() and plpks_unwrap_object() currently use u32 for the input and output length parameters. As a result, the interfaces cannot represent the full range of values supported by the hcalls.
Use u64 for the length parameters to align them with the underlying hcall interfaces. Update the PKWM consumer accordingly.
--- arch/powerpc/include/asm/plpks.h | 8 ++++---- arch/powerpc/platforms/pseries/plpks.c | 8 ++++---- security/keys/trusted-keys/trusted_pkwm.c | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-)
arch/powerpc/include/asm/plpks.h +4 -4
@@ -118,11 +118,11 @@ bool plpks_wrapping_is_supported(void);int plpks_gen_wrapping_key (void ); -int plpks_wrap_object (u8 **input_buf,u32 input_len,u16 wrap_flags, -u8 **output_buf,u32 *output_len); +int plpks_wrap_object (u8 **input_buf,u64 input_len,u16 wrap_flags, +u8 **output_buf,u64 *output_len); -int plpks_unwrap_object (u8 **input_buf,u32 input_len, -u8 **output_buf,u32 *output_len); +int plpks_unwrap_object (u8 **input_buf,u64 input_len, +u8 **output_buf,u64 *output_len);#else // CONFIG_PSERIES_PLPKS static inline bool plpks_is_available (void ) {return false; }static inline u16 plpks_get_passwordlen (void ) {BUILD_BUG (); }
arch/powerpc/platforms/pseries/plpks.c +4 -4
@@ -1021,8 +1021,8 @@ EXPORT_SYMBOL_GPL(plpks_gen_wrapping_key);* * Returns: On success 0 is returned, a negative errno if not. */ -int plpks_wrap_object (u8 **input_buf,u32 input_len,u16 wrap_flags, -u8 **output_buf,u32 *output_len) +int plpks_wrap_object (u8 **input_buf,u64 input_len,u16 wrap_flags, +u8 **output_buf,u64 *output_len) {unsigned long retbuf[PLPAR_HCALL9_BUFSIZE ] = {0 };struct plpks_auth *auth;
@@ -1140,8 +1140,8 @@ EXPORT_SYMBOL_GPL(plpks_wrap_object);* * Returns: On success 0 is returned, a negative errno if not. */ -int plpks_unwrap_object (u8 **input_buf,u32 input_len,u8 **output_buf, -u32 *output_len) +int plpks_unwrap_object (u8 **input_buf,u64 input_len,u8 **output_buf, +u64 *output_len) {unsigned long retbuf[PLPAR_HCALL9_BUFSIZE ] = {0 };struct plpks_auth *auth;
security/keys/trusted-keys/trusted_pkwm.c +2 -2
@@ -83,7 +83,7 @@ static int trusted_pkwm_seal(struct trusted_key_payload *p, char *datablob)struct trusted_key_options *options =NULL ;struct trusted_pkwm_options *pkwm =NULL ;u8 *input_buf, *output_buf; -u32 output_len, input_len; +u64 output_len, input_len;int rc; options =trusted_options_alloc ();
@@ -130,7 +130,7 @@ static int trusted_pkwm_seal(struct trusted_key_payload *p, char *datablob)static int trusted_pkwm_unseal (struct trusted_key_payload *p,char *datablob) {u8 *input_buf, *output_buf; -u32 input_len, output_len; +u64 input_len, output_len;int rc; input_len = p->blob_len;
Signature · 1 line
2.52.0
Srish Srinivasan
maintainerPATCH v3 2/6 keys/trusted_keys: propagate wrapping key generation errors
In reply to Srish Srinivasanplpks_gen_wrapping_key() returns a negative errno when default wrapping key generation fails. However, trusted_pkwm_init() returns -EINVAL for all such failures, discarding the original error.
Propagate the error returned by plpks_gen_wrapping_key() unchanged.
--- security/keys/trusted-keys/trusted_pkwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/keys/trusted-keys/trusted_pkwm.c +1 -1
@@ -170,7 +170,7 @@ static int trusted_pkwm_init(void) ret =plpks_gen_wrapping_key ();if (ret) {pr_err ("Failed to generate default wrapping key\n" ); -return -EINVAL ; +return ret; }return register_key_type (&key_type_trusted);
Signature · 1 line
2.52.0
Srish Srinivasan
maintainerPATCH v3 3/6 keys/trusted_keys: clear sensitive PKWM buffers
In reply to Srish SrinivasanThe input buffer to PKWM seal and the output buffer from PKWM unseal contain plaintext trusted-key payload data. Freeing these buffers with kfree(), without wiping the contents, can leave sensitive key material in memory.
Use kfree_sensitive() to wipe the sensitive key material when freeing these buffers.
--- security/keys/trusted-keys/trusted_pkwm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
security/keys/trusted-keys/trusted_pkwm.c +2 -2
@@ -118,7 +118,7 @@ static int trusted_pkwm_seal(struct trusted_key_payload *p, char *datablob)pr_err ("Wrapping of payload key failed: %d\n" , rc); } -kfree (input_buf); +kfree_sensitive (input_buf);kfree (output_buf); out:
@@ -153,7 +153,7 @@ static int trusted_pkwm_unseal(struct trusted_key_payload *p, char *datablob) }kfree (input_buf); -kfree (output_buf); +kfree_sensitive (output_buf);return rc; }
Signature · 1 line
2.52.0
Srish Srinivasan
maintainerPATCH v3 4/6 pseries/plpks: add HCALLs for PKWM wrapping key life cycle management
In reply to Srish SrinivasanThe PKWM trusted source uses a single wrapping key per LPAR, created only once during trust source initialization. All the wrap and unwrap requests are bound to this default wrapping key.
Implement H_PKS_REVOKE_OBJECT, H_PKS_UNREVOKE_OBJECT, and H_PKS_GET_OBJECTLABELS HCALLs to enable support for revoking and unrevoking PKWM wrapping keys, and for retrieving wrapping key labels. The label retrieval operation (H_PKS_GET_OBJECTLABELS) applies to all wrapping keys including the default one, while the life cycle operations (H_PKS_REVOKE_OBJECT/H_PKS_UNREVOKE_OBJECT) apply only to user-created wrapping keys.
--- Documentation/arch/powerpc/papr_hcalls.rst | 33 ++ arch/powerpc/include/asm/hvcall.h | 5 +- arch/powerpc/include/asm/plpks.h | 15 + arch/powerpc/platforms/pseries/plpks.c | 448 ++++++++++++++++++++- 4 files changed, 497 insertions(+), 4 deletions(-)
Documentation/arch/powerpc/papr_hcalls.rst +33 -0
@@ -343,6 +343,39 @@ is returned to the caller. H_PKS_UNWRAP_OBJECT is used to unwrap an object that was previously wrapped with H_PKS_WRAP_OBJECT. +**H_PKS_REVOKE_OBJECT** + +| Input: authorization, objectlabel, objectlabellen, flags +| Out: *object policy* +| Return Value: *H_Success, H_Function, H_State, H_Parameter, H_P2, H_P3, H_P4, + H_Authority, H_Not_Found, H_Busy, H_Aborted* + +H_PKS_REVOKE_OBJECT is used to revoke an object in Platform Keystore. + + +**H_PKS_UNREVOKE_OBJECT** + +| Input: authorization, objectlabel, objectlabellen, flags +| Out: *object policy* +| Return Value: *H_Success, H_Function, H_State, H_Parameter, H_P2, H_P3, H_P4, + H_Authority, H_Not_Found, H_Busy, H_Aborted* + +H_PKS_UNREVOKE_OBJECT is used to unrevoke an object that was previously revoked +with H_PKS_REVOKE_OBJECT in Platform Keystore. + + +**H_PKS_GET_OBJECTLABELS** + +| Input: authorization, continueToken, out, outlen +| Out: *continue-token, number of object labels in the returned list, object + label list* +| Return Value: *H_Success, H_Function, H_State, H_Parameter, H_P2, H_P3, H_P4, + H_Authority, H_Busy, H_Aborted, H_Continue* + +H_PKS_GET_OBJECTLABELS is used to retrieve a list of object labels owned by the +specified consumer. + + References ========== .. [1] "Power Architecture Platform Reference"
arch/powerpc/include/asm/hvcall.h +4 -1
@@ -340,6 +340,7 @@#define H_PKS_GET_CONFIG 0x41C#define H_PKS_SET_PASSWORD 0x420#define H_PKS_GEN_PASSWORD 0x424 +#define H_PKS_GET_OBJECTLABELS 0x428#define H_PKS_WRITE_OBJECT 0x42C#define H_PKS_GEN_KEY 0x430#define H_PKS_READ_OBJECT 0x434
@@ -362,7 +363,9 @@#define H_GUEST_DELETE 0x488#define H_PKS_WRAP_OBJECT 0x490#define H_PKS_UNWRAP_OBJECT 0x494 -#define MAX_HCALL_OPCODE H_PKS_UNWRAP_OBJECT +#define H_PKS_REVOKE_OBJECT 0x4AC +#define H_PKS_UNREVOKE_OBJECT 0x4B0 +#define MAX_HCALL_OPCODE H_PKS_UNREVOKE_OBJECT/* Scope args for H_SCM_UNBIND_ALL */ #define H_UNBIND_SCOPE_ALL (0x1)
arch/powerpc/include/asm/plpks.h +15 -0
@@ -25,6 +25,7 @@#define PLPKS_SIGNEDUPDATE PPC_BIT32(7) // Object can only be modified by signed updates#define PLPKS_WRAPPINGKEY PPC_BIT32(8) // Object contains a wrapping key#define PLPKS_HVPROVISIONED PPC_BIT32(28) // Hypervisor has provisioned this object +#define PLPKS_REVOKED PPC_BIT32(30) // Object is revoked// Signature algorithm flags from signed_update_algorithms #define PLPKS_ALG_RSA2048 PPC_BIT(0)
@@ -123,6 +124,20 @@ int plpks_wrap_object(u8 **input_buf, u64 input_len, u16 wrap_flags,int plpks_unwrap_object (u8 **input_buf,u64 input_len,u8 **output_buf,u64 *output_len); + +int plpks_revoke_wrapping_key (struct plpks_var *var); + +int plpks_unrevoke_wrapping_key (struct plpks_var *var); + +int plpks_del_wrapping_key (struct plpks_var *var); + +int plpks_is_wrapping_key_revoked (struct plpks_var *var); + +int plpks_get_object_labels (u8 **output_buf,u64 *output_len, +char *comp_prefix); + +bool plpks_revoke_is_supported (void ); +#else // CONFIG_PSERIES_PLPKS static inline bool plpks_is_available (void ) {return false; }static inline u16 plpks_get_passwordlen (void ) {BUILD_BUG (); }
arch/powerpc/platforms/pseries/plpks.c +445 -3
498 lines not on this page · raw message
Signature · 1 line
2.52.0
Srish Srinivasan
maintainerPATCH v3 5/6 keys/trusted_keys: enable PKWM wrapping key selection by label
In reply to Srish SrinivasanThe PKWM trusted source currently uses the default wrapping key for all seal and unseal operations. However, PKWM supports multiple wrapping keys, enabling better isolation between trusted keys.
Allow users to provide an active wrapping key of their choice created through sysfs when sealing trusted keys through a new wrapping_key=<label> option. If no label is specified, the default wrapping key is used for sealing.
--- .../security/keys/trusted-encrypted.rst | 4 +- arch/powerpc/include/asm/plpks.h | 10 +++- arch/powerpc/platforms/pseries/plpks.c | 49 ++++++++----------- include/keys/trusted_pkwm.h | 3 ++ security/keys/trusted-keys/trusted_pkwm.c | 38 ++++++++++++-- 5 files changed, 68 insertions(+), 36 deletions(-)
Documentation/security/keys/trusted-encrypted.rst +3 -1
@@ -83,7 +83,7 @@ safe. (5) PKWM (PowerVM Key Wrapping Module: IBM PowerVM + Platform KeyStore) - Rooted to a unique, per-LPAR key, which is derived from a system-wide, + Rooted to unique, per-LPAR keys, which are derived from a system-wide, randomly generated LPAR root key. Both the per-LPAR keys and the LPAR root key are stored in hypervisor-owned secure memory at runtime, and the LPAR root key is additionally persisted in secure locations
@@ -366,6 +366,8 @@ Usage:: 0x01: require secure boot to be in either audit or enforced mode 0x02: require secure boot to be in enforced mode + wrapping_key= optional wrapping key label as a string. The default + wrapping key is used when no label is provided. "keyctl print" returns an ASCII hex copy of the sealed key, which is in format specific to PKWM key-blob implementation. The key length for new keys is
arch/powerpc/include/asm/plpks.h +8 -2
@@ -50,6 +50,12 @@#define PLPKS_MAX_TIMEOUT (5 * USEC_PER_SEC)#define PLPKS_FLUSH_SLEEP 10000 // usec +// Label for the PKWM default wrapping key +#define PLPKS_DEFAULT_WRAPKEY_LABEL "default-wrapping-key" + +// Component for a PKWM wrapping key +#define PLPKS_WRAPKEY_COMPONENT "PLPKSWR" +struct plpks_var {char *component;u8 *name;
@@ -117,10 +123,10 @@ int plpks_config_create_softlink(struct kobject *from);bool plpks_wrapping_is_supported (void ); -int plpks_gen_wrapping_key (void ); +int plpks_gen_wrapping_key (struct plpks_var *var);int plpks_wrap_object (u8 **input_buf,u64 input_len,u16 wrap_flags, -u8 **output_buf,u64 *output_len); +u8 **output_buf,u64 *output_len,struct plpks_var *var);int plpks_unwrap_object (u8 **input_buf,u64 input_len,u8 **output_buf,u64 *output_len);
arch/powerpc/platforms/pseries/plpks.c +20 -29
124 lines not on this page · raw message
include/keys/trusted_pkwm.h +3 -0
@@ -6,10 +6,13 @@#include <linux/bitops.h> #include <linux/printk.h> +#define WRAPPING_KEY_LABEL_LEN_MAX 239 +extern struct trusted_key_ops pkwm_trusted_key_ops;struct trusted_pkwm_options {u16 wrap_flags; +unsigned char wrapping_key_label[WRAPPING_KEY_LABEL_LEN_MAX +1 ]; };static inline void dump_options (struct trusted_key_options *o)
security/keys/trusted-keys/trusted_pkwm.c +34 -4
@@ -13,10 +13,12 @@enum { Opt_err, Opt_wrap_flags, + Opt_wrapping_key_label, };static const match_table_t key_tokens = { {Opt_wrap_flags,"wrap_flags=%s" }, + {Opt_wrapping_key_label,"wrapping_key=%s" }, {Opt_err,NULL } };
@@ -50,6 +52,12 @@ static int getoptions(char *datablob, struct trusted_key_options *opt)return -EINVAL ; pkwm->wrap_flags = wrap_flags;break ; +case Opt_wrapping_key_label: +if (strlen (args[0 ].from) >WRAPPING_KEY_LABEL_LEN_MAX ) +return -EINVAL ; +strscpy (pkwm->wrapping_key_label, args[0 ].from, +sizeof (pkwm->wrapping_key_label)); +break ;default :return -EINVAL ; }
@@ -82,6 +90,7 @@ static int trusted_pkwm_seal(struct trusted_key_payload *p, char *datablob) {struct trusted_key_options *options =NULL ;struct trusted_pkwm_options *pkwm =NULL ; +struct plpks_var var = {0 };u8 *input_buf, *output_buf;u64 output_len, input_len;int rc;
@@ -108,8 +117,18 @@ static int trusted_pkwm_seal(struct trusted_key_payload *p, char *datablob) pkwm = options->private; +if (pkwm->wrapping_key_label[0 ]) { + var.name = (u8 *)pkwm->wrapping_key_label; + var.namelen =strlen (pkwm->wrapping_key_label); + }else { + var.name = (u8 *)PLPKS_DEFAULT_WRAPKEY_LABEL ; + var.namelen =strlen (PLPKS_DEFAULT_WRAPKEY_LABEL ); + } + var.os =PLPKS_VAR_LINUX ; + var.component =PLPKS_WRAPKEY_COMPONENT ; + rc =plpks_wrap_object (&input_buf, input_len, pkwm->wrap_flags, - &output_buf, &output_len); + &output_buf, &output_len, &var);if (!rc) {memcpy (p->blob, output_buf, output_len); p->blob_len = output_len;
@@ -161,15 +180,26 @@ static int trusted_pkwm_unseal(struct trusted_key_payload *p, char *datablob)static int trusted_pkwm_init (void ) {int ret; +struct plpks_var var;if (!plpks_wrapping_is_supported ()) {pr_err ("H_PKS_WRAP_OBJECT interface not supported\n" );return -ENODEV ; } - ret =plpks_gen_wrapping_key (); -if (ret) { -pr_err ("Failed to generate default wrapping key\n" ); + var = (struct plpks_var ) { + .name = (u8 *)PLPKS_DEFAULT_WRAPKEY_LABEL , + .namelen =sizeof (PLPKS_DEFAULT_WRAPKEY_LABEL ) -1 , + .policy =PLPKS_WRAPPINGKEY , + .os =PLPKS_VAR_LINUX , + .component =PLPKS_WRAPKEY_COMPONENT + }; + + ret =plpks_gen_wrapping_key (&var); + +/* An existing default wrapping key is considered success. */ +if (ret && ret != -EEXIST ) { +pr_err ("Failed to generate default wrapping key: %d\n" , ret);return ret; }
Signature · 1 line
2.52.0
Srish Srinivasan
maintainerPATCH v3 6/6 pseries/plpks/wrapkey: expose PKWM wrapping key management to userspace via sysfs
In reply to Srish SrinivasanThe PKWM trusted source currently uses a single default wrapping key created during initialization. However, PKWM also supports user-created wrapping keys for better isolation between trusted keys.
Expose wrapping key lifecycle operations through sysfs to allow users to create and manage their own wrapping keys.
Create a sysfs interface at /sys/firmware/plpks/wrapkey with the following attributes:
create - Create a new wrapping key with a user-provided label delete - Delete a revoked wrapping key by label revoke - Revoke a wrapping key by label unrevoke - Unrevoke a previously revoked wrapping key by label list_active - List labels of all active (non-revoked) wrapping keys list_revoked - List labels of all revoked wrapping keys
User-provided labels are validated to contain only alphanumeric characters.
Wrapping key lifecycle constraints:
- A wrapping key must be revoked before it can be deleted
- Revoked wrapping keys cannot be used for wrap operations until unrevoked
- The default wrapping key cannot be revoked or deleted; it always appears in list_active
The wrapping keys themselves are confidential objects stored in PLPKS. Only the user-provided labels are exposed to userspace for identification and management purposes.
These user-created wrapping keys can be used in seal/unseal operations via the wrapping_key=<label> option.
--- .../ABI/testing/sysfs-firmware-plpks | 116 +++++ arch/powerpc/include/asm/plpks.h | 9 + arch/powerpc/platforms/pseries/Kconfig | 15 + arch/powerpc/platforms/pseries/Makefile | 1 + arch/powerpc/platforms/pseries/plpks-sysfs.c | 11 + .../platforms/pseries/plpks-wrapkey-sysfs.c | 399 ++++++++++++++++++ arch/powerpc/platforms/pseries/plpks.c | 1 - 7 files changed, 551 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/platforms/pseries/plpks-wrapkey-sysfs.c
Documentation/ABI/testing/sysfs-firmware-plpks +116 -0
@@ -56,3 +56,119 @@ Description: Bitmask of the wrapping features indicating the wrapping algorithms that are supported for the H_PKS_WRAP_OBJECT requests , represented as a 8 byte hexadecimal ASCII string. Consult the hypervisor documentation for what these flags mean. + +What: /sys/firmware/plpks/wrapkey +Date: August 2026 +Contact: Srish Srinivasan <[email protected]> +Description: This directory provides the interface for creating and managing + user-created PKWM wrapping keys. + + The directory is present only when CONFIG_PLPKS_WRAPKEY_SYSFS is + enabled and the system supports the H_PKS_{UN}REVOKE_OBJECT + interfaces. + + Only alphanumeric characters are accepted in wrapping key + labels. The wrapping keys themselves are confidential PLPKS + objects and are not exposed to userspace. Only their labels are + exposed for identification and management. + + Each write is processed as an independent operation and accepts + exactly one wrapping key label. The resulting state can be + verified through list_active or list_revoked, as appropriate. + + The default wrapping key, named "default-wrapping-key", cannot + be created, revoked, unrevoked, or deleted through this + interface. + +What: /sys/firmware/plpks/wrapkey/create +Date: August 2026 +Contact: Srish Srinivasan <[email protected]> +Description: (WO) Create a wrapping key with the specified label, except + "default-wrapping-key", which is reserved for the default + wrapping key. + + On success, the label appears in list_active. + + For example, to create a wrapping key labelled "wk1": + + echo -n wk1 > /sys/firmware/plpks/wrapkey/create + + or: + + printf '%s' 'wk1' > /sys/firmware/plpks/wrapkey/create + +What: /sys/firmware/plpks/wrapkey/delete +Date: August 2026 +Contact: Srish Srinivasan <[email protected]> +Description: (WO) Delete a revoked wrapping key identified by the specified + label. A wrapping key must be revoked before it can be deleted. + The default wrapping key, named "default-wrapping-key", cannot + be deleted. + + On success, the label no longer appears in list_revoked. + + For example, to delete a revoked wrapping key labelled "wk1": + + echo -n wk1 > /sys/firmware/plpks/wrapkey/delete + + or: + + printf '%s' 'wk1' > /sys/firmware/plpks/wrapkey/delete + +What: /sys/firmware/plpks/wrapkey/revoke +Date: August 2026 +Contact: Srish Srinivasan <[email protected]> +Description: (WO) Revoke a wrapping key identified by the specified label. A + revoked wrapping key cannot be used for seal or unseal + operations until it is unrevoked. The default wrapping key, + named "default-wrapping-key", cannot be revoked. + + On success, the label appears in list_revoked and no longer + appears in list_active. + + For example, to revoke a wrapping key labelled "wk1": + + echo -n wk1 > /sys/firmware/plpks/wrapkey/revoke + + or: + + printf '%s' 'wk1' > /sys/firmware/plpks/wrapkey/revoke + +What: /sys/firmware/plpks/wrapkey/unrevoke +Date: August 2026 +Contact: Srish Srinivasan <[email protected]> +Description: (WO) Unrevoke a revoked wrapping key identified by the specified + label. The default wrapping key, named "default-wrapping-key", + cannot be unrevoked through this interface because it cannot be + revoked. + + On success, the label appears in list_active and no longer + appears in list_revoked. + + For example, to unrevoke a revoked wrapping key labelled "wk1": + + echo -n wk1 > /sys/firmware/plpks/wrapkey/unrevoke + + or: + + printf '%s' 'wk1' > /sys/firmware/plpks/wrapkey/unrevoke + +What: /sys/firmware/plpks/wrapkey/list_active +Date: August 2026 +Contact: Srish Srinivasan <[email protected]> +Description: (RO) List the labels of active, non-revoked wrapping keys. The + default wrapping key, named "default-wrapping-key", is always + included in this list. + + For example: + + cat /sys/firmware/plpks/wrapkey/list_active + +What: /sys/firmware/plpks/wrapkey/list_revoked +Date: August 2026 +Contact: Srish Srinivasan <[email protected]> +Description: (RO) List the labels of revoked wrapping keys. + + For example: + + cat /sys/firmware/plpks/wrapkey/list_revoked
arch/powerpc/include/asm/plpks.h +9 -0
@@ -56,6 +56,8 @@// Component for a PKWM wrapping key #define PLPKS_WRAPKEY_COMPONENT "PLPKSWR" +#define PLPKS_OBJLABEL_LEN_FIELD_SIZE 2 +struct plpks_var {char *component;u8 *name;
@@ -144,6 +146,9 @@ int plpks_get_object_labels(u8 **output_buf, u64 *output_len,bool plpks_revoke_is_supported (void ); +int plpks_init_child_kobj (struct kobject *kobj,const struct kobj_type *ktype, +const char *name); +#else // CONFIG_PSERIES_PLPKS static inline bool plpks_is_available (void ) {return false; }static inline u16 plpks_get_passwordlen (void ) {BUILD_BUG (); }
@@ -151,6 +156,10 @@ static inline void plpks_early_init_devtree(void) { }static inline int plpks_populate_fdt (void *fdt) {BUILD_BUG (); }static inline int plpks_config_create_softlink (struct kobject *from) {return 0 ; } +static inline int plpks_init_child_kobj (struct kobject *kobj, +const struct kobj_type *ktype, +const char *name) + {return 0 ; }#endif // CONFIG_PSERIES_PLPKS #endif // _ASM_POWERPC_PLPKS_H
arch/powerpc/platforms/pseries/Kconfig +15 -0
@@ -216,3 +216,18 @@ config PPC_SVM those guests. If unsure, say "N". + +config PLPKS_WRAPKEY_SYSFS + bool "Enable sysfs interface for managing PKWM wrapping keys" + default n + depends on PSERIES_PLPKS + depends on SYSFS + depends on TRUSTED_KEYS_PKWM + help + The PKWM trusted source supports user-created wrapping keys that are + managed by the OS. These wrapping keys can be created, revoked, + unrevoked, and deleted through sysfs. Their labels can also be viewed + through sysfs. + + Say Y if PLPKS and PKWM are enabled and you want to isolate trusted + keys using user-created wrapping keys.
arch/powerpc/platforms/pseries/Makefile +1 -0
@@ -33,6 +33,7 @@ obj-$(CONFIG_FA_DUMP) += rtas-fadump.o obj-$(CONFIG_PSERIES_PLPKS) += plpks.o plpks-sysfs.o obj-$(CONFIG_PPC_SECURE_BOOT) += plpks-secvar.o obj-$(CONFIG_PSERIES_PLPKS_SED) += plpks_sed_ops.o +obj-$(CONFIG_PLPKS_WRAPKEY_SYSFS) += plpks-wrapkey-sysfs.o obj-$(CONFIG_SUSPEND) += suspend.o obj-$(CONFIG_PPC_VAS) += vas.o vas-sysfs.o
arch/powerpc/platforms/pseries/plpks-sysfs.c +11 -0
@@ -55,6 +55,17 @@ static umode_t plpks_config_attr_is_visible(struct kobject *kobj,return attr->mode; } +int plpks_init_child_kobj (struct kobject *kobj,const struct kobj_type *ktype, +const char *name) +{ +kobject_init (kobj, ktype); + +if (!plpks_kobj) +return -ENODEV ; + +return kobject_add (kobj, plpks_kobj,"%s" , name); +} +int plpks_config_create_softlink (struct kobject *from) {if (!plpks_config_kobj)
arch/powerpc/platforms/pseries/plpks-wrapkey-sysfs.c new file +399 -0
399 lines not on this page · raw message
arch/powerpc/platforms/pseries/plpks.c +0 -1
@@ -25,7 +25,6 @@*/ #define PLPKS_OBJLABEL_BUF_MAX 2550 -#define PLPKS_OBJLABEL_LEN_FIELD_SIZE 2#define PLPKS_OBJLABEL_PREFIX_LEN 8#define PLPKS_WRAP_INTERFACE_BIT 3
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH v3 2/6] keys/trusted_keys: propagate wrapping key generation errors
In reply to Srish SrinivasanSashiko has reviewed this patch and found no issues.
Quoted 9 lines
plpks_gen_wrapping_key()returns a negative errno when default wrapping key generation fails. However,trusted_pkwm_init()returns-EINVALfor all such failures, discarding the original error.Propagate the error returned by
plpks_gen_wrapping_key()unchanged.Fixes c99fcb0d735b ("keys/trusted_keys: establish PKWM as a trusted source")Cc [email protected] # 7.0Signed-off-by Srish Srinivasan <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH v3 1/6] pseries/plpks: fix length types for wrapping operations
In reply to Srish SrinivasanSashiko has reviewed this patch and found no issues.
Quoted 5 lines
The object wrapping and unwrapping hcalls use 64-bit length values, but
plpks_wrap_object()andplpks_unwrap_object()currently use u32 for the input and output length parameters. As a result, the interfaces cannot represent the full range of values supported by the hcalls.
Quoted 7 lines
Use u64 for the length parameters to align them with the underlying hcall interfaces. Update the PKWM consumer accordingly.
Fixes 133aa79e211d ("pseries/plpks: add HCALLs for PowerVM Key Wrapping Module")Fixes c99fcb0d735b ("keys/trusted_keys: establish PKWM as a trusted source")Cc [email protected] # 7.0Signed-off-by Srish Srinivasan <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH v3 3/6] keys/trusted_keys: clear sensitive PKWM buffers
In reply to Srish SrinivasanSashiko has reviewed this patch and found no issues.
Quoted 11 lines
The input buffer to PKWM seal and the output buffer from PKWM unseal contain plaintext trusted-key payload data. Freeing these buffers with
kfree(), without wiping the contents, can leave sensitive key material in memory.Use
kfree_sensitive()to wipe the sensitive key material when freeing these buffers.Fixes c99fcb0d735b ("keys/trusted_keys: establish PKWM as a trusted source")Cc [email protected] # 7.0Signed-off-by Srish Srinivasan <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH v3 4/6] pseries/plpks: add HCALLs for PKWM wrapping key life cycle management
In reply to Srish SrinivasanThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] pseries/plpks: stale var->policy evaluated in plpks_is_wrapping_key_revoked() - [Low]…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] pseries/plpks: stale var->policy evaluated in plpks_is_wrapping_key_revoked()
- [Low] powerpc/pseries: papr_hcalls.rst swaps H_PKS_GET_OBJECTLABELS output order --
commit 73a27f4e02c0030b70181101065300c5db3bc91b
Author: Srish Srinivasan <[email protected]>
pseries/plpks: add HCALLs for PKWM wrapping key life cycle management
This commit implements the H_PKS_REVOKE_OBJECT, H_PKS_UNREVOKE_OBJECT, and H_PKS_GET_OBJECTLABELS hypervisor calls in the pseries PLPKS driver to support revoking, unrevoking, deleting, and listing PKWM wrapping keys.
Quoted 5 lines
Documentation/arch/powerpc/papr_hcalls.rst +0
-0@@ -343,6 +343,39 @@ is returned to the caller.
[ ... ]
Documentation/arch/powerpc/papr_hcalls.rst is returned to the caller. · line 376
Quoted 10 lines
Documentation/arch/powerpc/papr_hcalls.rst +10
-0+**H_PKS_GET_OBJECTLABELS** + +| Input: authorization, continueToken, out, outlen +| Out: *continue-token, number of object labels in the returned list, object + label list* +| Return Value: *H_Success, H_Function, H_State, H_Parameter, H_P2, H_P3, H_P4, + H_Authority, H_Busy, H_Aborted, H_Continue* + +H_PKS_GET_OBJECTLABELS is used to retrieve a list of object labels owned by the +specified consumer.
[Severity: Low]
Are the first two output fields for H_PKS_GET_OBJECTLABELS in Documentation/arch/powerpc/papr_hcalls.rst swapped relative to the output registers read in plpks_get_object_labels()?
In Documentation/arch/powerpc/papr_hcalls.rst, the Out field lists output registers in order starting from r4 (retbuf[0]) and r5 (retbuf[1]), which here places continue-token before the number of object labels.
However, in arch/powerpc/platforms/pseries/plpks.c:plpks_get_object_labels(), retbuf[0] is read as labels_count and retbuf[1] is read as continuetoken:
continuetoken = retbuf[1];
labels_count = retbuf[0];[ ... ]
Quoted 4 lines
arch/powerpc/platforms/pseries/plpks.c +0
-0
[ ... ]
Quoted 10 lines
arch/powerpc/platforms/pseries/plpks.c +0
-3@@ -831,9 +846,6 @@ static int plpks_read_var(u8 consumer, struct plpks_var *var)if (var->namelen >PLPKS_MAX_NAME_SIZE )return -EINVAL ; -if (var->policy &PLPKS_WRAPPINGKEY ) -return -EPERM ; - auth =construct_auth (consumer);if (IS_ERR (auth))return PTR_ERR (auth);
[ ... ]
Quoted 1 line
arch/powerpc/platforms/pseries/plpks.c +0
-0@@ -1189,6 +1218,419 @@ int plpks_unwrap_object(u8 **input_buf, u64 input_len, u8 **output_buf,
[ ... ]
Quoted 16 lines
arch/powerpc/platforms/pseries/plpks.c +16
-0+int plpks_is_wrapping_key_revoked (struct plpks_var *var) +{ +int rc; + +if (!var || !var->name || !*var->name) +return -EINVAL ; + + rc =plpks_read_var (PLPKS_OS_OWNER , var); +if (!rc) { +/* +* Reading a wrapping key is expected to fail with +* -EPERM and return its policy. +*/ + rc = -EIO ; + }else if (rc == -EPERM ) { +if (var->policy &PLPKS_WRAPPINGKEY ) {
arch/powerpc/platforms/pseries/plpks.c int plpks_unwrap_object(u8 **input_buf, u64 input_len, u8 **output_buf, · line 1417
Quoted 10 lines
arch/powerpc/platforms/pseries/plpks.c +10
-0+if (var->policy &PLPKS_REVOKED ) + rc =1 ; +else + rc =0 ; + } + } + +return rc; +} +EXPORT_SYMBOL_GPL (plpks_is_wrapping_key_revoked);
[Severity: Medium]
Can plpks_is_wrapping_key_revoked() evaluate a stale var->policy when H_PKS_READ_OBJECT fails with H_AUTHORITY and retbuf[1] is 0, or overwrite var->datalen and var->data if H_PKS_READ_OBJECT succeeds?
In arch/powerpc/platforms/pseries/plpks.c:plpks_read_var(), when H_PKS_READ_OBJECT returns H_AUTHORITY (mapped to -EPERM), var->policy is only updated if retbuf[1] is non-zero:
if (rc != H_SUCCESS) {
rc = pseries_status_to_err(rc);
if (rc != -EPERM || !retbuf[1])
goto out_free_output;
goto out_copy_policy;
}Because plpks_is_wrapping_key_revoked() does not zero var->policy before calling plpks_read_var(), an H_AUTHORITY failure with retbuf[1] == 0 leaves var->policy untouched and plpks_is_wrapping_key_revoked() then checks the pre-existing value in var->policy.
In the subsequent commit "pseries/plpks/wrapkey: expose PKWM wrapping key management to userspace via sysfs", list_key_labels() defines a single struct plpks_var var = {0} outside the loop and calls plpks_is_wrapping_key_revoked(&var) across all labels without resetting var.policy between iterations. Once an earlier iteration populates var.policy with PLPKS_WRAPPINGKEY, any later iteration where H_PKS_READ_OBJECT returns H_AUTHORITY with retbuf[1] == 0 will inspect the previous key's var.policy and return 0 or 1 instead of -EPERM. The same happens if a caller of plpks_is_wrapping_key_revoked() or plpks_del_wrapping_key() passes a struct plpks_var with PLPKS_WRAPPINGKEY already set in var->policy.
Additionally, if H_PKS_READ_OBJECT unexpectedly succeeds on a readable object, plpks_read_var() will overwrite var->datalen and copy into var->data (if non-NULL) before plpks_is_wrapping_key_revoked() returns -EIO.
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH v3 6/6] pseries/plpks/wrapkey: expose PKWM wrapping key management to userspace via sysfs
In reply to Srish SrinivasanThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] pseries/plpks: missing release() in wrapkey_ktype leaks wrapkey_kobj - [Medium] pseries/plpks…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] pseries/plpks: missing release() in wrapkey_ktype leaks wrapkey_kobj
- [Medium] pseries/plpks: stale var.policy across iterations in list_key_labels()
- [Low] powerpc/pseries: wrapkey_sysfs_init() runs on non-pseries platforms --
commit 7bc0ceea6c99f35ed770f462297146f04fc44fd3
Author: Srish Srinivasan <[email protected]>
pseries/plpks/wrapkey: expose PKWM wrapping key management to userspace via sysfs
This commit adds a sysfs interface under /sys/firmware/plpks/wrapkey to allow userspace to create, revoke, unrevoke, delete, and list PKWM wrapping keys.
Quoted 6 lines
arch/powerpc/platforms/pseries/plpks-wrapkey-sysfs.c new file +0
-0@@ -0,0 +1,399 @@
[ ... ]
Quoted 33 lines
arch/powerpc/platforms/pseries/plpks-wrapkey-sysfs.c new file +33
-0+static ssize_t list_key_labels (char *buf,u8 *obj_labels_buf, +u64 obj_labels_count,int revoked) +{ +struct plpks_var var = {0 }; +u8 *obj_labels_buf_ptr, *comp_prefix; +u8 *key_label_ptr; +u16 obj_label_len; +int len =0 ; +int is_revoked; +u64 i; + + var.os =PLPKS_VAR_LINUX ; + var.component =PLPKS_WRAPKEY_COMPONENT ; + obj_labels_buf_ptr = obj_labels_buf; + +for (i =0 ; i < obj_labels_count; ++i) { + obj_label_len =get_unaligned_be16 (obj_labels_buf_ptr); + comp_prefix = obj_labels_buf_ptr + +PLPKS_OBJLABEL_LEN_FIELD_SIZE ; + + var.namelen = obj_label_len -PLPKS_MAX_LABEL_ATTR_SIZE ; + var.name =kzalloc (var.namelen +1 ,GFP_KERNEL ); + +if (!var.name) +return -ENOMEM ; + + key_label_ptr = comp_prefix +PLPKS_MAX_LABEL_ATTR_SIZE ; +memcpy (var.name, key_label_ptr, var.namelen); + + is_revoked =plpks_is_wrapping_key_revoked (&var); +if (is_revoked == revoked) + len +=sysfs_emit_at (buf, len,"<%s>\n" , + (char *)var.name);
arch/powerpc/platforms/pseries/plpks-wrapkey-sysfs.c line 80
Quoted 10 lines
arch/powerpc/platforms/pseries/plpks-wrapkey-sysfs.c new file +10
-0+else if (is_revoked <0 ) +pr_warn ("Failed to get revocation status for <%s>\n" , + (char *)var.name); + +kfree (var.name); + obj_labels_buf_ptr = key_label_ptr + var.namelen; + } + +return len; +}
[Severity: Medium]
Can a stale var.policy value carry over across iterations of the loop in list_key_labels()?
In list_key_labels(), struct plpks_var var is zero-initialized once before the loop, and each iteration calls plpks_is_wrapping_key_revoked(&var) -> plpks_read_var(PLPKS_OS_OWNER, &var) without resetting var.policy.
When plpks_read_var() succeeds in retrieving a wrapping key's policy on one iteration, it sets var->policy (including PLPKS_WRAPPINGKEY and possibly PLPKS_REVOKED). If a subsequent iteration fails with -EPERM and retbuf[1] == 0:
arch/powerpc/platforms/pseries/plpks.c:plpks_read_var() {
if (rc != H_SUCCESS) {
rc = pseries_status_to_err(rc);
if (rc != -EPERM || !retbuf[1])
goto out_free_output;
goto out_copy_policy;
}
}var->policy is not overwritten. Then plpks_is_wrapping_key_revoked() inspects the stale var->policy from the previous key:
arch/powerpc/platforms/pseries/plpks.c:plpks_is_wrapping_key_revoked() {
} else if (rc == -EPERM) {
if (var->policy & PLPKS_WRAPPINGKEY) {
if (var->policy & PLPKS_REVOKED)
rc = 1;
else
rc = 0;
}
}
}Would this cause plpks_is_wrapping_key_revoked() to return the previous key's revocation status (0 or 1) instead of -EPERM?
[ ... ]
Quoted 15 lines
arch/powerpc/platforms/pseries/plpks-wrapkey-sysfs.c new file +15
-0+static const struct kobj_type wrapkey_ktype = { + .sysfs_ops = &kobj_sysfs_ops, + .default_groups = wrapkey_attr_groups, +}; + +static __init int wrapkey_sysfs_init (void ) +{ +int rc; + +if (!plpks_revoke_is_supported ()) { +pr_err ("H_PKS_{UN}REVOKE_OBJECT interface not supported\n" ); +return -ENODEV ; + } + + wrapkey_kobj =kzalloc_obj (*wrapkey_kobj);
arch/powerpc/platforms/pseries/plpks-wrapkey-sysfs.c line 397
Quoted 10 lines
arch/powerpc/platforms/pseries/plpks-wrapkey-sysfs.c new file +10
-0+if (!wrapkey_kobj) +return -ENOMEM ; + + rc =plpks_init_child_kobj (wrapkey_kobj, &wrapkey_ktype,"wrapkey" ); + +if (rc) +kobject_put (wrapkey_kobj); + +return rc; +}
[Severity: Medium]
Does calling kobject_put(wrapkey_kobj) leak wrapkey_kobj and trigger a kobject warning because wrapkey_ktype has no .release callback?
In wrapkey_sysfs_init(), wrapkey_kobj is dynamically allocated with kzalloc_obj(*wrapkey_kobj) and initialized via plpks_init_child_kobj() -> kobject_init(kobj, &wrapkey_ktype).
If plpks_init_child_kobj() fails (for example, when plpks_kobj is NULL or kobject_add() returns an error), wrapkey_sysfs_init() calls kobject_put(wrapkey_kobj). Because wrapkey_ktype omits .release, kobject_cleanup() will not free wrapkey_kobj, and wrapkey_kobj also remains non-NULL.
arch/powerpc/platforms/pseries/plpks-wrapkey-sysfs.c line 399
Quoted 2 lines
arch/powerpc/platforms/pseries/plpks-wrapkey-sysfs.c new file +2
-0+ +late_initcall (wrapkey_sysfs_init);
[Severity: Low]
Should this use machine_late_initcall(pseries, wrapkey_sysfs_init) instead of late_initcall(wrapkey_sysfs_init)?
Other PLPKS initcalls (such as pseries_plpks_init() in plpks.c and plpks_sysfs_init() in plpks-sysfs.c) use machine_*_initcall(pseries, ...). With a bare late_initcall(), booting a multi-platform powerpc kernel on a non-pseries machine will run wrapkey_sysfs_init() and log:
wrapkey-sysfs: H_PKS_{UN}REVOKE_OBJECT interface not supported
[]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
[email protected]
AI reviewRe: [PATCH v3 5/6] keys/trusted_keys: enable PKWM wrapping key selection by label
In reply to Srish SrinivasanThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] keys/trusted_keys: uninitialized output_buf freed in trusted_pkwm_seal() - [Medium]…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] keys/trusted_keys: uninitialized output_buf freed in trusted_pkwm_seal()
- [Medium] powerpc/pseries/plpks: double status conversion in plpks_gen_wrapping_key() --
commit 333e996cc70a34c8f3a006ec261f3d6b0dcd0e1f
Author: Srish Srinivasan <[email protected]>
keys/trusted_keys: enable PKWM wrapping key selection by label
This commit updates the PKWM trusted keys backend and pseries PLPKS wrapping interface to allow callers to specify a wrapping key label via the wrapping_key=<label> option when sealing trusted keys, falling back to the default wrapping key if none is specified.
Quoted 4 lines
arch/powerpc/platforms/pseries/plpks.c +0
-0
[ ... ]
Quoted 43 lines
arch/powerpc/platforms/pseries/plpks.c +7
-10@@ -960,25 +958,22 @@ EXPORT_SYMBOL_GPL(plpks_revoke_is_supported);* * Returns: On success 0 is returned, a negative errno if not. */ -int plpks_gen_wrapping_key (void ) +int plpks_gen_wrapping_key (struct plpks_var *var) {unsigned long retbuf[PLPAR_HCALL_BUFSIZE ] = {0 };struct plpks_auth *auth;struct label *label;int rc =0 , pseries_status =0 ; -struct plpks_var var = { - .name =PLPKS_DEFAULT_WRAPKEY_LABEL , - .namelen =sizeof (PLPKS_DEFAULT_WRAPKEY_LABEL ) -1 , - .policy =PLPKS_WRAPPINGKEY , - .os =PLPKS_VAR_LINUX , - .component =PLPKS_WRAPKEY_COMPONENT - }; + +if (!var || !var->name || !*var->name) +return -EINVAL ; auth =construct_auth (PLPKS_OS_OWNER );if (IS_ERR (auth))return PTR_ERR (auth); - label =construct_label (var.component, var.os, var.name, var.namelen); + label =construct_label (var->component, var->os, var->name, + var->namelen);if (IS_ERR (label)) { rc =PTR_ERR (label); goto out;@@ -986,7 +981,7 @@ int plpks_gen_wrapping_key(void) rc =plpar_hcall (H_PKS_GEN_KEY , retbuf,virt_to_phys (auth),virt_to_phys (label), - label->size, var.policy, + label->size, var->policy,NULL ,PLPKS_WRAPPING_KEY_LENGTH );if (!rc)@@ -995,12 +990,9 @@ int plpks_gen_wrapping_key(void) pseries_status = rc;
arch/powerpc/platforms/pseries/plpks.c int plpks_gen_wrapping_key(void) · line 1003
Quoted 10 lines
arch/powerpc/platforms/pseries/plpks.c +2
-5rc =pseries_status_to_err (rc); -if (rc && rc != -EEXIST ) { -pr_err ("H_PKS_GEN_KEY failed. pseries_status=%d, rc=%d" , +if (rc && rc != -EEXIST ) +pr_err ("H_PKS_GEN_KEY failed. pseries_status=%d, rc=%d\n" , pseries_status, rc); - }else { - rc =0 ; - }
[Severity: Medium]
When plpar_hcall(H_PKS_GEN_KEY, ...) returns 0, plpks_gen_wrapping_key() calls plpks_confirm_object_flushed(label, auth):
arch/powerpc/platforms/pseries/plpks.c:plpks_confirm_object_flushed() {
...
if (timed_out)
return -ETIMEDOUT;
return pseries_status_to_err(rc);
}Since plpks_confirm_object_flushed() already converts the hypervisor status code into a negative Linux errno (or returns -ETIMEDOUT), passing its return value through pseries_status_to_err(rc) a second time in plpks_gen_wrapping_key() re-maps the Linux errno as if it were a hypervisor return code.
Because H_RESOURCE is -16 and -EBUSY is also -16, a -EBUSY return from plpks_confirm_object_flushed() gets converted into -EEXIST. With this patch Propagating -EEXIST to callers and trusted_pkwm_init() treating -EEXIST as success, won't a -EBUSY flush failure be silently ignored in both plpks_gen_wrapping_key() and trusted_pkwm_init(), while other flush errors like -ETIMEDOUT or -EIO are corrupted into -EINVAL or -ENXIO?
Quoted 3 lines
arch/powerpc/platforms/pseries/plpks.c +0
-0kfree (label); out:
[ ... ]
Quoted 4 lines
security/keys/trusted-keys/trusted_pkwm.c +0
-0
[ ... ]
Quoted 18 lines
security/keys/trusted-keys/trusted_pkwm.c +7
-0@@ -82,6 +90,7 @@ static int trusted_pkwm_seal(struct trusted_key_payload *p, char *datablob) {struct trusted_key_options *options =NULL ;struct trusted_pkwm_options *pkwm =NULL ; +struct plpks_var var = {0 };u8 *input_buf, *output_buf;u64 output_len, input_len;int rc;@@ -108,8 +117,18 @@ static int trusted_pkwm_seal(struct trusted_key_payload *p, char *datablob) pkwm = options->private; +if (pkwm->wrapping_key_label[0 ]) { + var.name = (u8 *)pkwm->wrapping_key_label; + var.namelen =strlen (pkwm->wrapping_key_label); + }else { + var.name = (u8 *)PLPKS_DEFAULT_WRAPKEY_LABEL ; + var.namelen =strlen (PLPKS_DEFAULT_WRAPKEY_LABEL );
security/keys/trusted-keys/trusted_pkwm.c static int trusted_pkwm_seal(struct trusted_key_payload *p, char *datablob) · line 134
Quoted 10 lines
security/keys/trusted-keys/trusted_pkwm.c +5
-1+ } + var.os =PLPKS_VAR_LINUX ; + var.component =PLPKS_WRAPKEY_COMPONENT ; + rc =plpks_wrap_object (&input_buf, input_len, pkwm->wrap_flags, - &output_buf, &output_len); + &output_buf, &output_len, &var);if (!rc) {memcpy (p->blob, output_buf, output_len); p->blob_len = output_len;
[Severity: High]
Can kfree(output_buf) be called on an uninitialized pointer in trusted_pkwm_seal()?
In trusted_pkwm_seal(), output_buf is declared on the stack without being initialized to NULL:
security/keys/trusted-keys/trusted_pkwm.c:trusted_pkwm_seal() {
...
u8 *input_buf, *output_buf;
...
rc = plpks_wrap_object(&input_buf, input_len, pkwm->wrap_flags,
&output_buf, &output_len, &var);
if (!rc) {
...
} else {
pr_err("Wrapping of payload key failed: %d\n", rc);
}
kfree_sensitive(input_buf);
kfree(output_buf);
}In plpks_wrap_object(), *output_buf is only assigned when kzalloc() is called:
arch/powerpc/platforms/pseries/plpks.c:plpks_wrap_object() {
...
if (!var || !var->name || !*var->name)
return -EINVAL;
auth = construct_auth(PLPKS_OS_OWNER);
if (IS_ERR(auth))
return PTR_ERR(auth);
label = construct_label(var->component, var->os, var->name,
var->namelen);
if (IS_ERR(label)) {
rc = PTR_ERR(label);
goto out;
}
...
if (sb_audit_or_enforce_bit & sb_enforce_bit) {
pr_err("Cannot set both audit/enforce and enforce bits.");
rc = -EINVAL;
goto out_free_label;
}
...
*output_buf = kzalloc(ALIGN(*output_len, PLPKS_WRAPPING_BUF_ALIGN),
GFP_KERNEL);
}If plpks_wrap_object() returns early via any of those error paths before reaching kzalloc() (for example if construct_label() fails on the user- supplied var->name or var->namelen, or if construct_auth() fails with -ENOMEM), *output_buf is never written and trusted_pkwm_seal() passes the uninitialized stack value to kfree(output_buf).
The same pattern also exists in trusted_pkwm_unseal(), where output_buf is uninitialized on the stack and passed to kfree_sensitive(output_buf) if construct_auth() fails in plpks_unwrap_object() before *output_buf is allocated. Should output_buf be initialized to NULL in both trusted_pkwm_seal() and trusted_pkwm_unseal()?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5