Add digitalSignature enforcement keyring restrictions
Subsystems (8)
Eric Snowberg
reviewerv2 cover Add digitalSignature enforcement keyring restrictions
X.509 certificates may contain a key usage extension [1]. The key usage extension defines the purpose of the certificate. One area of interest is the digitalSignature. The digitalSignature usage is typically used for code signing (integrity).
Within the "Add CA enforcement key restrictions" [2] series, the digitalSignature is being saved. This series builds upon the previous one and adds restrictions based on the digitalSignature usage.
A new keyring restriction called restrict_link_by_digsig is added. The new restriction only allows keys that contain digitalSignature usage within it.
With this update, keys can be filtered based on digitalSignature. The first two keyrings to use this restriction are the .ima and .evm keyrings. Only keys containing a digitalSignature shall be allowed into either keyring.
1. https://www.rfc-editor.org/rfc/rfc5280#section-4.2.1.3
2. https://lore.kernel.org/all/[email protected]/T/
Changelog:
v2:
- No new code changes
- Added Reviewed-by and ACKs
- Updated code comments requested by Jarkko
Eric Snowberg (3):
KEYS: DigitalSignature link restriction
integrity: Enforce digitalSignature usage in the ima and evm keyrings
integrity: Remove EXPERIMENTAL from Kconfig
certs/system_keyring.c | 50 +++++++++++++++++++++++++++++++ crypto/asymmetric_keys/restrict.c | 44 +++++++++++++++++++++++++++ include/crypto/public_key.h | 11 +++++++ include/keys/system_keyring.h | 11 +++++++ security/integrity/digsig.c | 4 +-- security/integrity/evm/Kconfig | 3 +- security/integrity/ima/Kconfig | 5 ++-- 7 files changed, 123 insertions(+), 5 deletions(-)
base-commit: 44c026a73be8038f03dbdeef028b642880cf1511
Signature · 1 line
2.27.0
Eric Snowberg
reviewerPATCH v2 1/3 KEYS: DigitalSignature link restriction
Add a new link restriction. Restrict the addition of keys in a keyring based on the key having digitalSignature usage set. Additionally, verify the new certificate against the ones in the system keyrings. Add two additional functions to use the new restriction within either the builtin or secondary keyrings.
--- certs/system_keyring.c | 50 +++++++++++++++++++++++++++++++ crypto/asymmetric_keys/restrict.c | 44 +++++++++++++++++++++++++++ include/crypto/public_key.h | 11 +++++++ include/keys/system_keyring.h | 11 +++++++ 4 files changed, 116 insertions(+)
certs/system_keyring.c +50 -0
@@ -51,6 +51,26 @@ int restrict_link_by_builtin_trusted(struct key *dest_keyring, builtin_trusted_keys); } +/** +* restrict_link_by_digsig_builtin - Restrict digitalSignature key additions by the built-in keyring +* @dest_keyring: Keyring being linked to. +* @type: The type of key being added. +* @payload: The payload of the new key. +* @restriction_key: A ring of keys that can be used to vouch for the new cert. +* +* Restrict the addition of keys into a keyring based on the key-to-be-added +* being vouched for by a key in the built in system keyring. The new key +* must have the digitalSignature usage field set. +*/ +int restrict_link_by_digsig_builtin (struct key *dest_keyring, +const struct key_type *type, +const union key_payload *payload, +struct key *restriction_key) +{ +return restrict_link_by_digsig (dest_keyring, type, payload, + builtin_trusted_keys); +} +#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING /** * restrict_link_by_builtin_and_secondary_trusted - Restrict keyring
@@ -83,6 +103,36 @@ int restrict_link_by_builtin_and_secondary_trusted( secondary_trusted_keys); } +/** +* restrict_link_by_digsig_builtin_and_secondary - Restrict by digitalSignature. +* @dest_keyring: Keyring being linked to. +* @type: The type of key being added. +* @payload: The payload of the new key. +* @restrict_key: A ring of keys that can be used to vouch for the new cert. +* +* Restrict the addition of keys into a keyring based on the key-to-be-added +* being vouched for by a key in either the built-in or the secondary system +* keyrings. The new key must have the digitalSignature usage field set. +*/ +int restrict_link_by_digsig_builtin_and_secondary ( +struct key *dest_keyring, +const struct key_type *type, +const union key_payload *payload, +struct key *restrict_key) +{ +/* If we have a secondary trusted keyring, then that contains a link +* through to the builtin keyring and the search will follow that link. +*/ +if (type == &key_type_keyring && + dest_keyring == secondary_trusted_keys && + payload == &builtin_trusted_keys->payload) +/* Allow the builtin keyring to be added to the secondary */ +return 0 ; + +return restrict_link_by_digsig (dest_keyring, type, payload, + secondary_trusted_keys); +} +/* * Allocate a struct key_restriction for the "builtin and secondary trust" * keyring. Only for use in system_trusted_keyring_init().
crypto/asymmetric_keys/restrict.c +44 -0
50 lines not on this page · raw message
include/crypto/public_key.h +11 -0
@@ -80,6 +80,10 @@ extern int restrict_link_by_ca(struct key *dest_keyring,const struct key_type *type, const union key_payload *payload, struct key *trust_keyring); +int restrict_link_by_digsig (struct key *dest_keyring, +const struct key_type *type, +const union key_payload *payload, +struct key *trust_keyring);#else static inline int restrict_link_by_ca(struct key *dest_keyring, const struct key_type *type,
@@ -88,6 +92,13 @@ static inline int restrict_link_by_ca(struct key *dest_keyring, {return 0 ; } +static inline int restrict_link_by_digsig (struct key *dest_keyring, +const struct key_type *type, +const union key_payload *payload, +struct key *trust_keyring) +{ +return 0 ; +}#endif extern int query_asymmetric_key(const struct kernel_pkey_params *,
include/keys/system_keyring.h +11 -0
@@ -23,10 +23,15 @@ extern int restrict_link_by_builtin_trusted(struct key *keyring,const struct key_type *type, const union key_payload *payload, struct key *restriction_key); +int restrict_link_by_digsig_builtin (struct key *dest_keyring, +const struct key_type *type, +const union key_payload *payload, +struct key *restriction_key);extern __init int load_module_cert (struct key *keyring);#else #define restrict_link_by_builtin_trusted restrict_link_reject +#define restrict_link_by_digsig_builtin restrict_link_rejectstatic inline __init int load_module_cert (struct key *keyring) {
@@ -41,8 +46,14 @@ extern int restrict_link_by_builtin_and_secondary_trusted(const struct key_type *type, const union key_payload *payload, struct key *restriction_key); +extern int restrict_link_by_digsig_builtin_and_secondary ( +struct key *keyring, +const struct key_type *type, +const union key_payload *payload, +struct key *restriction_key);#else #define restrict_link_by_builtin_and_secondary_trusted restrict_link_by_builtin_trusted +#define restrict_link_by_digsig_builtin_and_secondary restrict_link_by_digsig_builtin#endif #ifdef CONFIG_INTEGRITY_MACHINE_KEYRING
Signature · 1 line
2.27.0
Mimi Zohar
maintainerRe: [PATCH v2 1/3] KEYS: DigitalSignature link restriction
Quoted 8 lines · Eric Snowberg
Add a new link restriction. Restrict the addition of keys in a keyring based on the key having digitalSignature usage set. Additionally, verify the new certificate against the ones in the system keyrings. Add two additional functions to use the new restriction within either the builtin or secondary keyrings.
Signed-off-by Eric Snowberg <[email protected]>Reviewed-by Mimi Zohar <[email protected]>
Jarkko, please update the above tag to Reviewed-and-tested-by.
Signature · 3 lines
thanks, Mimi
Eric Snowberg
reviewerPATCH v2 2/3 integrity: Enforce digitalSignature usage in the ima and evm keyrings
In reply to Eric SnowbergAfter being vouched for by a system keyring, only allow keys into the .ima and .evm keyrings that have the digitalSignature usage field set.
--- security/integrity/digsig.c | 4 ++-- security/integrity/evm/Kconfig | 3 ++- security/integrity/ima/Kconfig | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-)
security/integrity/digsig.c +2 -2
@@ -34,9 +34,9 @@ static const char * const keyring_name[INTEGRITY_KEYRING_MAX] = { };#ifdef CONFIG_IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY -#define restrict_link_to_ima restrict_link_by_builtin_and_secondary_trusted +#define restrict_link_to_ima restrict_link_by_digsig_builtin_and_secondary#else -#define restrict_link_to_ima restrict_link_by_builtin_trusted +#define restrict_link_to_ima restrict_link_by_digsig_builtin#endif static struct key *integrity_keyring_from_id (const unsigned int id)
security/integrity/evm/Kconfig +2 -1
@@ -64,7 +64,8 @@ config EVM_LOAD_X509 This option enables X509 certificate loading from the kernel onto the '.evm' trusted keyring. A public key can be used to - verify EVM integrity starting from the 'init' process. + verify EVM integrity starting from the 'init' process. The + key must have digitalSignature usage set. config EVM_X509_PATH string "EVM X509 certificate path"
security/integrity/ima/Kconfig +2 -1
@@ -270,7 +270,8 @@ config IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY help Keys may be added to the IMA or IMA blacklist keyrings, if the key is validly signed by a CA cert in the system built-in or - secondary trusted keyrings. + secondary trusted keyrings. The key must also have the + digitalSignature usage set. Intermediate keys between those the kernel has compiled in and the IMA keys to be added may be added to the system secondary keyring,
Signature · 1 line
2.27.0
Mimi Zohar
maintainerRe: [PATCH v2 2/3] integrity: Enforce digitalSignature usage in the ima and evm keyrings
Quoted 7 lines · Eric Snowberg
After being vouched for by a system keyring, only allow keys into the .ima and .evm keyrings that have the digitalSignature usage field set.
Suggested-by Mimi Zohar <[email protected]>Signed-off-by Eric Snowberg <[email protected]>Acked-by Mimi Zohar <[email protected]>
Jarrko, similarly please update the above tag to Acked-and-test-by.
Signature · 3 lines
thanks, Mimi
Jarkko Sakkinen
maintainerRe: [PATCH v2 2/3] integrity: Enforce digitalSignature usage in the ima and evm keyrings
Quoted 10 lines · Mimi Zohar
Quoted 7 lines · Eric Snowberg
After being vouched for by a system keyring, only allow keys into the .ima and .evm keyrings that have the digitalSignature usage field set.
Suggested-by Mimi Zohar <[email protected]>Signed-off-by Eric Snowberg <[email protected]>Acked-by Mimi Zohar <[email protected]>Jarrko, similarly please update the above tag to Acked-and-test-by.
OK, cool, I'll pick this series, thanks.
BR, Jarkko
Jarkko Sakkinen
maintainerRe: [PATCH v2 2/3] integrity: Enforce digitalSignature usage in the ima and evm keyrings
Quoted 5 lines · Jarkko Sakkinen
Quoted 4 lines · Mimi Zohar
Quoted 3 lines · Eric Snowberg
After being vouched for by a system keyring, only allow keys into the .ima and .evm keyrings that have the digitalSignature usage field set.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Suggested-by Mimi Zohar <[email protected]>Signed-off-by Eric Snowberg <[email protected]>Acked-by Mimi Zohar <[email protected]>Jarrko, similarly please update the above tag to Acked-and-test-by.
OK, cool, I'll pick this series, thanks.
Please check https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git
BR, Jarkko
Eric Snowberg
reviewerPATCH v2 3/3 integrity: Remove EXPERIMENTAL from Kconfig
In reply to Eric SnowbergRemove the EXPERIMENTAL from the IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY Kconfig now that digitalSignature usage enforcement is set.
--- security/integrity/ima/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/integrity/ima/Kconfig +1 -1
@@ -261,7 +261,7 @@ config IMA_TRUSTED_KEYRING This option is deprecated in favor of INTEGRITY_TRUSTED_KEYRING config IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY - bool "Permit keys validly signed by a built-in or secondary CA cert (EXPERIMENTAL)" + bool "Permit keys validly signed by a built-in or secondary CA cert" depends on SYSTEM_TRUSTED_KEYRING depends on SECONDARY_TRUSTED_KEYRING depends on INTEGRITY_ASYMMETRIC_KEYS
Signature · 1 line
2.27.0