Skip to content

Commit 12b393a

Browse files
author
Mamatha Inamdar
committed
powerpc/pseries: Correct secvar format representation for static key management
JIRA: https://issues.redhat.com/browse/RHEL-101962 commit fbf355f Author: Srish Srinivasan <ssrish@linux.ibm.com> Date: Wed Jun 11 02:49:05 2025 +0530 powerpc/pseries: Correct secvar format representation for static key management On a PLPKS enabled PowerVM LPAR, the secvar format property for static key management is misrepresented as "ibm,plpks-sb-unknown", creating reason for confusion. Static key management mode uses fixed, built-in keys. Dynamic key management mode allows keys to be updated in production to handle security updates without firmware rebuilds. Define a function named plpks_get_sb_keymgmt_mode() to retrieve the key management mode based on the existence of the SB_VERSION property in the firmware. Set the secvar format property to either "ibm,plpks-sb-v<version>" or "ibm,plpks-sb-v0" based on the key management mode, and return the length of the secvar format property. Co-developed-by: Souradeep <soura@imap.linux.ibm.com> Signed-off-by: Souradeep <soura@imap.linux.ibm.com> Signed-off-by: Srish Srinivasan <ssrish@linux.ibm.com> Tested-by: R Nageswara Sastry <rnsastry@linux.ibm.com> Reviewed-by: Mimi Zohar <zohar@linux.ibm.com> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: Nayna Jain <nayna@linux.ibm.com> Reviewed-by: Andrew Donnellan <ajd@linux.ibm.com> Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com> Link: https://patch.msgid.link/20250610211907.101384-2-ssrish@linux.ibm.com Signed-off-by: Mamatha Inamdar <minamdar@redhat.com>
1 parent 0b30218 commit 12b393a

File tree

2 files changed

+53
-33
lines changed

2 files changed

+53
-33
lines changed

Documentation/ABI/testing/sysfs-secvar

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ Description: A string indicating which backend is in use by the firmware.
2222
and is expected to be "ibm,edk2-compat-v1".
2323

2424
On pseries/PLPKS, this is generated by the kernel based on the
25-
version number in the SB_VERSION variable in the keystore, and
26-
has the form "ibm,plpks-sb-v<version>", or
27-
"ibm,plpks-sb-unknown" if there is no SB_VERSION variable.
25+
version number in the SB_VERSION variable in the keystore. The
26+
version numbering in the SB_VERSION variable starts from 1. The
27+
format string takes the form "ibm,plpks-sb-v<version>" in the
28+
case of dynamic key management mode. If the SB_VERSION variable
29+
does not exist (or there is an error while reading it), it takes
30+
the form "ibm,plpks-sb-v0", indicating that the key management
31+
mode is static.
2832

2933
What: /sys/firmware/secvar/vars/<variable name>
3034
Date: August 2019

arch/powerpc/platforms/pseries/plpks-secvar.c

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -159,39 +159,55 @@ static int plpks_set_variable(const char *key, u64 key_len, u8 *data,
159159
return rc;
160160
}
161161

162-
// PLPKS dynamic secure boot doesn't give us a format string in the same way OPAL does.
163-
// Instead, report the format using the SB_VERSION variable in the keystore.
164-
// The string is made up by us, and takes the form "ibm,plpks-sb-v<n>" (or "ibm,plpks-sb-unknown"
165-
// if the SB_VERSION variable doesn't exist). Hypervisor defines the SB_VERSION variable as a
166-
// "1 byte unsigned integer value".
167-
static ssize_t plpks_secvar_format(char *buf, size_t bufsize)
162+
/*
163+
* Return the key management mode.
164+
*
165+
* SB_VERSION is defined as a "1 byte unsigned integer value", taking values
166+
* starting from 1. It is owned by the Partition Firmware and its presence
167+
* indicates that the key management mode is dynamic. Any failure in
168+
* reading SB_VERSION defaults the key management mode to static. The error
169+
* codes -ENOENT or -EPERM are expected in static key management mode. An
170+
* unexpected error code will have to be investigated. Only signed variables
171+
* have null bytes in their names, SB_VERSION does not.
172+
*
173+
* Return 0 to indicate that the key management mode is static. Otherwise
174+
* return the SB_VERSION value to indicate that the key management mode is
175+
* dynamic.
176+
*/
177+
static u8 plpks_get_sb_keymgmt_mode(void)
168178
{
169-
struct plpks_var var = {0};
170-
ssize_t ret;
171-
u8 version;
172-
173-
var.component = NULL;
174-
// Only the signed variables have null bytes in their names, this one doesn't
175-
var.name = "SB_VERSION";
176-
var.namelen = strlen(var.name);
177-
var.datalen = 1;
178-
var.data = &version;
179-
180-
// Unlike the other vars, SB_VERSION is owned by firmware instead of the OS
181-
ret = plpks_read_fw_var(&var);
182-
if (ret) {
183-
if (ret == -ENOENT) {
184-
ret = snprintf(buf, bufsize, "ibm,plpks-sb-unknown");
185-
} else {
186-
pr_err("Error %ld reading SB_VERSION from firmware\n", ret);
187-
ret = -EIO;
188-
}
189-
goto err;
179+
u8 mode;
180+
ssize_t rc;
181+
struct plpks_var var = {
182+
.component = NULL,
183+
.name = "SB_VERSION",
184+
.namelen = 10,
185+
.datalen = 1,
186+
.data = &mode,
187+
};
188+
189+
rc = plpks_read_fw_var(&var);
190+
if (rc) {
191+
if (rc != -ENOENT && rc != -EPERM)
192+
pr_info("Error %ld reading SB_VERSION from firmware\n", rc);
193+
mode = 0;
190194
}
195+
return mode;
196+
}
191197

192-
ret = snprintf(buf, bufsize, "ibm,plpks-sb-v%hhu", version);
193-
err:
194-
return ret;
198+
/*
199+
* PLPKS dynamic secure boot doesn't give us a format string in the same way
200+
* OPAL does. Instead, report the format using the SB_VERSION variable in the
201+
* keystore. The string, made up by us, takes the form of either
202+
* "ibm,plpks-sb-v<n>" or "ibm,plpks-sb-v0", based on the key management mode,
203+
* and return the length of the secvar format property.
204+
*/
205+
static ssize_t plpks_secvar_format(char *buf, size_t bufsize)
206+
{
207+
u8 mode;
208+
209+
mode = plpks_get_sb_keymgmt_mode();
210+
return snprintf(buf, bufsize, "ibm,plpks-sb-v%hhu", mode);
195211
}
196212

197213
static int plpks_max_size(u64 *max_size)

0 commit comments

Comments
 (0)