Skip to content

Commit fbf355f

Browse files
ssrish17maddy-kerneldev
authored andcommitted
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 <[email protected]> Signed-off-by: Souradeep <[email protected]> Signed-off-by: Srish Srinivasan <[email protected]> Tested-by: R Nageswara Sastry <[email protected]> Reviewed-by: Mimi Zohar <[email protected]> Reviewed-by: Stefan Berger <[email protected]> Reviewed-by: Nayna Jain <[email protected]> Reviewed-by: Andrew Donnellan <[email protected]> Signed-off-by: Madhavan Srinivasan <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 760b9b4 commit fbf355f

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
@@ -152,39 +152,55 @@ static int plpks_set_variable(const char *key, u64 key_len, u8 *data,
152152
return rc;
153153
}
154154

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

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

190206
static int plpks_max_size(u64 *max_size)

0 commit comments

Comments
 (0)