Add CA enforcement keyring restrictions
Subsystems (8)
Eric Snowberg
reviewerv4 cover Add CA enforcement keyring restrictions
Prior to the introduction of the machine keyring, most distros simply allowed all keys contained within the platform keyring to be used for both kernel and module verification. This was done by an out of tree patch. Some distros took it even further and loaded all these keys into the secondary trusted keyring. This also allowed the system owner to add their own key for IMA usage.
Each distro contains similar documentation on how to sign kernel modules and enroll the key into the MOK. The process is fairly straightforward. With the introduction of the machine keyring, the process remains basically the same, without the need for any out of tree patches.
The machine keyring allowed distros to eliminate the out of tree patches for kernel module signing. However, it falls short in allowing the end user to add their own keys for IMA. Currently, the machine keyring can not be used as another trust anchor for adding keys to the ima keyring, since CA enforcement does not currently exist. This would expand the current integrity gap. The IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY Kconfig states that keys may be added to the ima keyrings if the key is validly signed by a CA cert in the system built-in or secondary trusted keyring. Currently, there is not code that enforces the contents of a CA cert.
This series introduces a way to do CA enforement with the machine keyring. It introduces three different ways to configure the machine keyring. A new menu option is added to control the type of keys that may be added to it. The options include none, min, and max restrictions. The default is CONFIG_INTEGRITY_CA_MACHINE_KEYRING_NONE. This allows all MOK keys into the machine keyring. When CONFIG_INTEGRITY_CA_MACHINE_KEYRING_MIN is selected, the X.509 CA bit must be true. Also, the key usage must contain keyCertSign, any other usage field may also be set. When CONFIG_INTEGRITY_CA_MACHINE_KEYRING_MAX is selected, the X.509 CA bit must be true. Also, the key usage must contain keyCertSign and the digitialSignature usage may not be set. If a key doesn't pass the CA restriction check, instead of going into the machine keyring, it is added to the platform keyring. With the ability to configure the machine keyring with CA restrictions, code that prevented the machine keyring from being enabled with IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY has been removed.
Changelog:
v4:
- Removed all code that validated the certificate chain back to the root CA. Now the only restriction is what is initially placed in the machine keyring.
- Check and store if the X.509 usage contains digitalSignature
- New Kconfig menu item with none, min and max CA restriction on the machine keyring
v3:
- Allow Intermediate CA certs to be enrolled through the MOK. The Intermediate CA cert must contain keyCertSign key usage and have the CA bit set to true. This was done by removing the self signed requirement.
Eric Snowberg (6):
KEYS: Create static version of public_key_verify_signature
KEYS: Add missing function documentation
KEYS: X.509: Parse Basic Constraints for CA
KEYS: X.509: Parse Key Usage
KEYS: CA link restriction
integrity: machine keyring CA configuration
certs/system_keyring.c | 14 +++++-- crypto/asymmetric_keys/restrict.c | 40 ++++++++++++++++++ crypto/asymmetric_keys/x509_cert_parser.c | 50 +++++++++++++++++++++++ include/crypto/public_key.h | 28 +++++++++++++ security/integrity/Kconfig | 39 +++++++++++++++++- security/integrity/digsig.c | 8 +++- 6 files changed, 173 insertions(+), 6 deletions(-)
base-commit: 4ec5183ec48656cec489c49f989c508b68b518e3
Signature · 1 line
2.27.0
Eric Snowberg
reviewerPATCH v4 1/6 KEYS: Create static version of public_key_verify_signature
The kernel test robot reports undefined reference to public_key_verify_signature when CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE is not defined. Create a static version in this case and return -EINVAL.
--- include/crypto/public_key.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/crypto/public_key.h +9 -0
@@ -80,7 +80,16 @@ extern int create_signature(struct kernel_pkey_params *, const void *, void *);extern int verify_signature (const struct key *,const struct public_key_signature *); +#if IS_REACHABLE (CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE )int public_key_verify_signature (const struct public_key *pkey,const struct public_key_signature *sig); +#else +static inline +int public_key_verify_signature (const struct public_key *pkey, +const struct public_key_signature *sig) +{ +return -EINVAL ; +} +#endif #endif /* _LINUX_PUBLIC_KEY_H */
Signature · 1 line
2.27.0
Jarkko Sakkinen
maintainerRe: [PATCH v4 1/6] KEYS: Create static version of public_key_verify_signature
Quoted 6 lines · Eric Snowberg
The kernel test robot reports undefined reference to
public_key_verify_signaturewhenCONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPEis not defined. Create a static version in this case and return-EINVAL.Fixes db6c43bd2132 ("crypto: KEYS: convert public key and digsig asym to the akcipher api")Reported-by kernel test robot <[email protected]>
What is this reported-by is good for?
Quoted 31 lines
Signed-off-by Eric Snowberg <[email protected]>Reviewed-by Mimi Zohar <[email protected]>Reviewed-by Petr Vorel <[email protected]>--- include/crypto/public_key.h | 9 +++++++++ 1 file changed, 9 insertions(+)include/crypto/public_key.h +9
-0@@ -80,7 +80,16 @@ extern int create_signature(struct kernel_pkey_params *, const void *, void *);extern int verify_signature (const struct key *,const struct public_key_signature *); +#if IS_REACHABLE (CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE )int public_key_verify_signature (const struct public_key *pkey,const struct public_key_signature *sig); +#else +static inline +int public_key_verify_signature (const struct public_key *pkey, +const struct public_key_signature *sig) +{ +return -EINVAL ; +} +#endif #endif /* _LINUX_PUBLIC_KEY_H */ Signature · 1 line
2.27.0
BR, Jarkko
Eric Snowberg
reviewerRe: [PATCH v4 1/6] KEYS: Create static version of public_key_verify_signature
Quoted 13 lines · Jarkko Sakkinen
Quoted 6 lines · Eric Snowberg
The kernel test robot reports undefined reference to
public_key_verify_signaturewhenCONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPEis not defined. Create a static version in this case and return-EINVAL.Fixes db6c43bd2132 ("crypto: KEYS: convert public key and digsig asym to the akcipher api")Reported-by kernel test robot <[email protected]>What is this reported-by is good for?
Back in September of 2021, I received the following message from the test robot [1]. Within the message it asks that I add the Reported-by tag. To prevent the test robot from generating this error again, I have included this patch at the beginning of the series for the last year and a half. It would be great if someone would apply the first two patches.
Eric Snowberg
reviewerPATCH v4 2/6 KEYS: Add missing function documentation
In reply to Eric SnowbergCompiling with 'W=1' results in warnings that 'Function parameter or member not described'
Add the missing parameters for restrict_link_by_builtin_and_secondary_trusted and restrict_link_to_builtin_trusted.
Use /* instead of /** for get_builtin_and_secondary_restriction, since it is a static function.
Fix wrong function name restrict_link_to_builtin_trusted.
--- certs/system_keyring.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
certs/system_keyring.c +11 -3
@@ -33,7 +33,11 @@ extern __initconst const unsigned long system_certificate_list_size;extern __initconst const unsigned long module_cert_size;/** -* restrict_link_to_builtin_trusted - Restrict keyring addition by built in CA +* restrict_link_by_builtin_trusted - Restrict keyring addition by built in CA +* @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.
@@ -50,7 +54,11 @@ int restrict_link_by_builtin_trusted(struct key *dest_keyring,#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING /** * restrict_link_by_builtin_and_secondary_trusted - Restrict keyring -* addition by both builtin and secondary keyrings +* addition by both builtin and secondary keyrings. +* @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
@@ -75,7 +83,7 @@ int restrict_link_by_builtin_and_secondary_trusted( secondary_trusted_keys); } -/** +/* * Allocate a struct key_restriction for the "builtin and secondary trust" * keyring. Only for use in system_trusted_keyring_init(). */
Signature · 1 line
2.27.0
Re: [PATCH v4 2/6] KEYS: Add missing function documentation
Quoted 24 lines · Eric Snowberg
Compiling with 'W=1' results in warnings that 'Function parameter or member not described'
Add the missing parameters for
restrict_link_by_builtin_and_secondary_trustedandrestrict_link_to_builtin_trusted.Use /* instead of /** for
get_builtin_and_secondary_restriction, since it is a static function.Fix wrong function name
restrict_link_to_builtin_trusted.Fixes d3bfe84129f6 ("certs: Add a secondary system keyring that can be added to dynamically")Signed-off-by Eric Snowberg <[email protected]>Reviewed-by Petr Vorel <[email protected]>--- certs/system_keyring.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)certs/system_keyring.c +0
-0
certs/system_keyring.c extern __initconst const unsigned long system_certificate_list_size; · line 36
Quoted 5 lines
certs/system_keyring.c +1
-1@@ -33,7 +33,11 @@ extern __initconst const unsigned long system_certificate_list_size;extern __initconst const unsigned long module_cert_size;/** -* restrict_link_to_builtin_trusted - Restrict keyring addition by built in CA +* restrict_link_by_builtin_trusted - Restrict keyring addition by built in CA
While fixing the kernel doc, might as well update "built in" to be consistent.
certs/system_keyring.c int restrict_link_by_builtin_trusted(struct key *dest_keyring, · line 57
Quoted 13 lines
certs/system_keyring.c +5
-1+* @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. @@ -50,7 +54,11 @@ int restrict_link_by_builtin_trusted(struct key *dest_keyring,#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING /** * restrict_link_by_builtin_and_secondary_trusted - Restrict keyring -* addition by both builtin and secondary keyrings +* addition by both builtin and secondary keyrings.
and here
certs/system_keyring.c int restrict_link_by_builtin_trusted(struct key *dest_keyring, · line 64
Quoted 7 lines
certs/system_keyring.c +4
-0+* @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
and here
certs/system_keyring.c int restrict_link_by_builtin_and_secondary_trusted( · line 89
Quoted 9 lines
certs/system_keyring.c +1
-1@@ -75,7 +83,7 @@ int restrict_link_by_builtin_and_secondary_trusted( secondary_trusted_keys); } -/** +/* * Allocate a struct key_restriction for the "builtin and secondary trust" * keyring. Only for use in system_trusted_keyring_init(). */
Re: [PATCH v4 2/6] KEYS: Add missing function documentation
In reply to Eric SnowbergQuoted 61 lines · Eric Snowberg
Compiling with 'W=1' results in warnings that 'Function parameter or member not described'
Add the missing parameters for
restrict_link_by_builtin_and_secondary_trustedandrestrict_link_to_builtin_trusted.Use /* instead of /** for
get_builtin_and_secondary_restriction, since it is a static function.Fix wrong function name
restrict_link_to_builtin_trusted.Fixes d3bfe84129f6 ("certs: Add a secondary system keyring that can be added to dynamically")Signed-off-by Eric Snowberg <[email protected]>Reviewed-by Petr Vorel <[email protected]>--- certs/system_keyring.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)certs/system_keyring.c +11
-3@@ -33,7 +33,11 @@ extern __initconst const unsigned long system_certificate_list_size;extern __initconst const unsigned long module_cert_size;/** -* restrict_link_to_builtin_trusted - Restrict keyring addition by built in CA +* restrict_link_by_builtin_trusted - Restrict keyring addition by built in CA +* @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. @@ -50,7 +54,11 @@ int restrict_link_by_builtin_trusted(struct key *dest_keyring,#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING /** * restrict_link_by_builtin_and_secondary_trusted - Restrict keyring -* addition by both builtin and secondary keyrings +* addition by both builtin and secondary keyrings. +* @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 @@ -75,7 +83,7 @@ int restrict_link_by_builtin_and_secondary_trusted( secondary_trusted_keys); } -/** +/* * Allocate a struct key_restriction for the "builtin and secondary trust" * keyring. Only for use in system_trusted_keyring_init(). */ Signature · 1 line
2.27.0
BR, Jarkko
Eric Snowberg
reviewerPATCH v4 3/6 KEYS: X.509: Parse Basic Constraints for CA
In reply to Eric SnowbergParse the X.509 Basic Constraints. The basic constraints extension identifies whether the subject of the certificate is a CA.
BasicConstraints ::= SEQUENCE {
cA BOOLEAN DEFAULT FALSE,
pathLenConstraint INTEGER (0..MAX) OPTIONAL }
If the CA is true, store it in the public_key. This will be used in a follow on patch that requires knowing if the public key is a CA.
--- crypto/asymmetric_keys/x509_cert_parser.c | 22 ++++++++++++++++++++++ include/crypto/public_key.h | 2 ++ 2 files changed, 24 insertions(+)
crypto/asymmetric_keys/x509_cert_parser.c +22 -0
@@ -586,6 +586,28 @@ int x509_process_extension(void *context, size_t hdrlen,return 0 ; } +if (ctx->last_oid == OID_basicConstraints) { +/* +* Get hold of the basicConstraints +* v[1] is the encoding size +* (Expect 0x2 or greater, making it 1 or more bytes) +* v[2] is the encoding type +* (Expect an ASN1_BOOL for the CA) +* v[3] is the contents of the ASN1_BOOL +* (Expect 1 if the CA is TRUE) +* vlen should match the entire extension size +*/ +if (v[0 ] != (ASN1_CONS_BIT |ASN1_SEQ )) +return -EBADMSG ; +if (vlen <2 ) +return -EBADMSG ; +if (v[1 ] != vlen -2 ) +return -EBADMSG ; +if (vlen >=4 && v[1 ] !=0 && v[2 ] ==ASN1_BOOL && v[3 ] ==1 ) + ctx->cert->pub->key_eflags |=1 <<KEY_EFLAG_CA ; +return 0 ; + } +return 0 ; }
include/crypto/public_key.h +2 -0
@@ -28,6 +28,8 @@ struct public_key {bool key_is_private;const char *id_type;const char *pkey_algo; +unsigned long key_eflags;/* key extension flags */ +#define KEY_EFLAG_CA 0/* set if the CA basic constraints is set */ };extern void public_key_free (struct public_key *key);
Signature · 1 line
2.27.0
Re: [PATCH v4 3/6] KEYS: X.509: Parse Basic Constraints for CA
Quoted 7 lines · Eric Snowberg
Parse the X.509 Basic Constraints. The basic constraints extension identifies whether the subject of the certificate is a CA.
BasicConstraints ::= SEQUENCE {
cA BOOLEAN DEFAULT FALSE,
pathLenConstraint INTEGER (0..MAX) OPTIONAL }
Quoted 5 lines
If the CA is true, store it in the
public_key. This will be used in a follow on patch that requires knowing if the public key is a CA.
Re: [PATCH v4 3/6] KEYS: X.509: Parse Basic Constraints for CA
In reply to Eric SnowbergQuoted 66 lines · Eric Snowberg
Parse the X.509 Basic Constraints. The basic constraints extension identifies whether the subject of the certificate is a CA.
BasicConstraints ::= SEQUENCE {
cA BOOLEAN DEFAULT FALSE,
pathLenConstraint INTEGER (0..MAX) OPTIONAL }If the CA is true, store it in the
public_key. This will be used in a follow on patch that requires knowing if the public key is a CA.Signed-off-by Eric Snowberg <[email protected]>--- crypto/asymmetric_keys/x509_cert_parser.c | 22 ++++++++++++++++++++++ include/crypto/public_key.h | 2 ++ 2 files changed, 24 insertions(+)crypto/asymmetric_keys/x509_cert_parser.c +22
-0@@ -586,6 +586,28 @@ int x509_process_extension(void *context, size_t hdrlen,return 0 ; } +if (ctx->last_oid == OID_basicConstraints) { +/* +* Get hold of the basicConstraints +* v[1] is the encoding size +* (Expect 0x2 or greater, making it 1 or more bytes) +* v[2] is the encoding type +* (Expect an ASN1_BOOL for the CA) +* v[3] is the contents of the ASN1_BOOL +* (Expect 1 if the CA is TRUE) +* vlen should match the entire extension size +*/ +if (v[0 ] != (ASN1_CONS_BIT |ASN1_SEQ )) +return -EBADMSG ; +if (vlen <2 ) +return -EBADMSG ; +if (v[1 ] != vlen -2 ) +return -EBADMSG ; +if (vlen >=4 && v[1 ] !=0 && v[2 ] ==ASN1_BOOL && v[3 ] ==1 ) + ctx->cert->pub->key_eflags |=1 <<KEY_EFLAG_CA ; +return 0 ; + } +return 0 ; }include/crypto/public_key.h +2
-0@@ -28,6 +28,8 @@ struct public_key {bool key_is_private;const char *id_type;const char *pkey_algo; +unsigned long key_eflags;/* key extension flags */ +#define KEY_EFLAG_CA 0/* set if the CA basic constraints is set */ };extern void public_key_free (struct public_key *key);Signature · 1 line
2.27.0
BR, Jarkko
Eric Snowberg
reviewerPATCH v4 4/6 KEYS: X.509: Parse Key Usage
In reply to Eric SnowbergParse the X.509 Key Usage. The key usage extension defines the purpose of the key contained in the certificate.
id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 }
KeyUsage ::= BIT STRING {
digitalSignature (0),
contentCommitment (1),
keyEncipherment (2),
dataEncipherment (3),
keyAgreement (4),
keyCertSign (5),
cRLSign (6),
encipherOnly (7),
decipherOnly (8) }If the keyCertSign or digitalSignature is set, store it in the public_key structure. This will be used in a follow on patch that requires knowing the certificate key usage type.
--- crypto/asymmetric_keys/x509_cert_parser.c | 28 +++++++++++++++++++++++ include/crypto/public_key.h | 2 ++ 2 files changed, 30 insertions(+)
crypto/asymmetric_keys/x509_cert_parser.c +28 -0
@@ -579,6 +579,34 @@ int x509_process_extension(void *context, size_t hdrlen,return 0 ; } +if (ctx->last_oid == OID_keyUsage) { +/* +* Get hold of the keyUsage bit string +* v[1] is the encoding size +* (Expect either 0x02 or 0x03, making it 1 or 2 bytes) +* v[2] is the number of unused bits in the bit string +* (If >= 3 keyCertSign is missing when v[1] = 0x02) +* v[3] and possibly v[4] contain the bit string +* +* From RFC 5280 4.2.1.3: +* 0x04 is where keyCertSign lands in this bit string +* 0x80 is where digitalSignature lands in this bit string +*/ +if (v[0 ] !=ASN1_BTS ) +return -EBADMSG ; +if (vlen <4 ) +return -EBADMSG ; +if (v[2 ] >=8 ) +return -EBADMSG ; +if (v[3 ] &0x80 ) + ctx->cert->pub->key_eflags |=1 <<KEY_EFLAG_DIGITALSIG ; +if (v[1 ] ==0x02 && v[2 ] <=2 && (v[3 ] &0x04 )) + ctx->cert->pub->key_eflags |=1 <<KEY_EFLAG_KEYCERTSIGN ; +else if (vlen >4 && v[1 ] ==0x03 && (v[3 ] &0x04 )) + ctx->cert->pub->key_eflags |=1 <<KEY_EFLAG_KEYCERTSIGN ; +return 0 ; + } +if (ctx->last_oid == OID_authorityKeyIdentifier) {/* Get hold of the CA key fingerprint */ ctx->raw_akid = v;
include/crypto/public_key.h +2 -0
@@ -30,6 +30,8 @@ struct public_key {const char *pkey_algo;unsigned long key_eflags;/* key extension flags */ #define KEY_EFLAG_CA 0/* set if the CA basic constraints is set */ +#define KEY_EFLAG_DIGITALSIG 1/* set if the digitalSignature usage is set */ +#define KEY_EFLAG_KEYCERTSIGN 2/* set if the keyCertSign usage is set */ };extern void public_key_free (struct public_key *key);
Signature · 1 line
2.27.0
Re: [PATCH v4 4/6] KEYS: X.509: Parse Key Usage
Quoted 16 lines · Eric Snowberg
Parse the X.509 Key Usage. The key usage extension defines the purpose of the key contained in the certificate.
id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 } KeyUsage ::= BIT STRING { digitalSignature (0), contentCommitment (1), keyEncipherment (2), dataEncipherment (3), keyAgreement (4), keyCertSign (5), cRLSign (6), encipherOnly (7), decipherOnly (8) }
Quoted 6 lines
If the keyCertSign or digitalSignature is set, store it in the
public_keystructure. This will be used in a follow on patch that requires knowing the certificate key usage type.
Jarkko Sakkinen
maintainerRe: [PATCH v4 4/6] KEYS: X.509: Parse Key Usage
In reply to Eric SnowbergQuoted 16 lines · Eric Snowberg
Parse the X.509 Key Usage. The key usage extension defines the purpose of the key contained in the certificate.
id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 } KeyUsage ::= BIT STRING { digitalSignature (0), contentCommitment (1), keyEncipherment (2), dataEncipherment (3), keyAgreement (4), keyCertSign (5), cRLSign (6), encipherOnly (7), decipherOnly (8) }
Quoted 3 lines
If the keyCertSign or digitalSignature is set, store it in the
public_keystructure. This will be used in a follow on patch that requires knowing the certificate key usage type.
It would be better to shortly explain why we want to know key usage type, rather than give zero information with "follow on patch".
Quoted 63 lines
Signed-off-by Eric Snowberg <[email protected]>--- crypto/asymmetric_keys/x509_cert_parser.c | 28 +++++++++++++++++++++++ include/crypto/public_key.h | 2 ++ 2 files changed, 30 insertions(+)crypto/asymmetric_keys/x509_cert_parser.c +28
-0@@ -579,6 +579,34 @@ int x509_process_extension(void *context, size_t hdrlen,return 0 ; } +if (ctx->last_oid == OID_keyUsage) { +/* +* Get hold of the keyUsage bit string +* v[1] is the encoding size +* (Expect either 0x02 or 0x03, making it 1 or 2 bytes) +* v[2] is the number of unused bits in the bit string +* (If >= 3 keyCertSign is missing when v[1] = 0x02) +* v[3] and possibly v[4] contain the bit string +* +* From RFC 5280 4.2.1.3: +* 0x04 is where keyCertSign lands in this bit string +* 0x80 is where digitalSignature lands in this bit string +*/ +if (v[0 ] !=ASN1_BTS ) +return -EBADMSG ; +if (vlen <4 ) +return -EBADMSG ; +if (v[2 ] >=8 ) +return -EBADMSG ; +if (v[3 ] &0x80 ) + ctx->cert->pub->key_eflags |=1 <<KEY_EFLAG_DIGITALSIG ; +if (v[1 ] ==0x02 && v[2 ] <=2 && (v[3 ] &0x04 )) + ctx->cert->pub->key_eflags |=1 <<KEY_EFLAG_KEYCERTSIGN ; +else if (vlen >4 && v[1 ] ==0x03 && (v[3 ] &0x04 )) + ctx->cert->pub->key_eflags |=1 <<KEY_EFLAG_KEYCERTSIGN ; +return 0 ; + } +if (ctx->last_oid == OID_authorityKeyIdentifier) {/* Get hold of the CA key fingerprint */ ctx->raw_akid = v;include/crypto/public_key.h +2
-0@@ -30,6 +30,8 @@ struct public_key {const char *pkey_algo;unsigned long key_eflags;/* key extension flags */ #define KEY_EFLAG_CA 0/* set if the CA basic constraints is set */ +#define KEY_EFLAG_DIGITALSIG 1/* set if the digitalSignature usage is set */ +#define KEY_EFLAG_KEYCERTSIGN 2/* set if the keyCertSign usage is set */ };extern void public_key_free (struct public_key *key);Signature · 1 line
2.27.0
BR, Jarkko
Eric Snowberg
reviewerRe: [PATCH v4 4/6] KEYS: X.509: Parse Key Usage
Quoted 21 lines · Jarkko Sakkinen
Quoted 16 lines · Eric Snowberg
Parse the X.509 Key Usage. The key usage extension defines the purpose of the key contained in the certificate.
id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 }
KeyUsage ::= BIT STRING { digitalSignature (0), contentCommitment (1), keyEncipherment (2), dataEncipherment (3), keyAgreement (4), keyCertSign (5), cRLSign (6), encipherOnly (7), decipherOnly (8) }
Quoted 6 lines
Quoted 3 lines
If the keyCertSign or digitalSignature is set, store it in the
public_keystructure. This will be used in a follow on patch that requires knowing the certificate key usage type.It would be better to shortly explain why we want to know key usage type, rather than give zero information with "follow on patch”.
Ok, I will add this in the next round, thanks.
Eric Snowberg
reviewerPATCH v4 5/6 KEYS: CA link restriction
In reply to Eric SnowbergAdd a new link restriction. Restrict the addition of keys in a keyring based on the key to be added being a CA.
--- crypto/asymmetric_keys/restrict.c | 38 +++++++++++++++++++++++++++++++ include/crypto/public_key.h | 15 ++++++++++++ 2 files changed, 53 insertions(+)
crypto/asymmetric_keys/restrict.c +38 -0
@@ -108,6 +108,44 @@ int restrict_link_by_signature(struct key *dest_keyring,return ret; } +/** +* restrict_link_by_ca - Restrict additions to a ring of CA keys +* @dest_keyring: Keyring being linked to. +* @type: The type of key being added. +* @payload: The payload of the new key. +* @trust_keyring: Unused. +* +* Check if the new certificate is a CA. If it is a CA, then mark the new +* certificate as being ok to link. +* +* Returns 0 if the new certificate was accepted, -ENOKEY if the +* certificate is not a CA. -ENOPKG if the signature uses unsupported +* crypto, or some other error if there is a matching certificate but +* the signature check cannot be performed. +*/ +int restrict_link_by_ca (struct key *dest_keyring, +const struct key_type *type, +const union key_payload *payload, +struct key *trust_keyring) +{ +const struct public_key *pkey; + +if (type != &key_type_asymmetric) +return -EOPNOTSUPP ; + + pkey = payload->data[asym_crypto]; +if (!pkey) +return -ENOPKG ; +if (!test_bit (KEY_EFLAG_CA , &pkey->key_eflags)) +return -ENOKEY ; +if (!test_bit (KEY_EFLAG_KEYCERTSIGN , &pkey->key_eflags)) +return -ENOKEY ; +if (test_bit (KEY_EFLAG_DIGITALSIG , &pkey->key_eflags)) +return -ENOKEY ; + +return 0 ; +} +static bool match_either_id (const struct asymmetric_key_id **pair,const struct asymmetric_key_id *single) {
include/crypto/public_key.h +15 -0
@@ -75,6 +75,21 @@ extern int restrict_link_by_key_or_keyring_chain(struct key *trust_keyring,const union key_payload *payload, struct key *trusted); +#if IS_REACHABLE (CONFIG_ASYMMETRIC_KEY_TYPE ) +extern int restrict_link_by_ca (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, +const union key_payload *payload, +struct key *trust_keyring) +{ +return 0 ; +} +#endif +extern int query_asymmetric_key (const struct kernel_pkey_params *,struct kernel_pkey_query *);
Signature · 1 line
2.27.0
Re: [PATCH v4 5/6] KEYS: CA link restriction
Quoted 4 lines · Eric Snowberg
Add a new link restriction. Restrict the addition of keys in a keyring based on the key to be added being a CA.
Signed-off-by Eric Snowberg <[email protected]>
Other than expanding the patch description to mention the keyUsage,
Eric Snowberg
reviewerPATCH v4 6/6 integrity: machine keyring CA configuration
In reply to Eric SnowbergAdd a machine keyring CA restriction menu option to control the type of keys that may be added to it. The options include none, min and max restrictions.
When no restrictions are selected, all Machine Owner Keys (MOK) are added to the machine keyring. When CONFIG_INTEGRITY_CA_MACHINE_KEYRING_MIN is selected, the CA bit must be true. Also the key usage must contain keyCertSign, any other usage field may be set as well.
When CONFIG_INTEGRITY_CA_MACHINE_KEYRING_MAX is selected, the CA bit must be true. Also the key usage must contain keyCertSign and the digitialSignature usage may not be set.
--- crypto/asymmetric_keys/restrict.c | 2 ++ security/integrity/Kconfig | 39 ++++++++++++++++++++++++++++++- security/integrity/digsig.c | 8 +++++-- 3 files changed, 46 insertions(+), 3 deletions(-)
crypto/asymmetric_keys/restrict.c +2 -0
@@ -140,6 +140,8 @@ int restrict_link_by_ca(struct key *dest_keyring,return -ENOKEY ;if (!test_bit (KEY_EFLAG_KEYCERTSIGN , &pkey->key_eflags))return -ENOKEY ; +if (IS_ENABLED (CONFIG_INTEGRITY_CA_MACHINE_KEYRING_MIN )) +return 0 ;if (test_bit (KEY_EFLAG_DIGITALSIG , &pkey->key_eflags))return -ENOKEY ;
security/integrity/Kconfig +38 -1
@@ -68,13 +68,50 @@ config INTEGRITY_MACHINE_KEYRING depends on INTEGRITY_ASYMMETRIC_KEYS depends on SYSTEM_BLACKLIST_KEYRING depends on LOAD_UEFI_KEYS - depends on !IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY help If set, provide a keyring to which Machine Owner Keys (MOK) may be added. This keyring shall contain just MOK keys. Unlike keys in the platform keyring, keys contained in the .machine keyring will be trusted within the kernel. +choice + prompt "Enforce Machine Keyring CA Restrictions" + default INTEGRITY_CA_MACHINE_KEYRING_NONE + depends on INTEGRITY_MACHINE_KEYRING + help + The .machine keyring can be configured to enforce CA restriction + on any key added to it. The options include none, min and max + restrictions. By default no restrictions are in place and all + Machine Owner Keys (MOK) are added to the machine keyring. + +config INTEGRITY_CA_MACHINE_KEYRING_NONE + bool "No restrictions" + help + When no restrictions are selected, all Machine Owner Keys (MOK) + are added to the machine keyring. MOK keys do not require the + CA bit to be set. The key usage field is ignored. This is the + default setting. + +config INTEGRITY_CA_MACHINE_KEYRING_MIN + bool "Only CA keys (with or without DigitialSignature usage set)" + help + When min is selected, only load CA keys into the machine keyring. + The CA bit must be set along with the keyCertSign Usage field. + Keys containing the digitialSignature Usage field will also be + loaded. The remaining MOK keys are loaded into the .platform + keyring. + +config INTEGRITY_CA_MACHINE_KEYRING_MAX + bool "Only CA keys" + help + When max is selected, only load CA keys into the machine keyring. + The CA bit must be set along with the keyCertSign Usage field. + Keys containing the digitialSignature Usage field will not be + loaded. The remaining MOK keys are loaded into the .platform + keyring. + +endchoice + config LOAD_UEFI_KEYS depends on INTEGRITY_PLATFORM_KEYRING depends on EFI
security/integrity/digsig.c +6 -2
@@ -132,7 +132,8 @@ int __init integrity_init_keyring(const unsigned int id) | KEY_USR_READ | KEY_USR_SEARCH;if (id ==INTEGRITY_KEYRING_PLATFORM || - id ==INTEGRITY_KEYRING_MACHINE ) { + (id ==INTEGRITY_KEYRING_MACHINE && +IS_ENABLED (CONFIG_INTEGRITY_CA_MACHINE_KEYRING_NONE ))) { restriction =NULL ; goto out; }
@@ -144,7 +145,10 @@ int __init integrity_init_keyring(const unsigned int id)if (!restriction)return -ENOMEM ; - restriction->check = restrict_link_to_ima; +if (id ==INTEGRITY_KEYRING_MACHINE ) + restriction->check = restrict_link_by_ca; +else + restriction->check = restrict_link_to_ima;/* * MOK keys can only be added through a read-only runtime services
Signature · 1 line
2.27.0
Mimi Zohar
maintainerRe: [PATCH v4 6/6] integrity: machine keyring CA configuration
Hi Eric,
Quoted 9 lines · Eric Snowberg
Add a machine keyring CA restriction menu option to control the type of keys that may be added to it. The options include none, min and max restrictions.
When no restrictions are selected, all Machine Owner Keys (MOK) are added to the machine keyring. When
CONFIG_INTEGRITY_CA_MACHINE_KEYRING_MINis selected, the CA bit must be true. Also the key usage must contain keyCertSign, any other usage field may be set as well.
Quoted 5 lines
When
CONFIG_INTEGRITY_CA_MACHINE_KEYRING_MAXis selected, the CA bit must be true. Also the key usage must contain keyCertSign and the digitialSignature usage may not be set.Signed-off-by Eric Snowberg <[email protected]>
Missing from the patch description is the motivation for this change. The choices none, min, max implies a progression, which is good, and the technical differences between the choices, but not the reason.
The motivation, at least from my perspective, is separation of certificate signing from code signing keys, where "none" is no separation and "max" being total separation of keys based on usage.
Subsequent work, as discussed in the cover letter thread, will limit certificates being loaded onto the IMA keyring to code signing keys used for signature verification.
thanks,
Mimi
Quoted 101 lines
--- crypto/asymmetric_keys/restrict.c | 2 ++ security/integrity/Kconfig | 39 ++++++++++++++++++++++++++++++- security/integrity/digsig.c | 8 +++++-- 3 files changed, 46 insertions(+), 3 deletions(-)crypto/asymmetric_keys/restrict.c +2
-0@@ -140,6 +140,8 @@ int restrict_link_by_ca(struct key *dest_keyring,return -ENOKEY ;if (!test_bit (KEY_EFLAG_KEYCERTSIGN , &pkey->key_eflags))return -ENOKEY ; +if (IS_ENABLED (CONFIG_INTEGRITY_CA_MACHINE_KEYRING_MIN )) +return 0 ;if (test_bit (KEY_EFLAG_DIGITALSIG , &pkey->key_eflags))return -ENOKEY ;security/integrity/Kconfig +38
-1@@ -68,13 +68,50 @@ config INTEGRITY_MACHINE_KEYRING depends on INTEGRITY_ASYMMETRIC_KEYS depends on SYSTEM_BLACKLIST_KEYRING depends on LOAD_UEFI_KEYS - depends on !IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY help If set, provide a keyring to which Machine Owner Keys (MOK) may be added. This keyring shall contain just MOK keys. Unlike keys in the platform keyring, keys contained in the .machine keyring will be trusted within the kernel. +choice + prompt "Enforce Machine Keyring CA Restrictions" + default INTEGRITY_CA_MACHINE_KEYRING_NONE + depends on INTEGRITY_MACHINE_KEYRING + help + The .machine keyring can be configured to enforce CA restriction + on any key added to it. The options include none, min and max + restrictions. By default no restrictions are in place and all + Machine Owner Keys (MOK) are added to the machine keyring. + +config INTEGRITY_CA_MACHINE_KEYRING_NONE + bool "No restrictions" + help + When no restrictions are selected, all Machine Owner Keys (MOK) + are added to the machine keyring. MOK keys do not require the + CA bit to be set. The key usage field is ignored. This is the + default setting. + +config INTEGRITY_CA_MACHINE_KEYRING_MIN + bool "Only CA keys (with or without DigitialSignature usage set)" + help + When min is selected, only load CA keys into the machine keyring. + The CA bit must be set along with the keyCertSign Usage field. + Keys containing the digitialSignature Usage field will also be + loaded. The remaining MOK keys are loaded into the .platform + keyring. + +config INTEGRITY_CA_MACHINE_KEYRING_MAX + bool "Only CA keys" + help + When max is selected, only load CA keys into the machine keyring. + The CA bit must be set along with the keyCertSign Usage field. + Keys containing the digitialSignature Usage field will not be + loaded. The remaining MOK keys are loaded into the .platform + keyring. + +endchoice + config LOAD_UEFI_KEYS depends on INTEGRITY_PLATFORM_KEYRING depends on EFIsecurity/integrity/digsig.c +6
-2@@ -132,7 +132,8 @@ int __init integrity_init_keyring(const unsigned int id) | KEY_USR_READ | KEY_USR_SEARCH;if (id ==INTEGRITY_KEYRING_PLATFORM || - id ==INTEGRITY_KEYRING_MACHINE ) { + (id ==INTEGRITY_KEYRING_MACHINE && +IS_ENABLED (CONFIG_INTEGRITY_CA_MACHINE_KEYRING_NONE ))) { restriction =NULL ; goto out; }@@ -144,7 +145,10 @@ int __init integrity_init_keyring(const unsigned int id)if (!restriction)return -ENOMEM ; - restriction->check = restrict_link_to_ima; +if (id ==INTEGRITY_KEYRING_MACHINE ) + restriction->check = restrict_link_by_ca; +else + restriction->check = restrict_link_to_ima;/* * MOK keys can only be added through a read-only runtime services
Eric Snowberg
reviewerRe: [PATCH v4 6/6] integrity: machine keyring CA configuration
Quoted 26 lines · Mimi Zohar
Hi Eric,
Quoted 9 lines · Eric Snowberg
Add a machine keyring CA restriction menu option to control the type of keys that may be added to it. The options include none, min and max restrictions.
When no restrictions are selected, all Machine Owner Keys (MOK) are added to the machine keyring. When
CONFIG_INTEGRITY_CA_MACHINE_KEYRING_MINis selected, the CA bit must be true. Also the key usage must contain keyCertSign, any other usage field may be set as well.Quoted 5 lines
When
CONFIG_INTEGRITY_CA_MACHINE_KEYRING_MAXis selected, the CA bit must be true. Also the key usage must contain keyCertSign and the digitialSignature usage may not be set.Signed-off-by Eric Snowberg <[email protected]>Missing from the patch description is the motivation for this change. The choices none, min, max implies a progression, which is good, and the technical differences between the choices, but not the reason.
Quoted 7 lines
The motivation, at least from my perspective, is separation of certificate signing from code signing keys, where "none" is no separation and "max" being total separation of keys based on usage.
Subsequent work, as discussed in the cover letter thread, will limit certificates being loaded onto the IMA keyring to code signing keys used for signature verification.
I will include this in the next round too, thanks.
Jarkko Sakkinen
maintainerRe: [PATCH v4 6/6] integrity: machine keyring CA configuration
In reply to Mimi ZoharQuoted 22 lines · Mimi Zohar
Hi Eric,
Quoted 9 lines · Eric Snowberg
Add a machine keyring CA restriction menu option to control the type of keys that may be added to it. The options include none, min and max restrictions.
When no restrictions are selected, all Machine Owner Keys (MOK) are added to the machine keyring. When
CONFIG_INTEGRITY_CA_MACHINE_KEYRING_MINis selected, the CA bit must be true. Also the key usage must contain keyCertSign, any other usage field may be set as well.Quoted 5 lines
When
CONFIG_INTEGRITY_CA_MACHINE_KEYRING_MAXis selected, the CA bit must be true. Also the key usage must contain keyCertSign and the digitialSignature usage may not be set.Signed-off-by Eric Snowberg <[email protected]>Missing from the patch description is the motivation for this change. The choices none, min, max implies a progression, which is good, and the technical differences between the choices, but not the reason.
Quoted 7 lines
The motivation, at least from my perspective, is separation of certificate signing from code signing keys, where "none" is no separation and "max" being total separation of keys based on usage.
Subsequent work, as discussed in the cover letter thread, will limit certificates being loaded onto the IMA keyring to code signing keys used for signature verification.
It would be more robust just to have two binary options for CA bit and keyCertSign. You can use "select" for setting keyCertSign, when CA bit option is selected.
BR, Jarkko
Eric Snowberg
reviewerRe: [PATCH v4 6/6] integrity: machine keyring CA configuration
Quoted 31 lines · Jarkko Sakkinen
Quoted 26 lines · Mimi Zohar
Hi Eric,
Quoted 9 lines · Eric Snowberg
Add a machine keyring CA restriction menu option to control the type of keys that may be added to it. The options include none, min and max restrictions.
When no restrictions are selected, all Machine Owner Keys (MOK) are added to the machine keyring. When
CONFIG_INTEGRITY_CA_MACHINE_KEYRING_MINis selected, the CA bit must be true. Also the key usage must contain keyCertSign, any other usage field may be set as well.Quoted 5 lines
When
CONFIG_INTEGRITY_CA_MACHINE_KEYRING_MAXis selected, the CA bit must be true. Also the key usage must contain keyCertSign and the digitialSignature usage may not be set.Signed-off-by Eric Snowberg <[email protected]>Missing from the patch description is the motivation for this change. The choices none, min, max implies a progression, which is good, and the technical differences between the choices, but not the reason.
The motivation, at least from my perspective, is separation of certificate signing from code signing keys, where "none" is no separation and "max" being total separation of keys based on usage.
Quoted 8 lines
Quoted 3 lines
Subsequent work, as discussed in the cover letter thread, will limit certificates being loaded onto the IMA keyring to code signing keys used for signature verification.
It would be more robust just to have two binary options for CA bit and keyCertSign. You can use "select" for setting keyCertSign, when CA bit option is selected.
Ok, I will make that change in the next round, thanks.
Mimi Zohar
maintainer[CC'ing: Lee, Chun-Yi]
Quoted 40 lines · Eric Snowberg
Prior to the introduction of the machine keyring, most distros simply allowed all keys contained within the platform keyring to be used for both kernel and module verification. This was done by an out of tree patch. Some distros took it even further and loaded all these keys into the secondary trusted keyring. This also allowed the system owner to add their own key for IMA usage.
Each distro contains similar documentation on how to sign kernel modules and enroll the key into the MOK. The process is fairly straightforward. With the introduction of the machine keyring, the process remains basically the same, without the need for any out of tree patches.
The machine keyring allowed distros to eliminate the out of tree patches for kernel module signing. However, it falls short in allowing the end user to add their own keys for IMA. Currently, the machine keyring can not be used as another trust anchor for adding keys to the ima keyring, since CA enforcement does not currently exist. This would expand the current integrity gap. The
IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARYKconfigstates that keys may be added to the ima keyrings if the key is validly signed by a CA cert in the system built-in or secondary trusted keyring. Currently, there is not code that enforces the contents of a CA cert.This series introduces a way to do CA enforement with the machine keyring. It introduces three different ways to configure the machine keyring. A new menu option is added to control the type of keys that may be added to it. The options include none, min, and max restrictions. The default is
CONFIG_INTEGRITY_CA_MACHINE_KEYRING_NONE. This allows all MOK keys into the machine keyring. WhenCONFIG_INTEGRITY_CA_MACHINE_KEYRING_MINis selected, the X.509 CA bit must be true. Also, the key usage must contain keyCertSign, any other usage field may also be set. WhenCONFIG_INTEGRITY_CA_MACHINE_KEYRING_MAXis selected, the X.509 CA bit must be true. Also, the key usage must contain keyCertSign and the digitialSignature usage may not be set. If a key doesn't pass the CA restriction check, instead of going into the machine keyring, it is added to the platform keyring. With the ability to configure the machine keyring with CA restrictions, code that prevented the machine keyring from being enabled withIMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARYhas been removed.
Quoted 8 lines
Changelog:
v4:
- Removed all code that validated the certificate chain back to the root CA. Now the only restriction is what is initially placed in the machine keyring.
- Check and store if the X.509 usage contains digitalSignature
- NewKconfigmenu item with none, min and max CA restriction on the machine keyring
Thank you, Eric.
For complete separation of certificate usage, at least in the "max" CA restriction case, the next step would be to limit certificates being loaded onto the IMA keyring to those with key usage of "digitalSignature".
Perhaps also require a "codeSigning" extendedKeyUsage, though that might break existing usages. The "codeSigning" checking could piggyback on Joey's proposed "Check codeSigning extended key usage extension" patch set.
What do you think? Do you have any concerns with limiting the type of certificate being loaded onto the IMA keyring to those with "digitalSignature"?
Signature · 3 lines
thanks, Mimi
Eric Snowberg
reviewerQuoted 63 lines · Mimi Zohar
[CC'ing: Lee, Chun-Yi]
Quoted 40 lines · Eric Snowberg
Prior to the introduction of the machine keyring, most distros simply allowed all keys contained within the platform keyring to be used for both kernel and module verification. This was done by an out of tree patch. Some distros took it even further and loaded all these keys into the secondary trusted keyring. This also allowed the system owner to add their own key for IMA usage.
Each distro contains similar documentation on how to sign kernel modules and enroll the key into the MOK. The process is fairly straightforward. With the introduction of the machine keyring, the process remains basically the same, without the need for any out of tree patches.
The machine keyring allowed distros to eliminate the out of tree patches for kernel module signing. However, it falls short in allowing the end user to add their own keys for IMA. Currently, the machine keyring can not be used as another trust anchor for adding keys to the ima keyring, since CA enforcement does not currently exist. This would expand the current integrity gap. The
IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARYKconfigstates that keys may be added to the ima keyrings if the key is validly signed by a CA cert in the system built-in or secondary trusted keyring. Currently, there is not code that enforces the contents of a CA cert.This series introduces a way to do CA enforement with the machine keyring. It introduces three different ways to configure the machine keyring. A new menu option is added to control the type of keys that may be added to it. The options include none, min, and max restrictions. The default is
CONFIG_INTEGRITY_CA_MACHINE_KEYRING_NONE. This allows all MOK keys into the machine keyring. WhenCONFIG_INTEGRITY_CA_MACHINE_KEYRING_MINis selected, the X.509 CA bit must be true. Also, the key usage must contain keyCertSign, any other usage field may also be set. WhenCONFIG_INTEGRITY_CA_MACHINE_KEYRING_MAXis selected, the X.509 CA bit must be true. Also, the key usage must contain keyCertSign and the digitialSignature usage may not be set. If a key doesn't pass the CA restriction check, instead of going into the machine keyring, it is added to the platform keyring. With the ability to configure the machine keyring with CA restrictions, code that prevented the machine keyring from being enabled withIMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARYhas been removed.Quoted 8 lines
Changelog:
v4:
- Removed all code that validated the certificate chain back to the root CA. Now the only restriction is what is initially placed in the machine keyring.
- Check and store if the X.509 usage contains digitalSignature
- NewKconfigmenu item with none, min and max CA restriction on the machine keyringThank you, Eric.
For complete separation of certificate usage, at least in the "max" CA restriction case, the next step would be to limit certificates being loaded onto the IMA keyring to those with key usage of "digitalSignature".
Quoted 8 lines
Perhaps also require a "codeSigning" extendedKeyUsage, though that might break existing usages. The "codeSigning" checking could piggyback on Joey's proposed "Check codeSigning extended key usage extension" patch set.
What do you think? Do you have any concerns with limiting the type of certificate being loaded onto the IMA keyring to those with "digitalSignature"?
In the MAX setting I would not have a concern. Instead of restrict_link_to_ima being a macro, a new restriction similar to restrict_link_by_ca could be created. The new restriction would simply verify digitialSignature is set and the key can be vouched for by either the built-in or secondary keyrings. Joey’s work to parse the extended key usage extension could also be included in this restriction.
I’m assuming this would be follow on work?
Mimi Zohar
maintainerQuoted 71 lines · Eric Snowberg
Quoted 62 lines · Mimi Zohar
[CC'ing: Lee, Chun-Yi]
Quoted 40 lines · Eric Snowberg
Prior to the introduction of the machine keyring, most distros simply allowed all keys contained within the platform keyring to be used for both kernel and module verification. This was done by an out of tree patch. Some distros took it even further and loaded all these keys into the secondary trusted keyring. This also allowed the system owner to add their own key for IMA usage.
Each distro contains similar documentation on how to sign kernel modules and enroll the key into the MOK. The process is fairly straightforward. With the introduction of the machine keyring, the process remains basically the same, without the need for any out of tree patches.
The machine keyring allowed distros to eliminate the out of tree patches for kernel module signing. However, it falls short in allowing the end user to add their own keys for IMA. Currently, the machine keyring can not be used as another trust anchor for adding keys to the ima keyring, since CA enforcement does not currently exist. This would expand the current integrity gap. The
IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARYKconfigstates that keys may be added to the ima keyrings if the key is validly signed by a CA cert in the system built-in or secondary trusted keyring. Currently, there is not code that enforces the contents of a CA cert.This series introduces a way to do CA enforement with the machine keyring. It introduces three different ways to configure the machine keyring. A new menu option is added to control the type of keys that may be added to it. The options include none, min, and max restrictions. The default is
CONFIG_INTEGRITY_CA_MACHINE_KEYRING_NONE. This allows all MOK keys into the machine keyring. WhenCONFIG_INTEGRITY_CA_MACHINE_KEYRING_MINis selected, the X.509 CA bit must be true. Also, the key usage must contain keyCertSign, any other usage field may also be set. WhenCONFIG_INTEGRITY_CA_MACHINE_KEYRING_MAXis selected, the X.509 CA bit must be true. Also, the key usage must contain keyCertSign and the digitialSignature usage may not be set. If a key doesn't pass the CA restriction check, instead of going into the machine keyring, it is added to the platform keyring. With the ability to configure the machine keyring with CA restrictions, code that prevented the machine keyring from being enabled withIMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARYhas been removed.Quoted 8 lines
Changelog:
v4:
- Removed all code that validated the certificate chain back to the root CA. Now the only restriction is what is initially placed in the machine keyring.
- Check and store if the X.509 usage contains digitalSignature
- NewKconfigmenu item with none, min and max CA restriction on the machine keyringThank you, Eric.
For complete separation of certificate usage, at least in the "max" CA restriction case, the next step would be to limit certificates being loaded onto the IMA keyring to those with key usage of "digitalSignature".
Quoted 8 lines
Perhaps also require a "codeSigning" extendedKeyUsage, though that might break existing usages. The "codeSigning" checking could piggyback on Joey's proposed "Check codeSigning extended key usage extension" patch set.
What do you think? Do you have any concerns with limiting the type of certificate being loaded onto the IMA keyring to those with "digitalSignature"?
Quoted 5 lines
In the MAX setting I would not have a concern. Instead of
restrict_link_to_imabeing a macro, a new restriction similar torestrict_link_by_cacould be created. The new restriction would simply verify digitialSignature is set and the key can be vouched for by either the built-in or secondary keyrings. Joey’s work to parse the extended key usage extension could also be included in this restriction.
Sounds good.
Quoted 1 line
I’m assuming this would be follow on work?
Yes, that probably makes the most sense.
Signature · 3 lines
thanks, Mimi