Skip to contentSkip to conversation

Enhancements to the secvar interface in static key management mode

PATCH Superseded Srish Srinivasan 3 participants 20 messages Apr 30, 2025 – May 12, 2025

Subsystems (6)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Enhancements to the secvar interface in static key management mode

The PLPKS enabled Power LPAR sysfs exposes all of the secure boot secure variables irrespective of the key management mode. There is support for both static and dynamic key management and the key management mode can be updated using the management console. The user can modify the secure boot secvars db, dbx, grubdb, grubdbx, and sbat only in the dynamic key mode. But the sysfs interface exposes these secvars even in static key mode. This could lead to errors when reading them or writing to them in the static key mode.

Update the secvar format property based on the key management mode and expose only the secure variables relevant to the key management mode. Enable loading of signed third-party kernel modules in the static key mode when the platform keystore is enabled.

Srish Srinivasan (3):
powerpc/pseries: Correct secvar format representation for static key
management
powerpc/secvar: Expose secvars relevant to the key management mode integrity/platform_certs: Allow loading of keys in static key
management mode

 Documentation/ABI/testing/sysfs-secvar        |  9 +-
 arch/powerpc/platforms/pseries/plpks-secvar.c | 98 ++++++++++++-------
 .../integrity/platform_certs/load_powerpc.c   |  5 +-
 3 files changed, 73 insertions(+), 39 deletions(-)
Signature · 1 line
2.47.1
#1 lore raw

PATCH 1/3 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-v1" or "ibm,plpks-sb-v0" based on the key management mode, and return the length of the secvar format property.

---
 arch/powerpc/platforms/pseries/plpks-secvar.c | 70 +++++++++++--------
 1 file changed, 40 insertions(+), 30 deletions(-)
arch/powerpc/platforms/pseries/plpks-secvar.c +40 -30
index 257fd1f8bc19..d57067a733ab 100644
@@ -152,39 +152,49 @@ static int plpks_set_variable(const char *key, u64 key_len, u8 *data,
 	return rc;
 }
 
-// PLPKS dynamic secure boot doesn't give us a format string in the same way OPAL does.
-// Instead, report the format using the SB_VERSION variable in the keystore.
-// The string is made up by us, and takes the form "ibm,plpks-sb-v<n>" (or "ibm,plpks-sb-unknown"
-// if the SB_VERSION variable doesn't exist). Hypervisor defines the SB_VERSION variable as a
-// "1 byte unsigned integer value".
-static ssize_t plpks_secvar_format(char *buf, size_t bufsize)
+/*
+ * Return the key management mode.
+ *
+ * SB_VERSION is defined as a "1 byte unsigned integer value". It is owned by
+ * the Partition Firmware and its presence indicates that the key management
+ * mode is dynamic. Only signed variables have null bytes in their names.
+ * SB_VERSION does not.
+ *
+ * Return 1 to indicate that the key management mode is dynamic. Otherwise
+ * return 0, indicating that the key management mode is static.
+ */
+static u8 plpks_get_sb_keymgmt_mode(void)
 {
-	struct plpks_var var = {0};
-	ssize_t ret;
-	u8 version;
-
-	var.component = NULL;
-	// Only the signed variables have null bytes in their names, this one doesn't
-	var.name = "SB_VERSION";
-	var.namelen = strlen(var.name);
-	var.datalen = 1;
-	var.data = &version;
-
-	// Unlike the other vars, SB_VERSION is owned by firmware instead of the OS
-	ret = plpks_read_fw_var(&var);
-	if (ret) {
-		if (ret == -ENOENT) {
-			ret = snprintf(buf, bufsize, "ibm,plpks-sb-unknown");
-		} else {
-			pr_err("Error %ld reading SB_VERSION from firmware\n", ret);
-			ret = -EIO;
-		}
-		goto err;
+	u8 mode;
+	ssize_t rc;
+	struct plpks_var var = {
+		.component = NULL,
+		.name = "SB_VERSION",
+		.namelen = 10,
+		.datalen = 1,
+		.data = &mode,
+	};
+
+	rc = plpks_read_fw_var(&var);
+	if (rc) {
+		pr_info("Error %ld reading SB_VERSION from firmware\n", rc);
+		mode = 0;
 	}
+	return mode;
+}
 
-	ret = snprintf(buf, bufsize, "ibm,plpks-sb-v%hhu", version);
-err:
-	return ret;
+// PLPKS dynamic secure boot doesn't give us a format string in the same way
+// OPAL does. Instead, report the format using the SB_VERSION variable in the
+// keystore. The string, made up by us, takes the form "ibm,plpks-sb-v<n>".Set
+// the secvar format property to either "ibm,plpks-sb-v1" or "ibm,plpks-sb-v0",
+// based on the key management mode, and return the length of the secvar format
+// property.
+static ssize_t plpks_secvar_format(char *buf, size_t bufsize)
+{
+	u8 mode;
+
+	mode = plpks_get_sb_keymgmt_mode();
+	return snprintf(buf, bufsize, "ibm,plpks-sb-v%hhu", mode);
 }
 
 static int plpks_max_size(u64 *max_size)
Signature · 1 line
2.47.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] powerpc/pseries: Correct secvar format representation for static key management

Quoted 8 lines · Srish Srinivasan

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.

Quoted 7 lines

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-v1" or "ibm,plpks-sb-v0" based on the key management mode, and return the length of the secvar format property.

Thanks & Regards,
- Nayna

Quoted 94 lines
---
  arch/powerpc/platforms/pseries/plpks-secvar.c | 70 +++++++++++--------
  1 file changed, 40 insertions(+), 30 deletions(-)
arch/powerpc/platforms/pseries/plpks-secvar.c +40 -30
index 257fd1f8bc19..d57067a733ab 100644
@@ -152,39 +152,49 @@ static int plpks_set_variable(const char *key, u64 key_len, u8 *data,
  	return rc;
  }
 
-// PLPKS dynamic secure boot doesn't give us a format string in the same way OPAL does.
-// Instead, report the format using the SB_VERSION variable in the keystore.
-// The string is made up by us, and takes the form "ibm,plpks-sb-v<n>" (or "ibm,plpks-sb-unknown"
-// if the SB_VERSION variable doesn't exist). Hypervisor defines the SB_VERSION variable as a
-// "1 byte unsigned integer value".
-static ssize_t plpks_secvar_format(char *buf, size_t bufsize)
+/*
+ * Return the key management mode.
+ *
+ * SB_VERSION is defined as a "1 byte unsigned integer value". It is owned by
+ * the Partition Firmware and its presence indicates that the key management
+ * mode is dynamic. Only signed variables have null bytes in their names.
+ * SB_VERSION does not.
+ *
+ * Return 1 to indicate that the key management mode is dynamic. Otherwise
+ * return 0, indicating that the key management mode is static.
+ */
+static u8 plpks_get_sb_keymgmt_mode(void)
  {
-	struct plpks_var var = {0};
-	ssize_t ret;
-	u8 version;
-
-	var.component = NULL;
-	// Only the signed variables have null bytes in their names, this one doesn't
-	var.name = "SB_VERSION";
-	var.namelen = strlen(var.name);
-	var.datalen = 1;
-	var.data = &version;
-
-	// Unlike the other vars, SB_VERSION is owned by firmware instead of the OS
-	ret = plpks_read_fw_var(&var);
-	if (ret) {
-		if (ret == -ENOENT) {
-			ret = snprintf(buf, bufsize, "ibm,plpks-sb-unknown");
-		} else {
-			pr_err("Error %ld reading SB_VERSION from firmware\n", ret);
-			ret = -EIO;
-		}
-		goto err;
+	u8 mode;
+	ssize_t rc;
+	struct plpks_var var = {
+		.component = NULL,
+		.name = "SB_VERSION",
+		.namelen = 10,
+		.datalen = 1,
+		.data = &mode,
+	};
+
+	rc = plpks_read_fw_var(&var);
+	if (rc) {
+		pr_info("Error %ld reading SB_VERSION from firmware\n", rc);
+		mode = 0;
  	}
+	return mode;
+}
 
-	ret = snprintf(buf, bufsize, "ibm,plpks-sb-v%hhu", version);
-err:
-	return ret;
+// PLPKS dynamic secure boot doesn't give us a format string in the same way
+// OPAL does. Instead, report the format using the SB_VERSION variable in the
+// keystore. The string, made up by us, takes the form "ibm,plpks-sb-v<n>".Set
+// the secvar format property to either "ibm,plpks-sb-v1" or "ibm,plpks-sb-v0",
+// based on the key management mode, and return the length of the secvar format
+// property.
+static ssize_t plpks_secvar_format(char *buf, size_t bufsize)
+{
+	u8 mode;
+
+	mode = plpks_get_sb_keymgmt_mode();
+	return snprintf(buf, bufsize, "ibm,plpks-sb-v%hhu", mode);
  }
 
  static int plpks_max_size(u64 *max_size)
#3 lore raw

Re: [PATCH 1/3] powerpc/pseries: Correct secvar format representation for static key management

In reply to Srish Srinivasan
Quoted 54 lines · Srish Srinivasan

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-v1" or "ibm,plpks-sb-v0" based on the key management mode, and return the length of the secvar format property.

---
 arch/powerpc/platforms/pseries/plpks-secvar.c | 70 +++++++++++------ --

 1 file changed, 40 insertions(+), 30 deletions(-)
arch/powerpc/platforms/pseries/plpks-secvar.c +0 -0
index 257fd1f8bc19..d57067a733ab 100644
@@ -152,39 +152,49 @@ static int plpks_set_variable(const char *key,
 u64 key_len, u8 *data,
  	return rc;
  }


-// PLPKS dynamic secure boot doesn't give us a format string in the same way OPAL does.
-// Instead, report the format using the SB_VERSION variable in the keystore.
-// The string is made up by us, and takes the form "ibm,plpks-sb- v<n>" (or "ibm,plpks-sb-unknown"
-// if the SB_VERSION variable doesn't exist). Hypervisor defines the SB_VERSION variable as a

arch/powerpc/platforms/pseries/plpks-secvar.c +4 -2
-// "1 byte unsigned integer value".
-static ssize_t plpks_secvar_format(char *buf, size_t bufsize)
+/*
+ * Return the key management mode.
+ *
+ * SB_VERSION is defined as a "1 byte unsigned integer value". It is

owned by
+ * the Partition Firmware and its presence indicates that the key management

Quoted 8 lines

+ * mode is dynamic. Only signed variables have null bytes in their names.
+ * SB_VERSION does not.
+ *
+ * Return 1 to indicate that the key management mode is dynamic. Otherwise
+ * return 0, indicating that the key management mode is static.
+ */

This description isn't accurate.

For dynamic mode, it doesn't return 1, it returns whatever version is defined in SB_VERSION, which could be 1, or could at some later point be a higher version.

Which makes the function name a bit of a misnomer too - it is returning the version number, just the version number can now be zero.

Quoted 40 lines

+static u8 plpks_get_sb_keymgmt_mode(void)
 {

arch/powerpc/platforms/pseries/plpks-secvar.c +0 -6
-	struct plpks_var var = {0};
-	ssize_t ret;
-	u8 version;
-
-	var.component = NULL;
-	// Only the signed variables have null bytes in their names,

this one doesn't

arch/powerpc/platforms/pseries/plpks-secvar.c +0 -6
-	var.name = "SB_VERSION";
-	var.namelen = strlen(var.name);
-	var.datalen = 1;
-	var.data = &version;
-
-	// Unlike the other vars, SB_VERSION is owned by firmware

instead of the OS

arch/powerpc/platforms/pseries/plpks-secvar.c +0 -4
-	ret = plpks_read_fw_var(&var);
-	if (ret) {
-		if (ret == -ENOENT) {
-			ret = snprintf(buf, bufsize, "ibm,plpks-sb-

unknown");

arch/powerpc/platforms/pseries/plpks-secvar.c +0 -2
-		} else {
-			pr_err("Error %ld reading SB_VERSION from

firmware\n", ret);

arch/powerpc/platforms/pseries/plpks-secvar.c +13 -3
-			ret = -EIO;
-		}
-		goto err;
+	u8 mode;
+	ssize_t rc;
+	struct plpks_var var = {
+		.component = NULL,
+		.name = "SB_VERSION",
+		.namelen = 10,
+		.datalen = 1,
+		.data = &mode,
+	};
+
+	rc = plpks_read_fw_var(&var);
+	if (rc) {
+		pr_info("Error %ld reading SB_VERSION from
Quoted 1 line

firmware\n", rc);

We need to check for -ENOENT, otherwise this message is going to be printed every time you boot a machine in static mode.

I think you should handle this as the existing code does: if it's ENOENT, return 0, and for other codes print an error and return -EIO.

Quoted 18 lines
arch/powerpc/platforms/pseries/plpks-secvar.c +1 -0
+		mode = 0;

  }

arch/powerpc/platforms/pseries/plpks-secvar.c +2 -0
+	return mode;
+}

arch/powerpc/platforms/pseries/plpks-secvar.c +1 -3
-	ret = snprintf(buf, bufsize, "ibm,plpks-sb-v%hhu", version);
-err:
-	return ret;
+// PLPKS dynamic secure boot doesn't give us a format string in the

same way
+// OPAL does. Instead, report the format using the SB_VERSION variable in the
+// keystore. The string, made up by us, takes the form "ibm,plpks- sb-v<n>".Set
+// the secvar format property to either "ibm,plpks-sb-v1" or "ibm,plpks-sb-v0",
+// based on the key management mode, and return the length of the secvar format

arch/powerpc/platforms/pseries/plpks-secvar.c static int plpks_set_variable(const char *key, u64 key_len, u8 *data, · line 197

Quoted 7 lines
arch/powerpc/platforms/pseries/plpks-secvar.c +7 -0
+// property.
+static ssize_t plpks_secvar_format(char *buf, size_t bufsize)
+{
+	u8 mode;
+
+	mode = plpks_get_sb_keymgmt_mode();
+	return snprintf(buf, bufsize, "ibm,plpks-sb-v%hhu", mode);

It might be better to use something like "ibm,plpks-sb-static" in place of "ibm,plpks-sb-v0" to make it instantly clear that static mode doesn't use the same version numbering scheme as dynamic mode.

Quoted 3 lines

 }

 static int plpks_max_size(u64 *max_size)

Signature · 2 lines
Andrew Donnellan    OzLabs, ADL Canberra
[email protected]   IBM Australia Limited
#4 lore raw

Re: [PATCH 1/3] powerpc/pseries: Correct secvar format representation for static key management

Quoted 65 lines · Andrew Donnellan
Quoted 54 lines · Srish Srinivasan

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-v1" or "ibm,plpks-sb-v0" based on the key management mode, and return the length of the secvar format property.

---
  arch/powerpc/platforms/pseries/plpks-secvar.c | 70 +++++++++++------
--
  1 file changed, 40 insertions(+), 30 deletions(-)
arch/powerpc/platforms/pseries/plpks-secvar.c +0 -1
index 257fd1f8bc19..d57067a733ab 100644
@@ -152,39 +152,49 @@ static int plpks_set_variable(const char *key,
 u64 key_len, u8 *data,
  	return rc;
  }
 
-// PLPKS dynamic secure boot doesn't give us a format string in the

same way OPAL does.
-// Instead, report the format using the SB_VERSION variable in the keystore.
-// The string is made up by us, and takes the form "ibm,plpks-sb- v<n>" (or "ibm,plpks-sb-unknown"
-// if the SB_VERSION variable doesn't exist). Hypervisor defines the SB_VERSION variable as a

arch/powerpc/platforms/pseries/plpks-secvar.c +4 -2
-// "1 byte unsigned integer value".
-static ssize_t plpks_secvar_format(char *buf, size_t bufsize)
+/*
+ * Return the key management mode.
+ *
+ * SB_VERSION is defined as a "1 byte unsigned integer value". It is

owned by
+ * the Partition Firmware and its presence indicates that the key management

Quoted 8 lines

+ * mode is dynamic. Only signed variables have null bytes in their names.
+ * SB_VERSION does not.
+ *
+ * Return 1 to indicate that the key management mode is dynamic. Otherwise
+ * return 0, indicating that the key management mode is static.
+ */

This description isn't accurate.

Quoted 6 lines

For dynamic mode, it doesn't return 1, it returns whatever version is defined in SB_VERSION, which could be 1, or could at some later point be a higher version.

Which makes the function name a bit of a misnomer too - it is returning the version number, just the version number can now be zero.

Hi Andrew,
Thanks a lot for your feedback.

Thanks for noticing this. Yes, will fix it.

Quoted 36 lines
Quoted 36 lines
arch/powerpc/platforms/pseries/plpks-secvar.c +1 -6
+static u8 plpks_get_sb_keymgmt_mode(void)
  {
-	struct plpks_var var = {0};
-	ssize_t ret;
-	u8 version;
-
-	var.component = NULL;
-	// Only the signed variables have null bytes in their names,

this one doesn't

arch/powerpc/platforms/pseries/plpks-secvar.c +0 -6
-	var.name = "SB_VERSION";
-	var.namelen = strlen(var.name);
-	var.datalen = 1;
-	var.data = &version;
-
-	// Unlike the other vars, SB_VERSION is owned by firmware

instead of the OS

arch/powerpc/platforms/pseries/plpks-secvar.c +0 -4
-	ret = plpks_read_fw_var(&var);
-	if (ret) {
-		if (ret == -ENOENT) {
-			ret = snprintf(buf, bufsize, "ibm,plpks-sb-

unknown");

arch/powerpc/platforms/pseries/plpks-secvar.c +0 -2
-		} else {
-			pr_err("Error %ld reading SB_VERSION from

firmware\n", ret);

arch/powerpc/platforms/pseries/plpks-secvar.c +8 -3
-			ret = -EIO;
-		}
-		goto err;
+	u8 mode;
+	ssize_t rc;
+	struct plpks_var var = {
+		.component = NULL,
+		.name = "SB_VERSION",
+		.namelen = 10,
+		.datalen = 1,
+		.data = &mode,
Quoted 8 lines
Quoted 6 lines
arch/powerpc/platforms/pseries/plpks-secvar.c +5 -0
+	};
+
+	rc = plpks_read_fw_var(&var);
+	if (rc) {
+		pr_info("Error %ld reading SB_VERSION from

firmware\n", rc);

We need to check for -ENOENT, otherwise this message is going to be printed every time you boot a machine in static mode.

Yes, I agree with your concern. I just want to add that, as per my understanding, we need to check for both -ENOENT and -EPERM, as explained below:

As per H_PKS_READ_OBJECT semantics described in the PAPR v10.60 (https://files.openpower.foundation/s/XFgfMaqLMD5Bcm8),

* If the object is not world readable, verify that the consumer password matches the stored value in the hypervisor. Else return H_AUTHORITY.
* Verify if the object exists, else return H_NOT_FOUND.
* Verify if the policy for the object is met, else return H_AUTHORITY.

So, the hypervisor returns H_NOT_FOUND only for the authenticated consumer. For unauthenticated consumers, which is the case here, it would return H_AUTHORITY.

Quoted 2 lines

I think you should handle this as the existing code does: if it's ENOENT, return 0, and for other codes print an error and return -EIO.

Currently, the other layers in the boot stack assume static key mode for any failure in reading SB_VERSION. We added the same interpretation in the kernel to keep it consistent with the other layers, and represent the same to the user. This is the reason for not parsing the error codes when trying to read SB_VERSION, and defaulting to the static key management mode. However, we want the exact error code to be logged for debugging purposes. And, it does make sense to have logging only for error codes other than -ENOENT and -EPERM, as you suggested. Does this sound okay?

Quoted 21 lines
Quoted 21 lines
arch/powerpc/platforms/pseries/plpks-secvar.c +4 -3
+		mode = 0;
  	}
+	return mode;
+}
 
-	ret = snprintf(buf, bufsize, "ibm,plpks-sb-v%hhu", version);
-err:
-	return ret;
+// PLPKS dynamic secure boot doesn't give us a format string in the

same way
+// OPAL does. Instead, report the format using the SB_VERSION variable in the
+// keystore. The string, made up by us, takes the form "ibm,plpks- sb-v<n>".Set
+// the secvar format property to either "ibm,plpks-sb-v1" or "ibm,plpks-sb-v0",
+// based on the key management mode, and return the length of the secvar format

arch/powerpc/platforms/pseries/plpks-secvar.c +2 -0
+// property.
+static ssize_t plpks_secvar_format(char *buf, size_t bufsize)
Quoted 8 lines

arch/powerpc/platforms/pseries/plpks-secvar.c static int plpks_set_variable(const char *key, u64 key_len, u8 *data, · line 197

Quoted 5 lines
arch/powerpc/platforms/pseries/plpks-secvar.c +5 -0
+{
+	u8 mode;
+
+	mode = plpks_get_sb_keymgmt_mode();
+	return snprintf(buf, bufsize, "ibm,plpks-sb-v%hhu", mode);

It might be better to use something like "ibm,plpks-sb-static" in place of "ibm,plpks-sb-v0" to make it instantly clear that static mode doesn't use the same version numbering scheme as dynamic mode.

Sure.

Thanks and Regards,
Srish

Quoted 4 lines
Quoted 4 lines

 }

 static int plpks_max_size(u64 *max_size)

#5 lore raw

Re: [PATCH 1/3] powerpc/pseries: Correct secvar format representation for static key management

Quoted 20 lines · Srish Srinivasan
Quoted 6 lines
Quoted 4 lines
arch/powerpc/platforms/pseries/plpks-secvar.c +3 -0
+	rc = plpks_read_fw_var(&var);
+	if (rc) {
+		pr_info("Error %ld reading SB_VERSION from

firmware\n", rc);

We need to check for -ENOENT, otherwise this message is going to be printed every time you boot a machine in static mode.

Yes, I agree with your concern. I just want to add that, as per my understanding, we need to check for both -ENOENT and -EPERM, as explained below:

As per H_PKS_READ_OBJECT semantics described in the PAPR v10.60
(https://files.openpower.foundation/s/XFgfMaqLMD5Bcm8),

* If the object is not world readable, verify that the consumer password
matches the stored value in the hypervisor. Else return H_AUTHORITY.
* Verify if the object exists, else return H_NOT_FOUND.
* Verify if the policy for the object is met, else return H_AUTHORITY.

Quoted 3 lines

So, the hypervisor returns H_NOT_FOUND only for the authenticated consumer. For unauthenticated consumers, which is the case here, it would return H_AUTHORITY.

We expect SB_VERSION to always be world-readable, I think? In which case it shouldn't return H_AUTHORITY / -EPERM, ever, and if it does that's an error which should be handled as an error. Or am I misinterpreting the spec here?

Signature · 2 lines
Andrew Donnellan    OzLabs, ADL Canberra
[email protected]   IBM Australia Limited
#6 lore raw

Re: [PATCH 1/3] powerpc/pseries: Correct secvar format representation for static key management

Quoted 21 lines · Andrew Donnellan
Quoted 20 lines · Srish Srinivasan
Quoted 6 lines
Quoted 4 lines
arch/powerpc/platforms/pseries/plpks-secvar.c +3 -0
+	rc = plpks_read_fw_var(&var);
+	if (rc) {
+		pr_info("Error %ld reading SB_VERSION from

firmware\n", rc);

We need to check for -ENOENT, otherwise this message is going to be printed every time you boot a machine in static mode.

Yes, I agree with your concern. I just want to add that, as per my understanding, we need to check for both -ENOENT and -EPERM, as explained below:

As per H_PKS_READ_OBJECT semantics described in the PAPR v10.60
(https://files.openpower.foundation/s/XFgfMaqLMD5Bcm8),

* If the object is not world readable, verify that the consumer password
matches the stored value in the hypervisor. Else return H_AUTHORITY.
* Verify if the object exists, else return H_NOT_FOUND.
* Verify if the policy for the object is met, else return H_AUTHORITY.

Quoted 7 lines
Quoted 3 lines

So, the hypervisor returns H_NOT_FOUND only for the authenticated consumer. For unauthenticated consumers, which is the case here, it would return H_AUTHORITY.

We expect SB_VERSION to always be world-readable, I think? In which case it shouldn't return H_AUTHORITY / -EPERM, ever, and if it does that's an error which should be handled as an error. Or am I misinterpreting the spec here?

Yes, SB_VERSION is world-readable and should not return H_AUTHORITY in the case of dynamic key management mode. However, in the case of static key management mode, when SB_VERSION does not exist, the hypervisor tries to authenticate the consumer. If the authentication is successful, H_NOT_FOUND is returned, else H_AUTHORITY is returned. The intention behind authenticating the consumer when the object is not found is to ensure that a non-authenticated consumer is unable to conclude on the absence of the object. Here, when the kernel tries to read the non-existent SB_VERSION, it fails the authentication check and therefore, gets the H_AUTHORITY error code.

Quoted 2 lines
#7 lore raw

Re: [PATCH 1/3] powerpc/pseries: Correct secvar format representation for static key management

Quoted 5 lines · Srish Srinivasan
Quoted 4 lines

We expect SB_VERSION to always be world-readable, I think? In which case it shouldn't return H_AUTHORITY / -EPERM, ever, and if it does that's an error which should be handled as an error. Or am I misinterpreting the spec here?

Quoted 14 lines

Yes, SB_VERSION is world-readable and should not return H_AUTHORITY in
the case of dynamic key management mode. However, in
the case of static key management mode, when SB_VERSION does not exist,
the hypervisor tries to authenticate the consumer. If the authentication is successful, H_NOT_FOUND is returned, else H_AUTHORITY
is returned. The intention behind authenticating the consumer when the object is not found is to ensure that a non-authenticated consumer is unable to conclude on the absence of the object. Here, when the kernel tries to read the non-existent SB_VERSION, it fails the authentication check and therefore, gets the H_AUTHORITY error code.

Ah, I see my confusion: if the object *doesn't exist*, then it obviously can't be a world-readable object, thus triggering the password verification. In which case, we do need to catch -EPERM.

Thanks for correcting me!

Signature · 2 lines
Andrew Donnellan    OzLabs, ADL Canberra
[email protected]   IBM Australia Limited
#8 lore raw

Re: [PATCH 1/3] powerpc/pseries: Correct secvar format representation for static key management

In reply to Srish Srinivasan
Quoted 16 lines · Srish Srinivasan
Quoted 3 lines

I think you should handle this as the existing code does: if it's ENOENT, return 0, and for other codes print an error and return - EIO.

Currently, the other layers in the boot stack assume static key mode for
any failure in reading SB_VERSION. We added the same interpretation in the kernel to keep it consistent with the other layers, and represent
the same to the user. This is the reason for not parsing the error codes
when trying to read SB_VERSION, and defaulting to the static key management mode. However, we want the exact error code to be logged for debugging purposes. And, it does make sense to have logging only for
error codes other than -ENOENT and -EPERM, as you suggested. Does this sound okay?

Okay, maybe document explicitly in a comment that we default to static mode in the event of any weird errors.

Signature · 2 lines
Andrew Donnellan    OzLabs, ADL Canberra
[email protected]   IBM Australia Limited
#9 lore raw

Re: [PATCH 1/3] powerpc/pseries: Correct secvar format representation for static key management

Quoted 17 lines · Andrew Donnellan
Quoted 16 lines · Srish Srinivasan
Quoted 3 lines

I think you should handle this as the existing code does: if it's ENOENT, return 0, and for other codes print an error and return - EIO.

Currently, the other layers in the boot stack assume static key mode for
any failure in reading SB_VERSION. We added the same interpretation in the kernel to keep it consistent with the other layers, and represent
the same to the user. This is the reason for not parsing the error codes
when trying to read SB_VERSION, and defaulting to the static key management mode. However, we want the exact error code to be logged for debugging purposes. And, it does make sense to have logging only for
error codes other than -ENOENT and -EPERM, as you suggested. Does this sound okay?

Quoted 2 lines

Okay, maybe document explicitly in a comment that we default to static mode in the event of any weird errors.

Sure, will do that.
Thank You.

Quoted 1 line
#10 lore raw

Re: [PATCH 1/3] powerpc/pseries: Correct secvar format representation for static key management

In reply to Andrew Donnellan
Quoted 139 lines · Andrew Donnellan
Quoted 54 lines · Srish Srinivasan

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-v1" or "ibm,plpks-sb-v0" based on the key management mode, and return the length of the secvar format property.

---
  arch/powerpc/platforms/pseries/plpks-secvar.c | 70 +++++++++++------
--
  1 file changed, 40 insertions(+), 30 deletions(-)
arch/powerpc/platforms/pseries/plpks-secvar.c +0 -1
index 257fd1f8bc19..d57067a733ab 100644
@@ -152,39 +152,49 @@ static int plpks_set_variable(const char *key,
 u64 key_len, u8 *data,
  	return rc;
  }
 
-// PLPKS dynamic secure boot doesn't give us a format string in the

same way OPAL does.
-// Instead, report the format using the SB_VERSION variable in the keystore.
-// The string is made up by us, and takes the form "ibm,plpks-sb- v<n>" (or "ibm,plpks-sb-unknown"
-// if the SB_VERSION variable doesn't exist). Hypervisor defines the SB_VERSION variable as a

arch/powerpc/platforms/pseries/plpks-secvar.c +4 -2
-// "1 byte unsigned integer value".
-static ssize_t plpks_secvar_format(char *buf, size_t bufsize)
+/*
+ * Return the key management mode.
+ *
+ * SB_VERSION is defined as a "1 byte unsigned integer value". It is

owned by
+ * the Partition Firmware and its presence indicates that the key management

Quoted 8 lines

+ * mode is dynamic. Only signed variables have null bytes in their names.
+ * SB_VERSION does not.
+ *
+ * Return 1 to indicate that the key management mode is dynamic. Otherwise
+ * return 0, indicating that the key management mode is static.
+ */

This description isn't accurate.

For dynamic mode, it doesn't return 1, it returns whatever version is defined in SB_VERSION, which could be 1, or could at some later point be a higher version.

Which makes the function name a bit of a misnomer too - it is returning the version number, just the version number can now be zero.

Quoted 40 lines
arch/powerpc/platforms/pseries/plpks-secvar.c +1 -6
+static u8 plpks_get_sb_keymgmt_mode(void)
  {
-	struct plpks_var var = {0};
-	ssize_t ret;
-	u8 version;
-
-	var.component = NULL;
-	// Only the signed variables have null bytes in their names,

this one doesn't

arch/powerpc/platforms/pseries/plpks-secvar.c +0 -6
-	var.name = "SB_VERSION";
-	var.namelen = strlen(var.name);
-	var.datalen = 1;
-	var.data = &version;
-
-	// Unlike the other vars, SB_VERSION is owned by firmware

instead of the OS

arch/powerpc/platforms/pseries/plpks-secvar.c +0 -4
-	ret = plpks_read_fw_var(&var);
-	if (ret) {
-		if (ret == -ENOENT) {
-			ret = snprintf(buf, bufsize, "ibm,plpks-sb-

unknown");

arch/powerpc/platforms/pseries/plpks-secvar.c +0 -2
-		} else {
-			pr_err("Error %ld reading SB_VERSION from

firmware\n", ret);

arch/powerpc/platforms/pseries/plpks-secvar.c +13 -3
-			ret = -EIO;
-		}
-		goto err;
+	u8 mode;
+	ssize_t rc;
+	struct plpks_var var = {
+		.component = NULL,
+		.name = "SB_VERSION",
+		.namelen = 10,
+		.datalen = 1,
+		.data = &mode,
+	};
+
+	rc = plpks_read_fw_var(&var);
+	if (rc) {
+		pr_info("Error %ld reading SB_VERSION from
Quoted 1 line

firmware\n", rc);

We need to check for -ENOENT, otherwise this message is going to be printed every time you boot a machine in static mode.

I think you should handle this as the existing code does: if it's ENOENT, return 0, and for other codes print an error and return -EIO.

Quoted 20 lines
arch/powerpc/platforms/pseries/plpks-secvar.c +4 -3
+		mode = 0;
  	}
+	return mode;
+}
 
-	ret = snprintf(buf, bufsize, "ibm,plpks-sb-v%hhu", version);
-err:
-	return ret;
+// PLPKS dynamic secure boot doesn't give us a format string in the

same way
+// OPAL does. Instead, report the format using the SB_VERSION variable in the
+// keystore. The string, made up by us, takes the form "ibm,plpks- sb-v<n>".Set
+// the secvar format property to either "ibm,plpks-sb-v1" or "ibm,plpks-sb-v0",
+// based on the key management mode, and return the length of the secvar format

arch/powerpc/platforms/pseries/plpks-secvar.c +2 -0
+// property.
+static ssize_t plpks_secvar_format(char *buf, size_t bufsize)
Quoted 8 lines

arch/powerpc/platforms/pseries/plpks-secvar.c static int plpks_set_variable(const char *key, u64 key_len, u8 *data, · line 197

Quoted 5 lines
arch/powerpc/platforms/pseries/plpks-secvar.c +5 -0
+{
+	u8 mode;
+
+	mode = plpks_get_sb_keymgmt_mode();
+	return snprintf(buf, bufsize, "ibm,plpks-sb-v%hhu", mode);

It might be better to use something like "ibm,plpks-sb-static" in place of "ibm,plpks-sb-v0" to make it instantly clear that static mode doesn't use the same version numbering scheme as dynamic mode.

Yes, "ibm,plpks-sb-static" is more clear compared to "ibm,plpks-sb-v0".  However, I am not sure why "static mode doesn't use the same version numbering scheme as dynamic mode". Infact, as per my understanding,  it is part of same versioning system. "0 represent static, 1 represent dynamic and anything beyond 1 would mean dynamic with additional features".

Also, wouldn't having "ibm,pkpks-sb-static" and then "ibm,pkpk-sb-v1" for dynamic would be bit confusing? I mean being static is clear, but what they relate v1 to? Or did you mean to have "ibm,plpks-sb-static" and "ibm,plpks-sb-dynamic"  for the two modes?

Thanks & Regards,
         - Nayna

#11 lore raw

Re: [PATCH 1/3] powerpc/pseries: Correct secvar format representation for static key management

Quoted 15 lines · Nayna Jain
Quoted 5 lines

It might be better to use something like "ibm,plpks-sb-static" in place
of "ibm,plpks-sb-v0" to make it instantly clear that static mode doesn't use the same version numbering scheme as dynamic mode.

Yes, "ibm,plpks-sb-static" is more clear compared to "ibm,plpks-sb- v0".
However, I am not sure why "static mode doesn't use the same version numbering scheme as dynamic mode". Infact, as per my understanding, it
is part of same versioning system. "0 represent static, 1 represent dynamic and anything beyond 1 would mean dynamic with additional features".

Quoted 5 lines

Also, wouldn't having "ibm,pkpks-sb-static" and then "ibm,pkpk-sb-v1" for dynamic would be bit confusing? I mean being static is clear, but what they relate v1 to? Or did you mean to have "ibm,plpks-sb-static" and "ibm,plpks-sb-dynamic"  for the two modes?

I don't feel strongly about this, as long as it's well documented.

Signature · 2 lines
Andrew Donnellan    OzLabs, ADL Canberra
[email protected]   IBM Australia Limited
#12 lore raw

PATCH 2/3 powerpc/secvar: Expose secvars relevant to the key management mode

In reply to Srish Srinivasan

The PLPKS enabled PowerVM LPAR sysfs exposes all of the secure boot secvars irrespective of the key management mode.

The PowerVM LPAR supports static and dynamic key management for secure boot. The key management option can be updated in the management console. Only in the dynamic key mode can the user modify the secure boot secvars db, dbx, grubdb, grubdbx, and sbat, which are exposed via the sysfs interface. But the sysfs interface exposes these secvars even in the static key mode. This could lead to errors when reading them or writing to them in the static key mode.

Expose only PK, trustedcadb, and moduledb in the static key mode to enable loading of signed third-party kernel modules.

---
 Documentation/ABI/testing/sysfs-secvar        |  9 ++++--
 arch/powerpc/platforms/pseries/plpks-secvar.c | 28 ++++++++++++++++---
 2 files changed, 30 insertions(+), 7 deletions(-)
Documentation/ABI/testing/sysfs-secvar +6 -3
index 857cf12b0904..2bdc7d9c0c10 100644
@@ -22,9 +22,12 @@ Description:	A string indicating which backend is in use by the firmware.
 		and is expected to be "ibm,edk2-compat-v1".
 
 		On pseries/PLPKS, this is generated by the kernel based on the
-		version number in the SB_VERSION variable in the keystore, and
-		has the form "ibm,plpks-sb-v<version>", or
-		"ibm,plpks-sb-unknown" if there is no SB_VERSION variable.
+		existence of the SB_VERSION property in firmware. This string
+		takes the form "ibm,plpks-sb-v1" in the presence of SB_VERSION,
+		indicating the key management mode is dynamic. Otherwise it
+		takes the form "ibm,plpks-sb-v0" in the static key management
+		mode. Only secvars relevant to the key management mode are
+		exposed.
 
 What:		/sys/firmware/secvar/vars/<variable name>
 Date:		August 2019
arch/powerpc/platforms/pseries/plpks-secvar.c +24 -4
index d57067a733ab..cbcb2c356f2a 100644
@@ -59,7 +59,14 @@ static u32 get_policy(const char *name)
 		return PLPKS_SIGNEDUPDATE;
 }
 
-static const char * const plpks_var_names[] = {
+static const char * const plpks_var_names_static[] = {
+	"PK",
+	"moduledb",
+	"trustedcadb",
+	NULL,
+};
+
+static const char * const plpks_var_names_dynamic[] = {
 	"PK",
 	"KEK",
 	"db",
@@ -207,21 +214,34 @@ static int plpks_max_size(u64 *max_size)
 	return 0;
 }
 
+static const struct secvar_operations plpks_secvar_ops_static = {
+	.get = plpks_get_variable,
+	.set = plpks_set_variable,
+	.format = plpks_secvar_format,
+	.max_size = plpks_max_size,
+	.config_attrs = config_attrs,
+	.var_names = plpks_var_names_static,
+};
 
-static const struct secvar_operations plpks_secvar_ops = {
+static const struct secvar_operations plpks_secvar_ops_dynamic = {
 	.get = plpks_get_variable,
 	.set = plpks_set_variable,
 	.format = plpks_secvar_format,
 	.max_size = plpks_max_size,
 	.config_attrs = config_attrs,
-	.var_names = plpks_var_names,
+	.var_names = plpks_var_names_dynamic,
 };
 
 static int plpks_secvar_init(void)
 {
+	u8 mode;
+
 	if (!plpks_is_available())
 		return -ENODEV;
 
-	return set_secvar_ops(&plpks_secvar_ops);
+	mode = plpks_get_sb_keymgmt_mode();
+	if (mode)
+		return set_secvar_ops(&plpks_secvar_ops_dynamic);
+	return set_secvar_ops(&plpks_secvar_ops_static);
 }
 machine_device_initcall(pseries, plpks_secvar_init);
Signature · 1 line
2.47.1
Reviewed-by on v1 2/3
#13 lore raw

Re: [PATCH 2/3] powerpc/secvar: Expose secvars relevant to the key management mode

Quoted 11 lines · Srish Srinivasan

The PLPKS enabled PowerVM LPAR sysfs exposes all of the secure boot secvars irrespective of the key management mode.

The PowerVM LPAR supports static and dynamic key management for secure boot. The key management option can be updated in the management console. Only in the dynamic key mode can the user modify the secure boot secvars db, dbx, grubdb, grubdbx, and sbat, which are exposed via the sysfs interface. But the sysfs interface exposes these secvars even in the static key mode. This could lead to errors when reading them or writing to them in the static key mode.

Quoted 2 lines

Expose only PK, trustedcadb, and moduledb in the static key mode to enable loading of signed third-party kernel modules.

Thanks & Regards,
- Nayna

Quoted 89 lines
---
  Documentation/ABI/testing/sysfs-secvar        |  9 ++++--
  arch/powerpc/platforms/pseries/plpks-secvar.c | 28 ++++++++++++++++---
  2 files changed, 30 insertions(+), 7 deletions(-)
Documentation/ABI/testing/sysfs-secvar +6 -3
index 857cf12b0904..2bdc7d9c0c10 100644
@@ -22,9 +22,12 @@ Description:	A string indicating which backend is in use by the firmware.
  		and is expected to be "ibm,edk2-compat-v1".
 
  		On pseries/PLPKS, this is generated by the kernel based on the
-		version number in the SB_VERSION variable in the keystore, and
-		has the form "ibm,plpks-sb-v<version>", or
-		"ibm,plpks-sb-unknown" if there is no SB_VERSION variable.
+		existence of the SB_VERSION property in firmware. This string
+		takes the form "ibm,plpks-sb-v1" in the presence of SB_VERSION,
+		indicating the key management mode is dynamic. Otherwise it
+		takes the form "ibm,plpks-sb-v0" in the static key management
+		mode. Only secvars relevant to the key management mode are
+		exposed.
 
  What:		/sys/firmware/secvar/vars/<variable name>
  Date:		August 2019
arch/powerpc/platforms/pseries/plpks-secvar.c +24 -4
index d57067a733ab..cbcb2c356f2a 100644
@@ -59,7 +59,14 @@ static u32 get_policy(const char *name)
  		return PLPKS_SIGNEDUPDATE;
  }
 
-static const char * const plpks_var_names[] = {
+static const char * const plpks_var_names_static[] = {
+	"PK",
+	"moduledb",
+	"trustedcadb",
+	NULL,
+};
+
+static const char * const plpks_var_names_dynamic[] = {
  	"PK",
  	"KEK",
  	"db",
@@ -207,21 +214,34 @@ static int plpks_max_size(u64 *max_size)
  	return 0;
  }
 
+static const struct secvar_operations plpks_secvar_ops_static = {
+	.get = plpks_get_variable,
+	.set = plpks_set_variable,
+	.format = plpks_secvar_format,
+	.max_size = plpks_max_size,
+	.config_attrs = config_attrs,
+	.var_names = plpks_var_names_static,
+};
 
-static const struct secvar_operations plpks_secvar_ops = {
+static const struct secvar_operations plpks_secvar_ops_dynamic = {
  	.get = plpks_get_variable,
  	.set = plpks_set_variable,
  	.format = plpks_secvar_format,
  	.max_size = plpks_max_size,
  	.config_attrs = config_attrs,
-	.var_names = plpks_var_names,
+	.var_names = plpks_var_names_dynamic,
  };
 
  static int plpks_secvar_init(void)
  {
+	u8 mode;
+
  	if (!plpks_is_available())
  		return -ENODEV;
 
-	return set_secvar_ops(&plpks_secvar_ops);
+	mode = plpks_get_sb_keymgmt_mode();
+	if (mode)
+		return set_secvar_ops(&plpks_secvar_ops_dynamic);
+	return set_secvar_ops(&plpks_secvar_ops_static);
  }
  machine_device_initcall(pseries, plpks_secvar_init);
Reviewed-by on v1 2/3
#14 lore raw

Re: [PATCH 2/3] powerpc/secvar: Expose secvars relevant to the key management mode

In reply to Srish Srinivasan
Quoted 15 lines · Srish Srinivasan

The PLPKS enabled PowerVM LPAR sysfs exposes all of the secure boot secvars irrespective of the key management mode.

The PowerVM LPAR supports static and dynamic key management for secure
boot. The key management option can be updated in the management console. Only in the dynamic key mode can the user modify the secure boot secvars db, dbx, grubdb, grubdbx, and sbat, which are exposed via
the sysfs interface. But the sysfs interface exposes these secvars even
in the static key mode. This could lead to errors when reading them or
writing to them in the static key mode.

Quoted 8 lines

Expose only PK, trustedcadb, and moduledb in the static key mode to enable loading of signed third-party kernel modules.

I'm assuming it's been determined that there's no value in letting userspace see db/dbx/etc in a read-only way in static mode?

With one comment below:

Quoted 32 lines

---
 Documentation/ABI/testing/sysfs-secvar        |  9 ++++-- arch/powerpc/platforms/pseries/plpks-secvar.c | 28 ++++++++++++++++- --

 2 files changed, 30 insertions(+), 7 deletions(-)
Documentation/ABI/testing/sysfs-secvar +0 -0
index 857cf12b0904..2bdc7d9c0c10 100644
@@ -22,9 +22,12 @@ Description:	A string indicating which backend is

in use by the firmware.
  and is expected to be "ibm,edk2-compat-v1".
  On pseries/PLPKS, this is generated by the kernel based on the

Documentation/ABI/testing/sysfs-secvar +0 -1
-		version number in the SB_VERSION variable in the

keystore, and

Documentation/ABI/testing/sysfs-secvar +0 -2
-		has the form "ibm,plpks-sb-v<version>", or
-		"ibm,plpks-sb-unknown" if there is no SB_VERSION

variable.

Documentation/ABI/testing/sysfs-secvar +1 -0
+		existence of the SB_VERSION property in firmware.

This string

Documentation/ABI/testing/sysfs-secvar +1 -0
+		takes the form "ibm,plpks-sb-v1" in the presence of

SB_VERSION,

Documentation/ABI/testing/sysfs-secvar +1 -0
+		indicating the key management mode is dynamic.

Otherwise it

Documentation/ABI/testing/sysfs-secvar +1 -0
+		takes the form "ibm,plpks-sb-v0" in the static key

management

Documentation/ABI/testing/sysfs-secvar +1 -0
+		mode. Only secvars relevant to the key management

mode are

Documentation/ABI/testing/sysfs-secvar Description: A string indicating which backend is in use by the firmware. · line 30

Quoted 1 line
Documentation/ABI/testing/sysfs-secvar +1 -0
+		exposed.

Everything except the last sentence here is relevant to the previous patch in the series (noting my comments on the previous patch about the string).

The last sentence is more related to the <variable name> entry than the format entry, and perhaps worth including a list of what variables are applicable to each mode.

Quoted 62 lines


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

arch/powerpc/platforms/pseries/plpks-secvar.c +0 -0
index d57067a733ab..cbcb2c356f2a 100644
@@ -59,7 +59,14 @@ static u32 get_policy(const char *name)
  		return PLPKS_SIGNEDUPDATE;
  }

arch/powerpc/platforms/pseries/plpks-secvar.c +8 -1
-static const char * const plpks_var_names[] = {
+static const char * const plpks_var_names_static[] = {
+	"PK",
+	"moduledb",
+	"trustedcadb",
+	NULL,
+};
+
+static const char * const plpks_var_names_dynamic[] = {

  "PK",
  "KEK",
  "db",

arch/powerpc/platforms/pseries/plpks-secvar.c +0 -0
@@ -207,21 +214,34 @@ static int plpks_max_size(u64 *max_size)
  	return 0;
  }

arch/powerpc/platforms/pseries/plpks-secvar.c +8 -0
+static const struct secvar_operations plpks_secvar_ops_static = {
+	.get = plpks_get_variable,
+	.set = plpks_set_variable,
+	.format = plpks_secvar_format,
+	.max_size = plpks_max_size,
+	.config_attrs = config_attrs,
+	.var_names = plpks_var_names_static,
+};

arch/powerpc/platforms/pseries/plpks-secvar.c +1 -1
-static const struct secvar_operations plpks_secvar_ops = {
+static const struct secvar_operations plpks_secvar_ops_dynamic = {

  .get = plpks_get_variable,
  .set = plpks_set_variable,
  .format = plpks_secvar_format,
  .max_size = plpks_max_size,
  .config_attrs = config_attrs,

arch/powerpc/platforms/pseries/plpks-secvar.c +1 -1
-	.var_names = plpks_var_names,
+	.var_names = plpks_var_names_dynamic,

 };

 static int plpks_secvar_init(void)
 {

arch/powerpc/platforms/pseries/plpks-secvar.c +2 -0
+	u8 mode;
+

  if (!plpks_is_available())
  return -ENODEV;

arch/powerpc/platforms/pseries/plpks-secvar.c +4 -1
-	return set_secvar_ops(&plpks_secvar_ops);
+	mode = plpks_get_sb_keymgmt_mode();
+	if (mode)
+		return set_secvar_ops(&plpks_secvar_ops_dynamic);
+	return set_secvar_ops(&plpks_secvar_ops_static);

 }
 machine_device_initcall(pseries, plpks_secvar_init);

Signature · 2 lines
Andrew Donnellan    OzLabs, ADL Canberra
[email protected]   IBM Australia Limited
#15 lore raw

Re: [PATCH 2/3] powerpc/secvar: Expose secvars relevant to the key management mode

Quoted 24 lines · Andrew Donnellan
Quoted 15 lines · Srish Srinivasan

The PLPKS enabled PowerVM LPAR sysfs exposes all of the secure boot secvars irrespective of the key management mode.

The PowerVM LPAR supports static and dynamic key management for secure
boot. The key management option can be updated in the management console. Only in the dynamic key mode can the user modify the secure boot secvars db, dbx, grubdb, grubdbx, and sbat, which are exposed via
the sysfs interface. But the sysfs interface exposes these secvars even
in the static key mode. This could lead to errors when reading them or
writing to them in the static key mode.

Quoted 8 lines

Expose only PK, trustedcadb, and moduledb in the static key mode to enable loading of signed third-party kernel modules.

Quoted 6 lines

I'm assuming it's been determined that there's no value in letting userspace see db/dbx/etc in a read-only way in static mode?

With one comment below:

Hi Andrew,
Thanks a lot for your feedback.

Yes, that is correct.

Quoted 37 lines
Quoted 32 lines
---
  Documentation/ABI/testing/sysfs-secvar        |  9 ++++--
  arch/powerpc/platforms/pseries/plpks-secvar.c | 28 ++++++++++++++++-
--
  2 files changed, 30 insertions(+), 7 deletions(-)
Documentation/ABI/testing/sysfs-secvar +0 -0
index 857cf12b0904..2bdc7d9c0c10 100644
@@ -22,9 +22,12 @@ Description:	A string indicating which backend is

in use by the firmware.
  and is expected to be "ibm,edk2-compat-v1".

  On pseries/PLPKS, this is generated by the kernel
based on the

Documentation/ABI/testing/sysfs-secvar +0 -1
-		version number in the SB_VERSION variable in the

keystore, and

Documentation/ABI/testing/sysfs-secvar +0 -2
-		has the form "ibm,plpks-sb-v<version>", or
-		"ibm,plpks-sb-unknown" if there is no SB_VERSION

variable.

Documentation/ABI/testing/sysfs-secvar +1 -0
+		existence of the SB_VERSION property in firmware.

This string

Documentation/ABI/testing/sysfs-secvar +1 -0
+		takes the form "ibm,plpks-sb-v1" in the presence of

SB_VERSION,

Documentation/ABI/testing/sysfs-secvar +1 -0
+		indicating the key management mode is dynamic.

Otherwise it

Documentation/ABI/testing/sysfs-secvar +1 -0
+		takes the form "ibm,plpks-sb-v0" in the static key

management

Documentation/ABI/testing/sysfs-secvar +1 -0
+		mode. Only secvars relevant to the key management

mode are

Documentation/ABI/testing/sysfs-secvar Description: A string indicating which backend is in use by the firmware. · line 30

Quoted 1 line
Documentation/ABI/testing/sysfs-secvar +1 -0
+		exposed.

Everything except the last sentence here is relevant to the previous patch in the series (noting my comments on the previous patch about the string).

Quoted 3 lines

The last sentence is more related to the <variable name> entry than the format entry, and perhaps worth including a list of what variables are applicable to each mode.

Sure, will fix this.

Thanks and Regards,
Srish

Quoted 63 lines
Quoted 63 lines

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

arch/powerpc/platforms/pseries/plpks-secvar.c +24 -4
index d57067a733ab..cbcb2c356f2a 100644
@@ -59,7 +59,14 @@ static u32 get_policy(const char *name)
  		return PLPKS_SIGNEDUPDATE;
  }
 
-static const char * const plpks_var_names[] = {
+static const char * const plpks_var_names_static[] = {
+	"PK",
+	"moduledb",
+	"trustedcadb",
+	NULL,
+};
+
+static const char * const plpks_var_names_dynamic[] = {
  	"PK",
  	"KEK",
  	"db",
@@ -207,21 +214,34 @@ static int plpks_max_size(u64 *max_size)
  	return 0;
  }
 
+static const struct secvar_operations plpks_secvar_ops_static = {
+	.get = plpks_get_variable,
+	.set = plpks_set_variable,
+	.format = plpks_secvar_format,
+	.max_size = plpks_max_size,
+	.config_attrs = config_attrs,
+	.var_names = plpks_var_names_static,
+};
 
-static const struct secvar_operations plpks_secvar_ops = {
+static const struct secvar_operations plpks_secvar_ops_dynamic = {
  	.get = plpks_get_variable,
  	.set = plpks_set_variable,
  	.format = plpks_secvar_format,
  	.max_size = plpks_max_size,
  	.config_attrs = config_attrs,
-	.var_names = plpks_var_names,
+	.var_names = plpks_var_names_dynamic,
  };
 
  static int plpks_secvar_init(void)
  {
+	u8 mode;
+
  	if (!plpks_is_available())
  		return -ENODEV;
 
-	return set_secvar_ops(&plpks_secvar_ops);
+	mode = plpks_get_sb_keymgmt_mode();
+	if (mode)
+		return set_secvar_ops(&plpks_secvar_ops_dynamic);
+	return set_secvar_ops(&plpks_secvar_ops_static);
  }
  machine_device_initcall(pseries, plpks_secvar_init);
#16 lore raw

PATCH 3/3 integrity/platform_certs: Allow loading of keys in static key management mode

In reply to Srish Srinivasan

On PLPKS enabled PowerVM LPAR, there is no provision to load signed third-party kernel modules when the key management mode is static. This is because keys from secure boot secvars are only loaded when the key management mode is dynamic.

Allow loading of the trustedcadb and moduledb keys even in the static key management mode, where the secvar format string takes the form "ibm,plpks-sb-v0".

---
 security/integrity/platform_certs/load_powerpc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
security/integrity/platform_certs/load_powerpc.c +3 -2
index c85febca3343..714c961a00f5 100644
@@ -75,12 +75,13 @@ static int __init load_powerpc_certs(void)
 		return -ENODEV;
 
 	// Check for known secure boot implementations from OPAL or PLPKS
-	if (strcmp("ibm,edk2-compat-v1", buf) && strcmp("ibm,plpks-sb-v1", buf)) {
+	if (strcmp("ibm,edk2-compat-v1", buf) && strcmp("ibm,plpks-sb-v1", buf) &&
+	    strcmp("ibm,plpks-sb-v0", buf)) {
 		pr_err("Unsupported secvar implementation \"%s\", not loading certs\n", buf);
 		return -ENODEV;
 	}
 
-	if (strcmp("ibm,plpks-sb-v1", buf) == 0)
+	if (strcmp("ibm,plpks-sb-v1", buf) == 0 || strcmp("ibm,plpks-sb-v0", buf) == 0)
 		/* PLPKS authenticated variables ESL data is prefixed with 8 bytes of timestamp */
 		offset = 8;
 
Signature · 1 line
2.47.1
Reviewed-by on v1 3/3
#17 lore raw

Re: [PATCH 3/3] integrity/platform_certs: Allow loading of keys in static key management mode

Quoted 8 lines · Srish Srinivasan

On PLPKS enabled PowerVM LPAR, there is no provision to load signed third-party kernel modules when the key management mode is static. This is because keys from secure boot secvars are only loaded when the key management mode is dynamic.

Allow loading of the trustedcadb and moduledb keys even in the static key management mode, where the secvar format string takes the form "ibm,plpks-sb-v0".

Thanks & Regards,
- Nayna

Quoted 28 lines
---
  security/integrity/platform_certs/load_powerpc.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
security/integrity/platform_certs/load_powerpc.c +3 -2
index c85febca3343..714c961a00f5 100644
@@ -75,12 +75,13 @@ static int __init load_powerpc_certs(void)
  		return -ENODEV;
 
  	// Check for known secure boot implementations from OPAL or PLPKS
-	if (strcmp("ibm,edk2-compat-v1", buf) && strcmp("ibm,plpks-sb-v1", buf)) {
+	if (strcmp("ibm,edk2-compat-v1", buf) && strcmp("ibm,plpks-sb-v1", buf) &&
+	    strcmp("ibm,plpks-sb-v0", buf)) {
  		pr_err("Unsupported secvar implementation \"%s\", not loading certs\n", buf);
  		return -ENODEV;
  	}
 
-	if (strcmp("ibm,plpks-sb-v1", buf) == 0)
+	if (strcmp("ibm,plpks-sb-v1", buf) == 0 || strcmp("ibm,plpks-sb-v0", buf) == 0)
  		/* PLPKS authenticated variables ESL data is prefixed with 8 bytes of timestamp */
  		offset = 8;
 
Reviewed-by on v1 3/3
#18 lore raw

Re: [PATCH 3/3] integrity/platform_certs: Allow loading of keys in static key management mode

In reply to Srish Srinivasan
Quoted 6 lines · Srish Srinivasan

On PLPKS enabled PowerVM LPAR, there is no provision to load signed third-party kernel modules when the key management mode is static. This
is because keys from secure boot secvars are only loaded when the key management mode is dynamic.

Quoted 7 lines

Allow loading of the trustedcadb and moduledb keys even in the static key management mode, where the secvar format string takes the form "ibm,plpks-sb-v0".

Quoted 31 lines

---
 security/integrity/platform_certs/load_powerpc.c | 5 +++--

 1 file changed, 3 insertions(+), 2 deletions(-)
security/integrity/platform_certs/load_powerpc.c +0 -0
index c85febca3343..714c961a00f5 100644
@@ -75,12 +75,13 @@ static int __init load_powerpc_certs(void)
  		return -ENODEV;


  // Check for known secure boot implementations from OPAL or PLPKS

security/integrity/platform_certs/load_powerpc.c +0 -1
-	if (strcmp("ibm,edk2-compat-v1", buf) && strcmp("ibm,plpks-

sb-v1", buf)) {

security/integrity/platform_certs/load_powerpc.c +1 -0
+	if (strcmp("ibm,edk2-compat-v1", buf) && strcmp("ibm,plpks-

sb-v1", buf) &&

security/integrity/platform_certs/load_powerpc.c +1 -0
+	    strcmp("ibm,plpks-sb-v0", buf)) {

  pr_err("Unsupported secvar implementation \"%s\", not loading certs\n", buf);
  return -ENODEV;
  }

security/integrity/platform_certs/load_powerpc.c +1 -1
-	if (strcmp("ibm,plpks-sb-v1", buf) == 0)
+	if (strcmp("ibm,plpks-sb-v1", buf) == 0 ||

strcmp("ibm,plpks-sb-v0", buf) == 0)
  /* PLPKS authenticated variables ESL data is prefixed with 8 bytes of timestamp */
  offset = 8;

Signature · 2 lines
Andrew Donnellan    OzLabs, ADL Canberra
[email protected]   IBM Australia Limited
#19 lore raw

Re: [PATCH 3/3] integrity/platform_certs: Allow loading of keys in static key management mode

Quoted 7 lines · Andrew Donnellan
Quoted 6 lines · Srish Srinivasan

On PLPKS enabled PowerVM LPAR, there is no provision to load signed third-party kernel modules when the key management mode is static. This
is because keys from secure boot secvars are only loaded when the key management mode is dynamic.

Quoted 8 lines
Quoted 7 lines

Allow loading of the trustedcadb and moduledb keys even in the static key management mode, where the secvar format string takes the form "ibm,plpks-sb-v0".

Hi Andrew,
Thanks a lot for the review.

Thanks and Regards,
Srish

Quoted 31 lines
Quoted 31 lines
---
  security/integrity/platform_certs/load_powerpc.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
security/integrity/platform_certs/load_powerpc.c +0 -0
index c85febca3343..714c961a00f5 100644
@@ -75,12 +75,13 @@ static int __init load_powerpc_certs(void)
  		return -ENODEV;
 
  	// Check for known secure boot implementations from OPAL or

PLPKS

security/integrity/platform_certs/load_powerpc.c +0 -1
-	if (strcmp("ibm,edk2-compat-v1", buf) && strcmp("ibm,plpks-

sb-v1", buf)) {

security/integrity/platform_certs/load_powerpc.c +1 -0
+	if (strcmp("ibm,edk2-compat-v1", buf) && strcmp("ibm,plpks-

sb-v1", buf) &&

security/integrity/platform_certs/load_powerpc.c +1 -0
+	    strcmp("ibm,plpks-sb-v0", buf)) {
  		pr_err("Unsupported secvar implementation \"%s\",

not loading certs\n", buf);
  return -ENODEV;
  }

security/integrity/platform_certs/load_powerpc.c +1 -1
-	if (strcmp("ibm,plpks-sb-v1", buf) == 0)
+	if (strcmp("ibm,plpks-sb-v1", buf) == 0 ||

strcmp("ibm,plpks-sb-v0", buf) == 0)
  /* PLPKS authenticated variables ESL data is
prefixed with 8 bytes of timestamp */
  offset = 8;