2019-11-10 22:10:36 -05:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 IBM Corporation
|
|
|
|
* Author: Nayna Jain
|
|
|
|
*
|
|
|
|
* - loads keys and hashes stored and controlled by the firmware.
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/cred.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <asm/secure_boot.h>
|
|
|
|
#include <asm/secvar.h>
|
|
|
|
#include "keyring_handler.h"
|
2023-02-10 03:04:00 -05:00
|
|
|
#include "../integrity.h"
|
2019-11-10 22:10:36 -05:00
|
|
|
|
2023-06-08 08:04:44 -04:00
|
|
|
#define extract_esl(db, data, size, offset) \
|
|
|
|
do { db = data + offset; size = size - offset; } while (0)
|
|
|
|
|
2019-11-10 22:10:36 -05:00
|
|
|
/*
|
|
|
|
* Get a certificate list blob from the named secure variable.
|
2023-02-10 03:04:00 -05:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* - a pointer to a kmalloc'd buffer containing the cert list on success
|
|
|
|
* - NULL if the key does not exist
|
|
|
|
* - an ERR_PTR on error
|
2019-11-10 22:10:36 -05:00
|
|
|
*/
|
2023-02-10 03:03:39 -05:00
|
|
|
static __init void *get_cert_list(u8 *key, unsigned long keylen, u64 *size)
|
2019-11-10 22:10:36 -05:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
void *db;
|
|
|
|
|
|
|
|
rc = secvar_ops->get(key, keylen, NULL, size);
|
|
|
|
if (rc) {
|
2023-02-10 03:04:00 -05:00
|
|
|
if (rc == -ENOENT)
|
|
|
|
return NULL;
|
|
|
|
return ERR_PTR(rc);
|
2019-11-10 22:10:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
db = kmalloc(*size, GFP_KERNEL);
|
|
|
|
if (!db)
|
2023-02-10 03:04:00 -05:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2019-11-10 22:10:36 -05:00
|
|
|
|
|
|
|
rc = secvar_ops->get(key, keylen, db, size);
|
|
|
|
if (rc) {
|
|
|
|
kfree(db);
|
2023-02-10 03:04:00 -05:00
|
|
|
return ERR_PTR(rc);
|
2019-11-10 22:10:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return db;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load the certs contained in the keys databases into the platform trusted
|
|
|
|
* keyring and the blacklisted X.509 cert SHA256 hashes into the blacklist
|
|
|
|
* keyring.
|
|
|
|
*/
|
|
|
|
static int __init load_powerpc_certs(void)
|
|
|
|
{
|
2023-06-08 08:04:44 -04:00
|
|
|
void *db = NULL, *dbx = NULL, *data = NULL;
|
2023-08-15 07:27:17 -04:00
|
|
|
void *trustedca;
|
2023-08-15 07:27:22 -04:00
|
|
|
void *moduledb;
|
2023-06-08 08:04:44 -04:00
|
|
|
u64 dsize = 0;
|
|
|
|
u64 offset = 0;
|
2019-11-10 22:10:36 -05:00
|
|
|
int rc = 0;
|
integrity/powerpc: Support loading keys from PLPKS
Add support for loading keys from the PLPKS on pseries machines, with the
"ibm,plpks-sb-v1" format.
The object format is expected to be the same, so there shouldn't be any
functional differences between objects retrieved on powernv or pseries.
Unlike on powernv, on pseries the format string isn't contained in the
device tree. Use secvar_ops->format() to fetch the format string in a
generic manner, rather than searching the device tree ourselves.
(The current code searches the device tree for a node compatible with
"ibm,edk2-compat-v1". This patch switches to calling secvar_ops->format(),
which in the case of OPAL/powernv means opal_secvar_format(), which
searches the device tree for a node compatible with "ibm,secvar-backend"
and checks its "format" property. These are equivalent, as skiboot creates
a node with both "ibm,edk2-compat-v1" and "ibm,secvar-backend" as
compatible strings.)
Signed-off-by: Russell Currey <ruscur@russell.cc>
Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20230210080401.345462-27-ajd@linux.ibm.com
2023-02-10 03:04:01 -05:00
|
|
|
ssize_t len;
|
|
|
|
char buf[32];
|
2019-11-10 22:10:36 -05:00
|
|
|
|
|
|
|
if (!secvar_ops)
|
|
|
|
return -ENODEV;
|
|
|
|
|
integrity/powerpc: Support loading keys from PLPKS
Add support for loading keys from the PLPKS on pseries machines, with the
"ibm,plpks-sb-v1" format.
The object format is expected to be the same, so there shouldn't be any
functional differences between objects retrieved on powernv or pseries.
Unlike on powernv, on pseries the format string isn't contained in the
device tree. Use secvar_ops->format() to fetch the format string in a
generic manner, rather than searching the device tree ourselves.
(The current code searches the device tree for a node compatible with
"ibm,edk2-compat-v1". This patch switches to calling secvar_ops->format(),
which in the case of OPAL/powernv means opal_secvar_format(), which
searches the device tree for a node compatible with "ibm,secvar-backend"
and checks its "format" property. These are equivalent, as skiboot creates
a node with both "ibm,edk2-compat-v1" and "ibm,secvar-backend" as
compatible strings.)
Signed-off-by: Russell Currey <ruscur@russell.cc>
Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20230210080401.345462-27-ajd@linux.ibm.com
2023-02-10 03:04:01 -05:00
|
|
|
len = secvar_ops->format(buf, sizeof(buf));
|
|
|
|
if (len <= 0)
|
2019-11-10 22:10:36 -05:00
|
|
|
return -ENODEV;
|
|
|
|
|
integrity/powerpc: Support loading keys from PLPKS
Add support for loading keys from the PLPKS on pseries machines, with the
"ibm,plpks-sb-v1" format.
The object format is expected to be the same, so there shouldn't be any
functional differences between objects retrieved on powernv or pseries.
Unlike on powernv, on pseries the format string isn't contained in the
device tree. Use secvar_ops->format() to fetch the format string in a
generic manner, rather than searching the device tree ourselves.
(The current code searches the device tree for a node compatible with
"ibm,edk2-compat-v1". This patch switches to calling secvar_ops->format(),
which in the case of OPAL/powernv means opal_secvar_format(), which
searches the device tree for a node compatible with "ibm,secvar-backend"
and checks its "format" property. These are equivalent, as skiboot creates
a node with both "ibm,edk2-compat-v1" and "ibm,secvar-backend" as
compatible strings.)
Signed-off-by: Russell Currey <ruscur@russell.cc>
Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20230210080401.345462-27-ajd@linux.ibm.com
2023-02-10 03:04:01 -05:00
|
|
|
// Check for known secure boot implementations from OPAL or PLPKS
|
|
|
|
if (strcmp("ibm,edk2-compat-v1", buf) && strcmp("ibm,plpks-sb-v1", buf)) {
|
|
|
|
pr_err("Unsupported secvar implementation \"%s\", not loading certs\n", buf);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2023-06-08 08:04:44 -04:00
|
|
|
if (strcmp("ibm,plpks-sb-v1", buf) == 0)
|
|
|
|
/* PLPKS authenticated variables ESL data is prefixed with 8 bytes of timestamp */
|
|
|
|
offset = 8;
|
|
|
|
|
2019-11-10 22:10:36 -05:00
|
|
|
/*
|
|
|
|
* Get db, and dbx. They might not exist, so it isn't an error if we
|
|
|
|
* can't get them.
|
|
|
|
*/
|
2023-06-08 08:04:44 -04:00
|
|
|
data = get_cert_list("db", 3, &dsize);
|
|
|
|
if (!data) {
|
2023-02-10 03:04:00 -05:00
|
|
|
pr_info("Couldn't get db list from firmware\n");
|
2023-06-08 08:04:44 -04:00
|
|
|
} else if (IS_ERR(data)) {
|
|
|
|
rc = PTR_ERR(data);
|
2023-02-10 03:04:00 -05:00
|
|
|
pr_err("Error reading db from firmware: %d\n", rc);
|
|
|
|
return rc;
|
2019-11-10 22:10:36 -05:00
|
|
|
} else {
|
2023-06-08 08:04:44 -04:00
|
|
|
extract_esl(db, data, dsize, offset);
|
|
|
|
|
|
|
|
rc = parse_efi_signature_list("powerpc:db", db, dsize,
|
2019-11-10 22:10:36 -05:00
|
|
|
get_handler_for_db);
|
|
|
|
if (rc)
|
|
|
|
pr_err("Couldn't parse db signatures: %d\n", rc);
|
2023-06-08 08:04:44 -04:00
|
|
|
kfree(data);
|
2019-11-10 22:10:36 -05:00
|
|
|
}
|
|
|
|
|
2023-06-08 08:04:44 -04:00
|
|
|
data = get_cert_list("dbx", 4, &dsize);
|
|
|
|
if (!data) {
|
2019-11-10 22:10:36 -05:00
|
|
|
pr_info("Couldn't get dbx list from firmware\n");
|
2023-06-08 08:04:44 -04:00
|
|
|
} else if (IS_ERR(data)) {
|
|
|
|
rc = PTR_ERR(data);
|
2023-02-10 03:04:00 -05:00
|
|
|
pr_err("Error reading dbx from firmware: %d\n", rc);
|
|
|
|
return rc;
|
2019-11-10 22:10:36 -05:00
|
|
|
} else {
|
2023-06-08 08:04:44 -04:00
|
|
|
extract_esl(dbx, data, dsize, offset);
|
|
|
|
|
|
|
|
rc = parse_efi_signature_list("powerpc:dbx", dbx, dsize,
|
2019-11-10 22:10:36 -05:00
|
|
|
get_handler_for_dbx);
|
|
|
|
if (rc)
|
|
|
|
pr_err("Couldn't parse dbx signatures: %d\n", rc);
|
2023-06-08 08:04:44 -04:00
|
|
|
kfree(data);
|
2019-11-10 22:10:36 -05:00
|
|
|
}
|
|
|
|
|
2023-08-15 07:27:17 -04:00
|
|
|
data = get_cert_list("trustedcadb", 12, &dsize);
|
|
|
|
if (!data) {
|
|
|
|
pr_info("Couldn't get trustedcadb list from firmware\n");
|
|
|
|
} else if (IS_ERR(data)) {
|
|
|
|
rc = PTR_ERR(data);
|
|
|
|
pr_err("Error reading trustedcadb from firmware: %d\n", rc);
|
|
|
|
} else {
|
|
|
|
extract_esl(trustedca, data, dsize, offset);
|
|
|
|
|
|
|
|
rc = parse_efi_signature_list("powerpc:trustedca", trustedca, dsize,
|
|
|
|
get_handler_for_ca_keys);
|
|
|
|
if (rc)
|
|
|
|
pr_err("Couldn't parse trustedcadb signatures: %d\n", rc);
|
|
|
|
kfree(data);
|
|
|
|
}
|
|
|
|
|
2023-08-15 07:27:22 -04:00
|
|
|
data = get_cert_list("moduledb", 9, &dsize);
|
|
|
|
if (!data) {
|
|
|
|
pr_info("Couldn't get moduledb list from firmware\n");
|
|
|
|
} else if (IS_ERR(data)) {
|
|
|
|
rc = PTR_ERR(data);
|
|
|
|
pr_err("Error reading moduledb from firmware: %d\n", rc);
|
|
|
|
} else {
|
|
|
|
extract_esl(moduledb, data, dsize, offset);
|
|
|
|
|
|
|
|
rc = parse_efi_signature_list("powerpc:moduledb", moduledb, dsize,
|
|
|
|
get_handler_for_code_signing_keys);
|
|
|
|
if (rc)
|
|
|
|
pr_err("Couldn't parse moduledb signatures: %d\n", rc);
|
|
|
|
kfree(data);
|
|
|
|
}
|
|
|
|
|
2019-11-10 22:10:36 -05:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
late_initcall(load_powerpc_certs);
|