Message ID | 20230908121330.4076-1-d.glazkov@omp.ru (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [v2] certs: Add option to disallow non-CA certificates in secondary trusted keying | expand |
On Fri Sep 8, 2023 at 3:14 PM EEST, Denis Glazkov wrote: > The Linux kernel has an IMA (Integrity Measurement Architecture) > subsystem to check the integrity of the file system based on digital > signatures. IMA uses certificates in `.ima` keying to check integrity. > > Only certificates issued by one of the trusted CA (Certificate Authority) > certificates can be added to the `.ima` keying. > > The Linux kernel now has a secondary trusted keying to which trusted > certificates from user space can be added if you have superuser > privileges. Previously, all trusted certificates were in the built-in > trusted keying, which could not be modified from user space. > Trusted certificates were placed in the built-in trusted keying at > kernel compile time. > > The secondary trusted keying is designed so that any certificates that > are signed by one of the trusted CA certificates in the built-in or > secondary trusted keyring can be added to it. > > Let's imagine that we have the following certificate trust chain: > > ┌───────────────────────────┬─────────────────────┐ > │ │ ┌───────┐ │ > │ │ │ │ │ > ┌────────────▼────────┐ ┌─────────────▼─────▼────┐ │ ┌─────┴─────┐ > │.builtin_trusted_keys│◄───┤.secondary_trusted_keys ├──┘ │ .ima │ > ├─────────────────────┤ ├────────────────────────┤ ├───────────┤ > │ Root CA Cert │-----► Intermediate CA Cert │-----► IMA Cert │ > └─────────────────────┘ └────────────────────────┘ └───────────┘ > > Issues Restricted by > -------------► ──────────────► > > Since the IMA certificate is signed by a CA certificate from a secondary > trusted keying, an attacker with superuser privileges will be able to > add the IMA certificate to the secondary trusted keying. That is, the IMA > certificate will become trusted. > > Since, with `CONFIG_MODULE_SIG` option enabled, modules can only be > loaded into kernel space if they are signed with one of the trusted > certificates, an attacker could sign untrusted kernel modules with > the private key corresponding to the IMA certificate and successfully > load the untrusted modules into kernel space. > > This patch adds the configuration that once enabled, only > certificates that meet the following requirements can be added > to the secondary trusted keying: > > 1. The certificate is a CA (Certificate Authority) > 2. The certificate must be used for verifying a CA's signatures > 3. The certificate must not be used for digital signatures > > Signed-off-by: Denis Glazkov <d.glazkov@omp.ru> s/keying/keyring/ (multiple) Have you considered instead making mod_verify_sig() more robust? Obviously this would mean making selection of keys in verify_pkcs7_signature() more robust (see the documentation of 'trusted_keys'). The this would be also less niche feature to pick for distributors if it was just concerning module loading, and have associated config flag over there. BR, Jarkko
On Tue, Sep 12 2023 at 01:15 AM +0300, Jarkko Sakkinen wrote: > On Fri Sep 8, 2023 at 3:14 PM EEST, Denis Glazkov wrote: > > The Linux kernel has an IMA (Integrity Measurement Architecture) > > subsystem to check the integrity of the file system based on digital > > signatures. IMA uses certificates in `.ima` keying to check integrity. > > > > Only certificates issued by one of the trusted CA (Certificate Authority) > > certificates can be added to the `.ima` keying. > > > > The Linux kernel now has a secondary trusted keying to which trusted > > certificates from user space can be added if you have superuser > > privileges. Previously, all trusted certificates were in the built-in > > trusted keying, which could not be modified from user space. > > Trusted certificates were placed in the built-in trusted keying at > > kernel compile time. > > > > The secondary trusted keying is designed so that any certificates that > > are signed by one of the trusted CA certificates in the built-in or > > secondary trusted keyring can be added to it. > > > > Let's imagine that we have the following certificate trust chain: > > > > ┌───────────────────────────┬─────────────────────┐ > > │ │ ┌───────┐ │ > > │ │ │ │ │ > > ┌────────────▼────────┐ ┌─────────────▼─────▼────┐ │ ┌─────┴─────┐ > > │.builtin_trusted_keys│◄───┤.secondary_trusted_keys ├──┘ │ .ima │ > > ├─────────────────────┤ ├────────────────────────┤ ├───────────┤ > > │ Root CA Cert │-----► Intermediate CA Cert │-----► IMA Cert │ > > └─────────────────────┘ └────────────────────────┘ └───────────┘ > > > > Issues Restricted by > > -------------► ──────────────► > > > > Since the IMA certificate is signed by a CA certificate from a secondary > > trusted keying, an attacker with superuser privileges will be able to > > add the IMA certificate to the secondary trusted keying. That is, the IMA > > certificate will become trusted. > > > > Since, with `CONFIG_MODULE_SIG` option enabled, modules can only be > > loaded into kernel space if they are signed with one of the trusted > > certificates, an attacker could sign untrusted kernel modules with > > the private key corresponding to the IMA certificate and successfully > > load the untrusted modules into kernel space. > > > > This patch adds the configuration that once enabled, only > > certificates that meet the following requirements can be added > > to the secondary trusted keying: > > > > 1. The certificate is a CA (Certificate Authority) > > 2. The certificate must be used for verifying a CA's signatures > > 3. The certificate must not be used for digital signatures > > > > Signed-off-by: Denis Glazkov <d.glazkov@omp.ru> > > s/keying/keyring/ (multiple) > > Have you considered instead making mod_verify_sig() more robust? > Obviously this would mean making selection of keys in > verify_pkcs7_signature() more robust (see the documentation of > 'trusted_keys'). > > The this would be also less niche feature to pick for distributors > if it was just concerning module loading, and have associated config > flag over there. > > BR, Jarkko Jarkko, thank you for your suggestion. This patch was created not to solve only the problem of loading untrusted kernel modules, but to make it possible to use a secondary trusted keying only as a part of a chain of trust containing only CA certificates with no digital signature capability. Let's imagine that tomorrow we have a new kernel feature, similar to kernel modules in terms of its impact on system security, which also uses trusted certificates for signature verification. If at this point we solve only the problem of loading untrusted kernel modules, and not the problem of the entire trusted keys system, we will need to add a new kernel option each time to solve a similar problem for each new kernel feature that uses trusted certificates. BR, Denis
On Fri Sep 15, 2023 at 8:50 PM EEST, Denis Glazkov wrote: > On Tue, Sep 12 2023 at 01:15 AM +0300, Jarkko Sakkinen wrote: > > On Fri Sep 8, 2023 at 3:14 PM EEST, Denis Glazkov wrote: > > > The Linux kernel has an IMA (Integrity Measurement Architecture) > > > subsystem to check the integrity of the file system based on digital > > > signatures. IMA uses certificates in `.ima` keying to check integrity. > > > > > > Only certificates issued by one of the trusted CA (Certificate Authority) > > > certificates can be added to the `.ima` keying. > > > > > > The Linux kernel now has a secondary trusted keying to which trusted > > > certificates from user space can be added if you have superuser > > > privileges. Previously, all trusted certificates were in the built-in > > > trusted keying, which could not be modified from user space. > > > Trusted certificates were placed in the built-in trusted keying at > > > kernel compile time. > > > > > > The secondary trusted keying is designed so that any certificates that > > > are signed by one of the trusted CA certificates in the built-in or > > > secondary trusted keyring can be added to it. > > > > > > Let's imagine that we have the following certificate trust chain: > > > > > > ┌───────────────────────────┬─────────────────────┐ > > > │ │ ┌───────┐ │ > > > │ │ │ │ │ > > > ┌────────────▼────────┐ ┌─────────────▼─────▼────┐ │ ┌─────┴─────┐ > > > │.builtin_trusted_keys│◄───┤.secondary_trusted_keys ├──┘ │ .ima │ > > > ├─────────────────────┤ ├────────────────────────┤ ├───────────┤ > > > │ Root CA Cert │-----► Intermediate CA Cert │-----► IMA Cert │ > > > └─────────────────────┘ └────────────────────────┘ └───────────┘ > > > > > > Issues Restricted by > > > -------------► ──────────────► > > > > > > Since the IMA certificate is signed by a CA certificate from a secondary > > > trusted keying, an attacker with superuser privileges will be able to > > > add the IMA certificate to the secondary trusted keying. That is, the IMA > > > certificate will become trusted. > > > > > > Since, with `CONFIG_MODULE_SIG` option enabled, modules can only be > > > loaded into kernel space if they are signed with one of the trusted > > > certificates, an attacker could sign untrusted kernel modules with > > > the private key corresponding to the IMA certificate and successfully > > > load the untrusted modules into kernel space. > > > > > > This patch adds the configuration that once enabled, only > > > certificates that meet the following requirements can be added > > > to the secondary trusted keying: > > > > > > 1. The certificate is a CA (Certificate Authority) > > > 2. The certificate must be used for verifying a CA's signatures > > > 3. The certificate must not be used for digital signatures > > > > > > Signed-off-by: Denis Glazkov <d.glazkov@omp.ru> > > > > s/keying/keyring/ (multiple) > > > > Have you considered instead making mod_verify_sig() more robust? > > Obviously this would mean making selection of keys in > > verify_pkcs7_signature() more robust (see the documentation of > > 'trusted_keys'). > > > > The this would be also less niche feature to pick for distributors > > if it was just concerning module loading, and have associated config > > flag over there. > > > > BR, Jarkko > > Jarkko, thank you for your suggestion. > > This patch was created not to solve only the problem of loading > untrusted kernel modules, but to make it possible to use a secondary > trusted keying only as a part of a chain of trust containing only > CA certificates with no digital signature capability. > > Let's imagine that tomorrow we have a new kernel feature, similar > to kernel modules in terms of its impact on system security, which > also uses trusted certificates for signature verification. > > If at this point we solve only the problem of loading untrusted > kernel modules, and not the problem of the entire trusted keys > system, we will need to add a new kernel option each time to solve > a similar problem for each new kernel feature that uses trusted > certificates. Ok, I guessed so but given what I read from commit message I had to ask :-) The description is very detailed and of good quality, and also what you say CONFIG_MODULE_SIG is just fine but for completeness it would be good to mention that purpose and goal is to fully close the gap with any possible feature that might go without CA certificates (*in addition*). > BR, Denis BR, Jarkko
diff --git a/certs/Kconfig b/certs/Kconfig index 1f109b070877..4a4dc8aab892 100644 --- a/certs/Kconfig +++ b/certs/Kconfig @@ -90,6 +90,15 @@ config SECONDARY_TRUSTED_KEYRING those keys are not blacklisted and are vouched for by a key built into the kernel or already in the secondary trusted keyring. +config SECONDARY_TRUSTED_KEYRING_FOR_CA_CERTIFICATES_ONLY + bool "Allow only CA certificates to be added to the secondary trusted keyring" + depends on SECONDARY_TRUSTED_KEYRING + help + If set, only CA certificates can be added to the secondary trusted keyring. + An acceptable CA certificate must include the `keyCertSign` value in + the `keyUsage` field. CA certificates that include the `digitalSignature` + value in the `keyUsage` field will not be accepted. + config SYSTEM_BLACKLIST_KEYRING bool "Provide system-wide ring of blacklisted keys" depends on KEYS diff --git a/certs/system_keyring.c b/certs/system_keyring.c index 9de610bf1f4b..ee14447374e7 100644 --- a/certs/system_keyring.c +++ b/certs/system_keyring.c @@ -99,6 +99,22 @@ int restrict_link_by_builtin_and_secondary_trusted( /* Allow the builtin keyring to be added to the secondary */ return 0; + if (IS_ENABLED(CONFIG_SECONDARY_TRUSTED_KEYRING_FOR_CA_CERTIFICATES_ONLY) && + dest_keyring == secondary_trusted_keys) { + const struct public_key *pub = payload->data[asym_crypto]; + + if (type != &key_type_asymmetric) + return -EOPNOTSUPP; + if (!pub) + return -ENOPKG; + if (!test_bit(KEY_EFLAG_CA, &pub->key_eflags)) + return -EPERM; + if (!test_bit(KEY_EFLAG_KEYCERTSIGN, &pub->key_eflags)) + return -EPERM; + if (test_bit(KEY_EFLAG_DIGITALSIG, &pub->key_eflags)) + return -EPERM; + } + return restrict_link_by_signature(dest_keyring, type, payload, secondary_trusted_keys); }
The Linux kernel has an IMA (Integrity Measurement Architecture) subsystem to check the integrity of the file system based on digital signatures. IMA uses certificates in `.ima` keying to check integrity. Only certificates issued by one of the trusted CA (Certificate Authority) certificates can be added to the `.ima` keying. The Linux kernel now has a secondary trusted keying to which trusted certificates from user space can be added if you have superuser privileges. Previously, all trusted certificates were in the built-in trusted keying, which could not be modified from user space. Trusted certificates were placed in the built-in trusted keying at kernel compile time. The secondary trusted keying is designed so that any certificates that are signed by one of the trusted CA certificates in the built-in or secondary trusted keyring can be added to it. Let's imagine that we have the following certificate trust chain: ┌───────────────────────────┬─────────────────────┐ │ │ ┌───────┐ │ │ │ │ │ │ ┌────────────▼────────┐ ┌─────────────▼─────▼────┐ │ ┌─────┴─────┐ │.builtin_trusted_keys│◄───┤.secondary_trusted_keys ├──┘ │ .ima │ ├─────────────────────┤ ├────────────────────────┤ ├───────────┤ │ Root CA Cert │-----► Intermediate CA Cert │-----► IMA Cert │ └─────────────────────┘ └────────────────────────┘ └───────────┘ Issues Restricted by -------------► ──────────────► Since the IMA certificate is signed by a CA certificate from a secondary trusted keying, an attacker with superuser privileges will be able to add the IMA certificate to the secondary trusted keying. That is, the IMA certificate will become trusted. Since, with `CONFIG_MODULE_SIG` option enabled, modules can only be loaded into kernel space if they are signed with one of the trusted certificates, an attacker could sign untrusted kernel modules with the private key corresponding to the IMA certificate and successfully load the untrusted modules into kernel space. This patch adds the configuration that once enabled, only certificates that meet the following requirements can be added to the secondary trusted keying: 1. The certificate is a CA (Certificate Authority) 2. The certificate must be used for verifying a CA's signatures 3. The certificate must not be used for digital signatures Signed-off-by: Denis Glazkov <d.glazkov@omp.ru> --- v1 -> v2: - Rebase the patch from `linux-next` to the main `linux` repo master branch - Make the commit message more detailed - Move the variable declaration to the `if` block - Replace `#ifdef` with `IS_ENABLED` macro --- certs/Kconfig | 9 +++++++++ certs/system_keyring.c | 16 ++++++++++++++++ 2 files changed, 25 insertions(+)