Skip to content

Commit 087aa4e

Browse files
esnowbergjarkkojs
authored andcommitted
KEYS: Introduce link restriction for machine keys
Introduce a new link restriction that includes the trusted builtin, secondary and machine keys. The restriction is based on the key to be added being vouched for by a key in any of these three keyrings. With the introduction of the machine keyring, the end-user may choose to trust Machine Owner Keys (MOK) within the kernel. If they have chosen to trust them, the .machine keyring will contain these keys. If not, the machine keyring will always be empty. Update the restriction check to allow the secondary trusted keyring to also trust machine keys. Allow the .machine keyring to be linked to the secondary_trusted_keys. After the link is created, keys contained in the .machine keyring will automatically be searched when searching secondary_trusted_keys. Suggested-by: Mimi Zohar <zohar@linux.ibm.com> Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Tested-by: Mimi Zohar <zohar@linux.ibm.com> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent 56edb6c commit 087aa4e

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

certs/system_keyring.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ static __init struct key_restriction *get_builtin_and_secondary_restriction(void
8989
if (!restriction)
9090
panic("Can't allocate secondary trusted keyring restriction\n");
9191

92-
restriction->check = restrict_link_by_builtin_and_secondary_trusted;
92+
if (IS_ENABLED(CONFIG_INTEGRITY_MACHINE_KEYRING))
93+
restriction->check = restrict_link_by_builtin_secondary_and_machine;
94+
else
95+
restriction->check = restrict_link_by_builtin_and_secondary_trusted;
9396

9497
return restriction;
9598
}
@@ -98,6 +101,36 @@ static __init struct key_restriction *get_builtin_and_secondary_restriction(void
98101
void __init set_machine_trusted_keys(struct key *keyring)
99102
{
100103
machine_trusted_keys = keyring;
104+
105+
if (key_link(secondary_trusted_keys, machine_trusted_keys) < 0)
106+
panic("Can't link (machine) trusted keyrings\n");
107+
}
108+
109+
/**
110+
* restrict_link_by_builtin_secondary_and_machine - Restrict keyring addition.
111+
* @dest_keyring: Keyring being linked to.
112+
* @type: The type of key being added.
113+
* @payload: The payload of the new key.
114+
* @restrict_key: A ring of keys that can be used to vouch for the new cert.
115+
*
116+
* Restrict the addition of keys into a keyring based on the key-to-be-added
117+
* being vouched for by a key in either the built-in, the secondary, or
118+
* the machine keyrings.
119+
*/
120+
int restrict_link_by_builtin_secondary_and_machine(
121+
struct key *dest_keyring,
122+
const struct key_type *type,
123+
const union key_payload *payload,
124+
struct key *restrict_key)
125+
{
126+
if (machine_trusted_keys && type == &key_type_keyring &&
127+
dest_keyring == secondary_trusted_keys &&
128+
payload == &machine_trusted_keys->payload)
129+
/* Allow the machine keyring to be added to the secondary */
130+
return 0;
131+
132+
return restrict_link_by_builtin_and_secondary_trusted(dest_keyring, type,
133+
payload, restrict_key);
101134
}
102135
#endif
103136

include/keys/system_keyring.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ extern int restrict_link_by_builtin_and_secondary_trusted(
3939
#endif
4040

4141
#ifdef CONFIG_INTEGRITY_MACHINE_KEYRING
42+
extern int restrict_link_by_builtin_secondary_and_machine(
43+
struct key *dest_keyring,
44+
const struct key_type *type,
45+
const union key_payload *payload,
46+
struct key *restrict_key);
4247
extern void __init set_machine_trusted_keys(struct key *keyring);
4348
#else
49+
#define restrict_link_by_builtin_secondary_and_machine restrict_link_by_builtin_trusted
4450
static inline void __init set_machine_trusted_keys(struct key *keyring)
4551
{
4652
}

0 commit comments

Comments
 (0)