From: "Jarkko Sakkinen" <jarkko@kernel.org>
To: "Denis Glazkov" <d.glazkov@omp.ru>
Cc: "dhowells@redhat.com" <dhowells@redhat.com>,
"dwmw2@infradead.org" <dwmw2@infradead.org>,
"keyrings@vger.kernel.org" <keyrings@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Sergey Shtylyov" <s.shtylyov@omp.ru>
Subject: Re: [PATCH v3] certs: Add option to disallow non-CA certificates in secondary trusted keying
Date: Tue, 03 Oct 2023 02:49:53 +0300 [thread overview]
Message-ID: <CVYCTWRQAXDF.2HY5028ZT9FEC@seitikki> (raw)
In-Reply-To: <20231002104525.7631-1-d.glazkov@omp.ru>
On Mon Oct 2, 2023 at 1:46 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 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. This will
> help avoid similar problems when new features appear in the linux
> kernel that are similar to kernel modules in terms of their impact
> on system security, which will also use trusted certificates for
> signature verification.
>
> 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
>
> v2 -> v3:
> - Add the purpose and goal of the patch to the commit message
> ---
> certs/Kconfig | 9 +++++++++
> certs/system_keyring.c | 16 ++++++++++++++++
> 2 files changed, 25 insertions(+)
>
> 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);
> }
> --
> 2.34.1
I don't think this does any harm. What do you think Mimi?
BR, Jarkko
next prev parent reply other threads:[~2023-10-02 23:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-06 11:32 [PATCH] certs: Add the ability to add only CA certificates to the secondary trusted keyring Denis Glazkov
2023-09-06 12:58 ` Sergey Shtylyov
2023-09-08 12:14 ` [PATCH v2] certs: Add option to disallow non-CA certificates in secondary trusted keying Denis Glazkov
2023-09-11 21:15 ` Jarkko Sakkinen
2023-09-15 17:50 ` Denis Glazkov
2023-09-25 16:54 ` Jarkko Sakkinen
2023-10-02 10:46 ` [PATCH v3] " Denis Glazkov
2023-10-02 23:49 ` Jarkko Sakkinen [this message]
2023-10-03 19:04 ` Eric Snowberg
2023-10-05 21:33 ` Denis Glazkov
2023-10-09 14:10 ` Mimi Zohar
2023-10-17 12:43 ` Mimi Zohar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CVYCTWRQAXDF.2HY5028ZT9FEC@seitikki \
--to=jarkko@kernel.org \
--cc=d.glazkov@omp.ru \
--cc=dhowells@redhat.com \
--cc=dwmw2@infradead.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=s.shtylyov@omp.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®