staticint plpks_get_variable(constchar *key, u64 key_len, u8 *data,
u64 *data_size)
{ struct plpks_var var = {0}; int rc = 0;
// We subtract 1 from key_len because we don't need to include the // null terminator at the end of the string
var.name = kcalloc(key_len - 1, sizeof(wchar_t), GFP_KERNEL); if (!var.name) return -ENOMEM;
rc = utf8s_to_utf16s(key, key_len - 1, UTF16_LITTLE_ENDIAN, (wchar_t *)var.name,
key_len - 1); if (rc < 0) goto err;
var.namelen = rc * 2;
// Secure variables need to be prefixed with 8 bytes of flags. // We only want to perform the write if we have at least one byte of data. if (data_size <= sizeof(flags)) return -EINVAL;
// We subtract 1 from key_len because we don't need to include the // null terminator at the end of the string
var.name = kcalloc(key_len - 1, sizeof(wchar_t), GFP_KERNEL); if (!var.name) return -ENOMEM;
rc = utf8s_to_utf16s(key, key_len - 1, UTF16_LITTLE_ENDIAN, (wchar_t *)var.name,
key_len - 1); if (rc < 0) goto err;
var.namelen = rc * 2;
// Flags are contained in the first 8 bytes of the buffer, and are always big-endian
flags = be64_to_cpup((__be64 *)data);
// Unlike in the read case, the plpks error code can be useful to // userspace on write, so we return it rather than just -EIO
rc = plpks_signed_update_var(&var, flags);
err:
kfree(var.name); return rc;
}
/* * Return the key management mode. * * SB_VERSION is defined as a "1 byte unsigned integer value", taking values * starting from 1. It is owned by the Partition Firmware and its presence * indicates that the key management mode is dynamic. Any failure in * reading SB_VERSION defaults the key management mode to static. The error * codes -ENOENT or -EPERM are expected in static key management mode. An * unexpected error code will have to be investigated. Only signed variables * have null bytes in their names, SB_VERSION does not. * * Return 0 to indicate that the key management mode is static. Otherwise * return the SB_VERSION value to indicate that the key management mode is * dynamic.
*/ static u8 plpks_get_sb_keymgmt_mode(void)
{
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) { if (rc != -ENOENT && rc != -EPERM)
pr_info("Error %ld reading SB_VERSION from firmware\n", rc);
mode = 0;
} return mode;
}
/* * 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 of either * "ibm,plpks-sb-v<n>" 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;
staticint plpks_max_size(u64 *max_size)
{ // The max object size reported by the hypervisor is accurate for the // object itself, but we use the first 8 bytes of data on write as the // signed update flags, so the max size a user can write is larger.
*max_size = (u64)plpks_get_maxobjectsize() + sizeof(u64);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.