Hi,
This new patch series is a rebase on v5.14-rc1 . David or Jarkko, if
it's still OK with you, could you please push this to linux-next?
I successfully tested this patch series with the 211 entries from
https://uefi.org/sites/default/files/resources/dbxupdate_x64.bin
The goal of these patches is to add a new configuration option to enable the
root user to load signed keys in the blacklist keyring. This keyring is useful
to "untrust" certificates or files. Enabling to safely update this keyring
without recompiling the kernel makes it more usable.
Previous patch series:
https://lore.kernel.org/lkml/20210312171232.2681989-1-mic@digikod.net/
Regards,
Mickaël Salaün (5):
tools/certs: Add print-cert-tbs-hash.sh
certs: Check that builtin blacklist hashes are valid
certs: Make blacklist_vet_description() more strict
certs: Factor out the blacklist hash creation
certs: Allow root user to append signed hashes to the blacklist
keyring
MAINTAINERS | 2 +
certs/.gitignore | 1 +
certs/Kconfig | 17 +-
certs/Makefile | 17 +-
certs/blacklist.c | 218 ++++++++++++++----
crypto/asymmetric_keys/x509_public_key.c | 3 +-
include/keys/system_keyring.h | 14 +-
scripts/check-blacklist-hashes.awk | 37 +++
.../platform_certs/keyring_handler.c | 26 +--
tools/certs/print-cert-tbs-hash.sh | 91 ++++++++
10 files changed, 346 insertions(+), 80 deletions(-)
create mode 100755 scripts/check-blacklist-hashes.awk
create mode 100755 tools/certs/print-cert-tbs-hash.sh
base-commit: e73f0f0ee7541171d89f2e2491130c7771ba58d3
--
2.32.0
From: Mickaël Salaün <redacted>
Add and use a check-blacklist-hashes.awk script to make sure that the
builtin blacklist hashes set with CONFIG_SYSTEM_BLACKLIST_HASH_LIST will
effectively be taken into account as blacklisted hashes. This is useful
to debug invalid hash formats, and it make sure that previous hashes
which could have been loaded in the kernel, but silently ignored, are
now noticed and deal with by the user at kernel build time.
This also prevent stricter blacklist key description checking (provided
by following commits) to failed for builtin hashes.
Update CONFIG_SYSTEM_BLACKLIST_HASH_LIST help to explain the content of
a hash string and how to generate certificate ones.
Cc: David Howells <dhowells@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Eric Snowberg <eric.snowberg@oracle.com>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Mickaël Salaün <redacted>
Link: https://lore.kernel.org/r/20210712170313.884724-3-mic@digikod.net
---
Changes since v7:
* Rebase and fix trivial .gitignore conflict.
Changes since v5:
* Rebase on keys-next and fix conflict as previously done by David
Howells.
* Enable to use a file path relative to the kernel source directory.
This align with the handling of CONFIG_SYSTEM_TRUSTED_KEYS,
CONFIG_MODULE_SIG_KEY and CONFIG_SYSTEM_REVOCATION_KEYS.
Changes since v3:
* Improve commit description.
* Update CONFIG_SYSTEM_BLACKLIST_HASH_LIST help.
* Remove Acked-by Jarkko Sakkinen because of the above changes.
Changes since v2:
* Add Jarkko's Acked-by.
Changes since v1:
* Prefix script path with $(scrtree)/ (suggested by David Howells).
* Fix hexadecimal number check.
---
MAINTAINERS | 1 +
certs/.gitignore | 1 +
certs/Kconfig | 7 ++++--
certs/Makefile | 17 +++++++++++++-
scripts/check-blacklist-hashes.awk | 37 ++++++++++++++++++++++++++++++
5 files changed, 60 insertions(+), 3 deletions(-)
create mode 100755 scripts/check-blacklist-hashes.awk
From: Mickaël Salaün <redacted>
Add a new helper print-cert-tbs-hash.sh to generate a TBSCertificate
hash from a given certificate. This is useful to generate a blacklist
key description used to forbid loading a specific certificate in a
keyring, or to invalidate a certificate provided by a PKCS#7 file.
This kind of hash formatting is required to populate the file pointed
out by CONFIG_SYSTEM_BLACKLIST_HASH_LIST, but only the kernel code was
available to understand how to effectively create such hash.
Cc: David Howells <dhowells@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Eric Snowberg <eric.snowberg@oracle.com>
Signed-off-by: Mickaël Salaün <redacted>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Link: https://lore.kernel.org/r/20210712170313.884724-2-mic@digikod.net
---
Changes since v5:
* Add Reviewed-by Jarkko.
Changes since v3:
* Explain in the commit message that this kind of formating is not new
but it wasn't documented.
Changes since v1:
* Fix typo.
* Use "if" block instead of "||" .
---
MAINTAINERS | 1 +
tools/certs/print-cert-tbs-hash.sh | 91 ++++++++++++++++++++++++++++++
2 files changed, 92 insertions(+)
create mode 100755 tools/certs/print-cert-tbs-hash.sh
From: Mickaël Salaün <redacted>
Before exposing this new key type to user space, make sure that only
meaningful blacklisted hashes are accepted. This is also checked for
builtin blacklisted hashes, but a following commit make sure that the
user will notice (at built time) and will fix the configuration if it
already included errors.
Check that a blacklist key description starts with a valid prefix and
then a valid hexadecimal string.
Cc: David Howells <dhowells@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Eric Snowberg <eric.snowberg@oracle.com>
Signed-off-by: Mickaël Salaün <redacted>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Link: https://lore.kernel.org/r/20210712170313.884724-4-mic@digikod.net
---
Changes since v5:
* Add Reviewed-by Jarkko.
Changes since v2:
* Fix typo in blacklist_vet_description() comment, spotted by Tyler
Hicks.
* Add Jarkko's Acked-by.
Changes since v1:
* Return ENOPKG (instead of EINVAL) when a hash is greater than the
maximum currently known hash (suggested by David Howells).
---
certs/blacklist.c | 46 ++++++++++++++++++++++++++++++++++++----------
1 file changed, 36 insertions(+), 10 deletions(-)
@@ -32,24 +42,40 @@ extern __initconst const unsigned long revocation_certificate_list_size;*/staticintblacklist_vet_description(constchar*desc){-intn=0;--if(*desc==':')-return-EINVAL;-for(;*desc;desc++)-if(*desc==':')-gotofound_colon;+inti,prefix_len,tbs_step=0,bin_step=0;++/* The following algorithm only works if prefix lengths match. */+BUILD_BUG_ON(sizeof(tbs_prefix)!=sizeof(bin_prefix));+prefix_len=sizeof(tbs_prefix)-1;+for(i=0;*desc;desc++,i++){+if(*desc==':'){+if(tbs_step==prefix_len)+gotofound_colon;+if(bin_step==prefix_len)+gotofound_colon;+return-EINVAL;+}+if(i>=prefix_len)+return-EINVAL;+if(*desc==tbs_prefix[i])+tbs_step++;+if(*desc==bin_prefix[i])+bin_step++;+}return-EINVAL;found_colon:desc++;-for(;*desc;desc++){+for(i=0;*desc&&i<MAX_HASH_LEN;desc++,i++){if(!isxdigit(*desc)||isupper(*desc))return-EINVAL;-n++;}+if(*desc)+/* The hash is greater than MAX_HASH_LEN. */+return-ENOPKG;-if(n==0||n&1)+/* Checks for an even number of hexadecimal characters. */+if(i==0||i&1)return-EINVAL;return0;}
From: Mickaël Salaün <redacted>
Add a kernel option SYSTEM_BLACKLIST_AUTH_UPDATE to enable the root user
to dynamically add new keys to the blacklist keyring. This enables to
invalidate new certificates, either from being loaded in a keyring, or
from being trusted in a PKCS#7 certificate chain. This also enables to
add new file hashes to be denied by the integrity infrastructure.
Being able to untrust a certificate which could have normaly been
trusted is a sensitive operation. This is why adding new hashes to the
blacklist keyring is only allowed when these hashes are signed and
vouched by the builtin trusted keyring. A blacklist hash is stored as a
key description. The PKCS#7 signature of this description must be
provided as the key payload.
Marking a certificate as untrusted should be enforced while the system
is running. It is then forbiden to remove such blacklist keys.
Update blacklist keyring, blacklist key and revoked certificate access rights:
* allows the root user to search for a specific blacklisted hash, which
make sense because the descriptions are already viewable;
* forbids key update (blacklist and asymmetric ones);
* restricts kernel rights on the blacklist keyring to align with the
root user rights.
See help in tools/certs/print-cert-tbs-hash.sh .
Cc: David Howells <dhowells@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Eric Snowberg <eric.snowberg@oracle.com>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Mickaël Salaün <redacted>
Link: https://lore.kernel.org/r/20210712170313.884724-6-mic@digikod.net
---
Changes since v6:
* Rebase on keys-cve-2020-26541-v3: commit ebd9c2ae369a ("integrity:
Load mokx variables into the blacklist keyring").
Changes since v5:
* Rebase on keys-next, fix Kconfig conflict, and update the asymmetric
key rights added to the blacklist keyring by the new
add_key_to_revocation_list(): align with blacklist key rights by
removing KEY_POS_WRITE as a safeguard, and add
KEY_ALLOC_BYPASS_RESTRICTION to not be subject to
restrict_link_for_blacklist() that only allows blacklist key types to
be added to the keyring.
* Change the return code for restrict_link_for_blacklist() from -EPERM
to -EOPNOTSUPP to align with asymmetric key keyrings.
Changes since v3:
* Update commit message for print-cert-tbs-hash.sh .
Changes since v2:
* Add comment for blacklist_key_instantiate().
---
certs/Kconfig | 10 +++++
certs/blacklist.c | 96 ++++++++++++++++++++++++++++++++++++-----------
2 files changed, 85 insertions(+), 21 deletions(-)
From: Mickaël Salaün <redacted>
Factor out the blacklist hash creation with the get_raw_hash() helper.
This also centralize the "tbs" and "bin" prefixes and make them private,
which help to manage them consistently.
Cc: David Howells <dhowells@redhat.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Eric Snowberg <eric.snowberg@oracle.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Mickaël Salaün <redacted>
Link: https://lore.kernel.org/r/20210712170313.884724-5-mic@digikod.net
---
Changes since v6:
* Rebase on keys-cve-2020-26541-v3: commit ebd9c2ae369a ("integrity:
Load mokx variables into the blacklist keyring").
Changes since v5:
* Rebase on keys-next and fix conflict as previously done by David
Howells.
* Fix missing part to effectively handle UEFI DBX blacklisting.
* Remove Jarkko's Acked-by because of the above changes.
Changes since v2:
* Add Jarkko's Acked-by.
---
certs/blacklist.c | 76 ++++++++++++++-----
crypto/asymmetric_keys/x509_public_key.c | 3 +-
include/keys/system_keyring.h | 14 +++-
.../platform_certs/keyring_handler.c | 26 +------
4 files changed, 73 insertions(+), 46 deletions(-)
Hi Jarkko,
Since everyone seems OK with this and had plenty of time to complain, could you please take this patch series in your tree? It still applies on v5.16-rc5 and it is really important to us. Please let me know if you need something more.
Regards,
Mickaël
On 12/07/2021 19:03, Mickaël Salaün wrote:
Hi,
This new patch series is a rebase on v5.14-rc1 . David or Jarkko, if
it's still OK with you, could you please push this to linux-next?
I successfully tested this patch series with the 211 entries from
https://uefi.org/sites/default/files/resources/dbxupdate_x64.bin
The goal of these patches is to add a new configuration option to enable the
root user to load signed keys in the blacklist keyring. This keyring is useful
to "untrust" certificates or files. Enabling to safely update this keyring
without recompiling the kernel makes it more usable.
Previous patch series:
https://lore.kernel.org/lkml/20210312171232.2681989-1-mic@digikod.net/
Regards,
Mickaël Salaün (5):
tools/certs: Add print-cert-tbs-hash.sh
certs: Check that builtin blacklist hashes are valid
certs: Make blacklist_vet_description() more strict
certs: Factor out the blacklist hash creation
certs: Allow root user to append signed hashes to the blacklist
keyring
MAINTAINERS | 2 +
certs/.gitignore | 1 +
certs/Kconfig | 17 +-
certs/Makefile | 17 +-
certs/blacklist.c | 218 ++++++++++++++----
crypto/asymmetric_keys/x509_public_key.c | 3 +-
include/keys/system_keyring.h | 14 +-
scripts/check-blacklist-hashes.awk | 37 +++
.../platform_certs/keyring_handler.c | 26 +--
tools/certs/print-cert-tbs-hash.sh | 91 ++++++++
10 files changed, 346 insertions(+), 80 deletions(-)
create mode 100755 scripts/check-blacklist-hashes.awk
create mode 100755 tools/certs/print-cert-tbs-hash.sh
base-commit: e73f0f0ee7541171d89f2e2491130c7771ba58d3
From: Jarkko Sakkinen <jarkko@kernel.org> Date: 2021-12-21 08:50:51
On Mon, Dec 13, 2021 at 04:30:29PM +0100, Mickaël Salaün wrote:
Hi Jarkko,
Since everyone seems OK with this and had plenty of time to complain, could
you please take this patch series in your tree? It still applies on
v5.16-rc5 and it is really important to us. Please let me know if you need
something more.
Regards,
Mickaël
I'm off-work up until end of the year, i.e. I will address only important
bug fixes and v5.16 up until that.
If any of the patches is yet missing my ack, feel free to
Acked-by: Jarkko Sakkinen <jarkko@kernel.org>
/Jarkko
On Mon, Dec 13, 2021 at 04:30:29PM +0100, Mickaël Salaün wrote:
quoted
Hi Jarkko,
Since everyone seems OK with this and had plenty of time to complain, could
you please take this patch series in your tree? It still applies on
v5.16-rc5 and it is really important to us. Please let me know if you need
something more.
Regards,
Mickaël
I'm off-work up until end of the year, i.e. I will address only important
bug fixes and v5.16 up until that.
If any of the patches is yet missing my ack, feel free to
Acked-by: Jarkko Sakkinen <jarkko@kernel.org>
Thanks Jarkko. Can you please take it into your tree?
Regards,
Mickaël
From: Jarkko Sakkinen <jarkko@kernel.org> Date: 2022-01-06 19:12:29
On Tue, Jan 04, 2022 at 04:56:36PM +0100, Mickaël Salaün wrote:
On 21/12/2021 09:50, Jarkko Sakkinen wrote:
quoted
On Mon, Dec 13, 2021 at 04:30:29PM +0100, Mickaël Salaün wrote:
quoted
Hi Jarkko,
Since everyone seems OK with this and had plenty of time to complain, could
you please take this patch series in your tree? It still applies on
v5.16-rc5 and it is really important to us. Please let me know if you need
something more.
Regards,
Mickaël
I'm off-work up until end of the year, i.e. I will address only important
bug fixes and v5.16 up until that.
If any of the patches is yet missing my ack, feel free to
Acked-by: Jarkko Sakkinen <jarkko@kernel.org>
Thanks Jarkko. Can you please take it into your tree?
I can yes, as I need to anyway do a revised PR for v5.17, as one commit
in my first trial had a truncated fixes tag.
/Jarkko
From: Jarkko Sakkinen <jarkko@kernel.org> Date: 2022-01-06 19:16:36
On Thu, Jan 06, 2022 at 09:12:22PM +0200, Jarkko Sakkinen wrote:
On Tue, Jan 04, 2022 at 04:56:36PM +0100, Mickaël Salaün wrote:
quoted
On 21/12/2021 09:50, Jarkko Sakkinen wrote:
quoted
On Mon, Dec 13, 2021 at 04:30:29PM +0100, Mickaël Salaün wrote:
quoted
Hi Jarkko,
Since everyone seems OK with this and had plenty of time to complain, could
you please take this patch series in your tree? It still applies on
v5.16-rc5 and it is really important to us. Please let me know if you need
something more.
Regards,
Mickaël
I'm off-work up until end of the year, i.e. I will address only important
bug fixes and v5.16 up until that.
If any of the patches is yet missing my ack, feel free to
Acked-by: Jarkko Sakkinen <jarkko@kernel.org>
Thanks Jarkko. Can you please take it into your tree?
I can yes, as I need to anyway do a revised PR for v5.17, as one commit
in my first trial had a truncated fixes tag.
On Thu, Jan 06, 2022 at 09:12:22PM +0200, Jarkko Sakkinen wrote:
quoted
On Tue, Jan 04, 2022 at 04:56:36PM +0100, Mickaël Salaün wrote:
quoted
On 21/12/2021 09:50, Jarkko Sakkinen wrote:
quoted
On Mon, Dec 13, 2021 at 04:30:29PM +0100, Mickaël Salaün wrote:
quoted
Hi Jarkko,
Since everyone seems OK with this and had plenty of time to complain, could
you please take this patch series in your tree? It still applies on
v5.16-rc5 and it is really important to us. Please let me know if you need
something more.
Regards,
Mickaël
I'm off-work up until end of the year, i.e. I will address only important
bug fixes and v5.16 up until that.
If any of the patches is yet missing my ack, feel free to
Acked-by: Jarkko Sakkinen <jarkko@kernel.org>
Thanks Jarkko. Can you please take it into your tree?
I can yes, as I need to anyway do a revised PR for v5.17, as one commit
in my first trial had a truncated fixes tag.
On Thu, Jan 06, 2022 at 09:12:22PM +0200, Jarkko Sakkinen wrote:
quoted
On Tue, Jan 04, 2022 at 04:56:36PM +0100, Mickaël Salaün wrote:
quoted
On 21/12/2021 09:50, Jarkko Sakkinen wrote:
quoted
On Mon, Dec 13, 2021 at 04:30:29PM +0100, Mickaël Salaün wrote:
quoted
Hi Jarkko,
Since everyone seems OK with this and had plenty of time to complain, could
you please take this patch series in your tree? It still applies on
v5.16-rc5 and it is really important to us. Please let me know if you need
something more.
Regards,
Mickaël
I'm off-work up until end of the year, i.e. I will address only important
bug fixes and v5.16 up until that.
If any of the patches is yet missing my ack, feel free to
Acked-by: Jarkko Sakkinen <jarkko@kernel.org>
Thanks Jarkko. Can you please take it into your tree?
I can yes, as I need to anyway do a revised PR for v5.17, as one commit
in my first trial had a truncated fixes tag.
From: Jarkko Sakkinen <jarkko@kernel.org> Date: 2022-02-17 19:58:26
On Mon, Jan 31, 2022 at 12:33:51PM +0100, Mickaël Salaün wrote:
On 07/01/2022 13:14, Mickaël Salaün wrote:
quoted
On 06/01/2022 20:16, Jarkko Sakkinen wrote:
quoted
On Thu, Jan 06, 2022 at 09:12:22PM +0200, Jarkko Sakkinen wrote:
quoted
On Tue, Jan 04, 2022 at 04:56:36PM +0100, Mickaël Salaün wrote:
quoted
On 21/12/2021 09:50, Jarkko Sakkinen wrote:
quoted
On Mon, Dec 13, 2021 at 04:30:29PM +0100, Mickaël Salaün wrote:
quoted
Hi Jarkko,
Since everyone seems OK with this and had plenty of
time to complain, could
you please take this patch series in your tree? It still applies on
v5.16-rc5 and it is really important to us. Please
let me know if you need
something more.
Regards,
Mickaël
I'm off-work up until end of the year, i.e. I will
address only important
bug fixes and v5.16 up until that.
If any of the patches is yet missing my ack, feel free to
Acked-by: Jarkko Sakkinen <jarkko@kernel.org>
Thanks Jarkko. Can you please take it into your tree?
I can yes, as I need to anyway do a revised PR for v5.17, as one commit
in my first trial had a truncated fixes tag.
From: Jarkko Sakkinen <jarkko@kernel.org> Date: 2022-02-19 11:42:07
On Thu, Feb 17, 2022 at 08:58:57PM +0100, Jarkko Sakkinen wrote:
On Mon, Jan 31, 2022 at 12:33:51PM +0100, Mickaël Salaün wrote:
quoted
On 07/01/2022 13:14, Mickaël Salaün wrote:
quoted
On 06/01/2022 20:16, Jarkko Sakkinen wrote:
quoted
On Thu, Jan 06, 2022 at 09:12:22PM +0200, Jarkko Sakkinen wrote:
quoted
On Tue, Jan 04, 2022 at 04:56:36PM +0100, Mickaël Salaün wrote:
quoted
On 21/12/2021 09:50, Jarkko Sakkinen wrote:
quoted
On Mon, Dec 13, 2021 at 04:30:29PM +0100, Mickaël Salaün wrote:
quoted
Hi Jarkko,
Since everyone seems OK with this and had plenty of
time to complain, could
you please take this patch series in your tree? It still applies on
v5.16-rc5 and it is really important to us. Please
let me know if you need
something more.
Regards,
Mickaël
I'm off-work up until end of the year, i.e. I will
address only important
bug fixes and v5.16 up until that.
If any of the patches is yet missing my ack, feel free to
Acked-by: Jarkko Sakkinen <jarkko@kernel.org>
Thanks Jarkko. Can you please take it into your tree?
I can yes, as I need to anyway do a revised PR for v5.17, as one commit
in my first trial had a truncated fixes tag.
This must be some sort of mistake I've made. I'll re-apply the patches.
Sorry about this.
OK now the patches are in and will be included to the next PR. I fixed
merge conflicts caused by 5cca36069d4c ("certs: refactor file cleaning")
in "certs: Check that builtin blacklist hashes are valid" so please
sanity check that it is good.
BR, Jarkko
From: Jarkko Sakkinen <jarkko@kernel.org> Date: 2022-03-08 11:54:37
On Mon, Jul 12, 2021 at 07:03:13PM +0200, Mickaël Salaün wrote:
quoted hunk
From: Mickaël Salaün <redacted>
Add a kernel option SYSTEM_BLACKLIST_AUTH_UPDATE to enable the root user
to dynamically add new keys to the blacklist keyring. This enables to
invalidate new certificates, either from being loaded in a keyring, or
from being trusted in a PKCS#7 certificate chain. This also enables to
add new file hashes to be denied by the integrity infrastructure.
Being able to untrust a certificate which could have normaly been
trusted is a sensitive operation. This is why adding new hashes to the
blacklist keyring is only allowed when these hashes are signed and
vouched by the builtin trusted keyring. A blacklist hash is stored as a
key description. The PKCS#7 signature of this description must be
provided as the key payload.
Marking a certificate as untrusted should be enforced while the system
is running. It is then forbiden to remove such blacklist keys.
Update blacklist keyring, blacklist key and revoked certificate access rights:
* allows the root user to search for a specific blacklisted hash, which
make sense because the descriptions are already viewable;
* forbids key update (blacklist and asymmetric ones);
* restricts kernel rights on the blacklist keyring to align with the
root user rights.
See help in tools/certs/print-cert-tbs-hash.sh .
Cc: David Howells <dhowells@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Eric Snowberg <eric.snowberg@oracle.com>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Mickaël Salaün <redacted>
Link: https://lore.kernel.org/r/20210712170313.884724-6-mic@digikod.net
---
Changes since v6:
* Rebase on keys-cve-2020-26541-v3: commit ebd9c2ae369a ("integrity:
Load mokx variables into the blacklist keyring").
Changes since v5:
* Rebase on keys-next, fix Kconfig conflict, and update the asymmetric
key rights added to the blacklist keyring by the new
add_key_to_revocation_list(): align with blacklist key rights by
removing KEY_POS_WRITE as a safeguard, and add
KEY_ALLOC_BYPASS_RESTRICTION to not be subject to
restrict_link_for_blacklist() that only allows blacklist key types to
be added to the keyring.
* Change the return code for restrict_link_for_blacklist() from -EPERM
to -EOPNOTSUPP to align with asymmetric key keyrings.
Changes since v3:
* Update commit message for print-cert-tbs-hash.sh .
Changes since v2:
* Add comment for blacklist_key_instantiate().
---
certs/Kconfig | 10 +++++
certs/blacklist.c | 96 ++++++++++++++++++++++++++++++++++++-----------
2 files changed, 85 insertions(+), 21 deletions(-)
@@ -154,8 +189,7 @@ static int mark_raw_hash_blacklisted(const char *hash)hash,NULL,0,-((KEY_POS_ALL&~KEY_POS_SETATTR)|-KEY_USR_VIEW),+BLACKLIST_KEY_PERM,KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN);if(IS_ERR(key)){
@@ -232,8 +266,10 @@ int add_key_to_revocation_list(const char *data, size_t size)NULL,data,size,-((KEY_POS_ALL&~KEY_POS_SETATTR)|KEY_USR_VIEW),-KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN);+KEY_POS_VIEW|KEY_POS_READ|KEY_POS_SEARCH+|KEY_USR_VIEW,+KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN+|KEY_ALLOC_BYPASS_RESTRICTION);if(IS_ERR(key)){pr_err("Problem with revocation key (%ld)\n",PTR_ERR(key));
@@ -260,25 +296,43 @@ int is_key_on_revocation_list(struct pkcs7_message *pkcs7)}#endif+staticintrestrict_link_for_blacklist(structkey*dest_keyring,+conststructkey_type*type,constunionkey_payload*payload,+structkey*restrict_key)+{+if(type==&key_type_blacklist)+return0;+return-EOPNOTSUPP;+}+/**Initialisetheblacklist*/staticint__initblacklist_init(void){constchar*const*bl;+structkey_restriction*restriction;if(register_key_type(&key_type_blacklist)<0)panic("Can't allocate system blacklist key type\n");+restriction=kzalloc(sizeof(*restriction),GFP_KERNEL);+if(!restriction)+panic("Can't allocate blacklist keyring restriction\n");
This prevents me from taking this to my pull request. In moderns standards,
no new BUG_ON(), panic() etc. should never added to the kernel.
I missed this in my review.
This should rather be e.g.
restriction = kzalloc(sizeof(*restriction), GFP_KERNEL);
if (!restriction) {
pr_err("Can't allocate blacklist keyring restriction\n");
return 0;
}
Unfortunately I need to drop this patch set, because adding new panic()
is simply a no-go.
BR, Jarkko
On Mon, Jul 12, 2021 at 07:03:13PM +0200, Mickaël Salaün wrote:
quoted
From: Mickaël Salaün <redacted>
Add a kernel option SYSTEM_BLACKLIST_AUTH_UPDATE to enable the root user
to dynamically add new keys to the blacklist keyring. This enables to
invalidate new certificates, either from being loaded in a keyring, or
from being trusted in a PKCS#7 certificate chain. This also enables to
add new file hashes to be denied by the integrity infrastructure.
Being able to untrust a certificate which could have normaly been
trusted is a sensitive operation. This is why adding new hashes to the
blacklist keyring is only allowed when these hashes are signed and
vouched by the builtin trusted keyring. A blacklist hash is stored as a
key description. The PKCS#7 signature of this description must be
provided as the key payload.
Marking a certificate as untrusted should be enforced while the system
is running. It is then forbiden to remove such blacklist keys.
Update blacklist keyring, blacklist key and revoked certificate access rights:
* allows the root user to search for a specific blacklisted hash, which
make sense because the descriptions are already viewable;
* forbids key update (blacklist and asymmetric ones);
* restricts kernel rights on the blacklist keyring to align with the
root user rights.
See help in tools/certs/print-cert-tbs-hash.sh .
Cc: David Howells <dhowells@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Eric Snowberg <eric.snowberg@oracle.com>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Mickaël Salaün <redacted>
Link: https://lore.kernel.org/r/20210712170313.884724-6-mic@digikod.net
---
Changes since v6:
* Rebase on keys-cve-2020-26541-v3: commit ebd9c2ae369a ("integrity:
Load mokx variables into the blacklist keyring").
Changes since v5:
* Rebase on keys-next, fix Kconfig conflict, and update the asymmetric
key rights added to the blacklist keyring by the new
add_key_to_revocation_list(): align with blacklist key rights by
removing KEY_POS_WRITE as a safeguard, and add
KEY_ALLOC_BYPASS_RESTRICTION to not be subject to
restrict_link_for_blacklist() that only allows blacklist key types to
be added to the keyring.
* Change the return code for restrict_link_for_blacklist() from -EPERM
to -EOPNOTSUPP to align with asymmetric key keyrings.
Changes since v3:
* Update commit message for print-cert-tbs-hash.sh .
Changes since v2:
* Add comment for blacklist_key_instantiate().
---
certs/Kconfig | 10 +++++
certs/blacklist.c | 96 ++++++++++++++++++++++++++++++++++++-----------
2 files changed, 85 insertions(+), 21 deletions(-)
@@ -154,8 +189,7 @@ static int mark_raw_hash_blacklisted(const char *hash)hash,NULL,0,-((KEY_POS_ALL&~KEY_POS_SETATTR)|-KEY_USR_VIEW),+BLACKLIST_KEY_PERM,KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN);if(IS_ERR(key)){
@@ -232,8 +266,10 @@ int add_key_to_revocation_list(const char *data, size_t size)NULL,data,size,-((KEY_POS_ALL&~KEY_POS_SETATTR)|KEY_USR_VIEW),-KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN);+KEY_POS_VIEW|KEY_POS_READ|KEY_POS_SEARCH+|KEY_USR_VIEW,+KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN+|KEY_ALLOC_BYPASS_RESTRICTION);if(IS_ERR(key)){pr_err("Problem with revocation key (%ld)\n",PTR_ERR(key));
@@ -260,25 +296,43 @@ int is_key_on_revocation_list(struct pkcs7_message *pkcs7)}#endif+staticintrestrict_link_for_blacklist(structkey*dest_keyring,+conststructkey_type*type,constunionkey_payload*payload,+structkey*restrict_key)+{+if(type==&key_type_blacklist)+return0;+return-EOPNOTSUPP;+}+/**Initialisetheblacklist*/staticint__initblacklist_init(void){constchar*const*bl;+structkey_restriction*restriction;if(register_key_type(&key_type_blacklist)<0)panic("Can't allocate system blacklist key type\n");+restriction=kzalloc(sizeof(*restriction),GFP_KERNEL);+if(!restriction)+panic("Can't allocate blacklist keyring restriction\n");
This prevents me from taking this to my pull request. In moderns standards,
no new BUG_ON(), panic() etc. should never added to the kernel.
I missed this in my review.
This should rather be e.g.
restriction = kzalloc(sizeof(*restriction), GFP_KERNEL);
if (!restriction) {
pr_err("Can't allocate blacklist keyring restriction\n");
return 0;
}
Unfortunately I need to drop this patch set, because adding new panic()
is simply a no-go.
I agree that panic() is not great in general, but I followed the other part of the code (just above) that do the same. This part of the kernel should failed if critical memory allocation failed at boot time (only). It doesn't impact the kernel once it is running. I don't think that just ignoring this error with return 0 is fine, after all it's a critical error right?
Calling panic() seems OK here. Is there a better way to stop the kernel for such critical error? If the kernel cannot allocate memory at this time, it would be useless to try continuing booting.
From: Jarkko Sakkinen <jarkko@kernel.org> Date: 2022-03-08 13:20:14
On Tue, Mar 08, 2022 at 01:18:28PM +0100, Mickaël Salaün wrote:
On 08/03/2022 12:53, Jarkko Sakkinen wrote:
quoted
On Mon, Jul 12, 2021 at 07:03:13PM +0200, Mickaël Salaün wrote:
quoted
From: Mickaël Salaün <redacted>
Add a kernel option SYSTEM_BLACKLIST_AUTH_UPDATE to enable the root user
to dynamically add new keys to the blacklist keyring. This enables to
invalidate new certificates, either from being loaded in a keyring, or
from being trusted in a PKCS#7 certificate chain. This also enables to
add new file hashes to be denied by the integrity infrastructure.
Being able to untrust a certificate which could have normaly been
trusted is a sensitive operation. This is why adding new hashes to the
blacklist keyring is only allowed when these hashes are signed and
vouched by the builtin trusted keyring. A blacklist hash is stored as a
key description. The PKCS#7 signature of this description must be
provided as the key payload.
Marking a certificate as untrusted should be enforced while the system
is running. It is then forbiden to remove such blacklist keys.
Update blacklist keyring, blacklist key and revoked certificate access rights:
* allows the root user to search for a specific blacklisted hash, which
make sense because the descriptions are already viewable;
* forbids key update (blacklist and asymmetric ones);
* restricts kernel rights on the blacklist keyring to align with the
root user rights.
See help in tools/certs/print-cert-tbs-hash.sh .
Cc: David Howells <dhowells@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Eric Snowberg <eric.snowberg@oracle.com>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Mickaël Salaün <redacted>
Link: https://lore.kernel.org/r/20210712170313.884724-6-mic@digikod.net
---
Changes since v6:
* Rebase on keys-cve-2020-26541-v3: commit ebd9c2ae369a ("integrity:
Load mokx variables into the blacklist keyring").
Changes since v5:
* Rebase on keys-next, fix Kconfig conflict, and update the asymmetric
key rights added to the blacklist keyring by the new
add_key_to_revocation_list(): align with blacklist key rights by
removing KEY_POS_WRITE as a safeguard, and add
KEY_ALLOC_BYPASS_RESTRICTION to not be subject to
restrict_link_for_blacklist() that only allows blacklist key types to
be added to the keyring.
* Change the return code for restrict_link_for_blacklist() from -EPERM
to -EOPNOTSUPP to align with asymmetric key keyrings.
Changes since v3:
* Update commit message for print-cert-tbs-hash.sh .
Changes since v2:
* Add comment for blacklist_key_instantiate().
---
certs/Kconfig | 10 +++++
certs/blacklist.c | 96 ++++++++++++++++++++++++++++++++++++-----------
2 files changed, 85 insertions(+), 21 deletions(-)
@@ -154,8 +189,7 @@ static int mark_raw_hash_blacklisted(const char *hash)hash,NULL,0,-((KEY_POS_ALL&~KEY_POS_SETATTR)|-KEY_USR_VIEW),+BLACKLIST_KEY_PERM,KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN);if(IS_ERR(key)){
@@ -232,8 +266,10 @@ int add_key_to_revocation_list(const char *data, size_t size)NULL,data,size,-((KEY_POS_ALL&~KEY_POS_SETATTR)|KEY_USR_VIEW),-KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN);+KEY_POS_VIEW|KEY_POS_READ|KEY_POS_SEARCH+|KEY_USR_VIEW,+KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN+|KEY_ALLOC_BYPASS_RESTRICTION);if(IS_ERR(key)){pr_err("Problem with revocation key (%ld)\n",PTR_ERR(key));
@@ -260,25 +296,43 @@ int is_key_on_revocation_list(struct pkcs7_message *pkcs7)}#endif+staticintrestrict_link_for_blacklist(structkey*dest_keyring,+conststructkey_type*type,constunionkey_payload*payload,+structkey*restrict_key)+{+if(type==&key_type_blacklist)+return0;+return-EOPNOTSUPP;+}+/**Initialisetheblacklist*/staticint__initblacklist_init(void){constchar*const*bl;+structkey_restriction*restriction;if(register_key_type(&key_type_blacklist)<0)panic("Can't allocate system blacklist key type\n");+restriction=kzalloc(sizeof(*restriction),GFP_KERNEL);+if(!restriction)+panic("Can't allocate blacklist keyring restriction\n");
This prevents me from taking this to my pull request. In moderns standards,
no new BUG_ON(), panic() etc. should never added to the kernel.
I missed this in my review.
This should rather be e.g.
restriction = kzalloc(sizeof(*restriction), GFP_KERNEL);
if (!restriction) {
pr_err("Can't allocate blacklist keyring restriction\n");
return 0;
}
Unfortunately I need to drop this patch set, because adding new panic()
is simply a no-go.
I agree that panic() is not great in general, but I followed the other part
of the code (just above) that do the same. This part of the kernel should
failed if critical memory allocation failed at boot time (only). It doesn't
impact the kernel once it is running. I don't think that just ignoring this
error with return 0 is fine, after all it's a critical error right?
It's not good reason enough to crash the whole kernel, even if it is a
critical error (e.g. run-time foresincs). Even WARN() is not recommended
these days [*].
For the existing panic()-statements: I'm happy to review patches that
render them out.
Not sure tho, if this fails should it be then "everything blacklisted".
Just one thing to consider.
Calling panic() seems OK here. Is there a better way to stop the kernel for
such critical error? If the kernel cannot allocate memory at this time, it
would be useless to try continuing booting.
On Tue, Mar 08, 2022 at 01:18:28PM +0100, Mickaël Salaün wrote:
quoted
On 08/03/2022 12:53, Jarkko Sakkinen wrote:
quoted
On Mon, Jul 12, 2021 at 07:03:13PM +0200, Mickaël Salaün wrote:
quoted
From: Mickaël Salaün <redacted>
Add a kernel option SYSTEM_BLACKLIST_AUTH_UPDATE to enable the root user
to dynamically add new keys to the blacklist keyring. This enables to
invalidate new certificates, either from being loaded in a keyring, or
from being trusted in a PKCS#7 certificate chain. This also enables to
add new file hashes to be denied by the integrity infrastructure.
Being able to untrust a certificate which could have normaly been
trusted is a sensitive operation. This is why adding new hashes to the
blacklist keyring is only allowed when these hashes are signed and
vouched by the builtin trusted keyring. A blacklist hash is stored as a
key description. The PKCS#7 signature of this description must be
provided as the key payload.
Marking a certificate as untrusted should be enforced while the system
is running. It is then forbiden to remove such blacklist keys.
Update blacklist keyring, blacklist key and revoked certificate access rights:
* allows the root user to search for a specific blacklisted hash, which
make sense because the descriptions are already viewable;
* forbids key update (blacklist and asymmetric ones);
* restricts kernel rights on the blacklist keyring to align with the
root user rights.
See help in tools/certs/print-cert-tbs-hash.sh .
Cc: David Howells <dhowells@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Eric Snowberg <eric.snowberg@oracle.com>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Mickaël Salaün <redacted>
Link: https://lore.kernel.org/r/20210712170313.884724-6-mic@digikod.net
---
Changes since v6:
* Rebase on keys-cve-2020-26541-v3: commit ebd9c2ae369a ("integrity:
Load mokx variables into the blacklist keyring").
Changes since v5:
* Rebase on keys-next, fix Kconfig conflict, and update the asymmetric
key rights added to the blacklist keyring by the new
add_key_to_revocation_list(): align with blacklist key rights by
removing KEY_POS_WRITE as a safeguard, and add
KEY_ALLOC_BYPASS_RESTRICTION to not be subject to
restrict_link_for_blacklist() that only allows blacklist key types to
be added to the keyring.
* Change the return code for restrict_link_for_blacklist() from -EPERM
to -EOPNOTSUPP to align with asymmetric key keyrings.
Changes since v3:
* Update commit message for print-cert-tbs-hash.sh .
Changes since v2:
* Add comment for blacklist_key_instantiate().
---
certs/Kconfig | 10 +++++
certs/blacklist.c | 96 ++++++++++++++++++++++++++++++++++++-----------
2 files changed, 85 insertions(+), 21 deletions(-)
@@ -154,8 +189,7 @@ static int mark_raw_hash_blacklisted(const char *hash)hash,NULL,0,-((KEY_POS_ALL&~KEY_POS_SETATTR)|-KEY_USR_VIEW),+BLACKLIST_KEY_PERM,KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN);if(IS_ERR(key)){
@@ -232,8 +266,10 @@ int add_key_to_revocation_list(const char *data, size_t size)NULL,data,size,-((KEY_POS_ALL&~KEY_POS_SETATTR)|KEY_USR_VIEW),-KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN);+KEY_POS_VIEW|KEY_POS_READ|KEY_POS_SEARCH+|KEY_USR_VIEW,+KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN+|KEY_ALLOC_BYPASS_RESTRICTION);if(IS_ERR(key)){pr_err("Problem with revocation key (%ld)\n",PTR_ERR(key));
@@ -260,25 +296,43 @@ int is_key_on_revocation_list(struct pkcs7_message *pkcs7)}#endif+staticintrestrict_link_for_blacklist(structkey*dest_keyring,+conststructkey_type*type,constunionkey_payload*payload,+structkey*restrict_key)+{+if(type==&key_type_blacklist)+return0;+return-EOPNOTSUPP;+}+/**Initialisetheblacklist*/staticint__initblacklist_init(void){constchar*const*bl;+structkey_restriction*restriction;if(register_key_type(&key_type_blacklist)<0)panic("Can't allocate system blacklist key type\n");+restriction=kzalloc(sizeof(*restriction),GFP_KERNEL);+if(!restriction)+panic("Can't allocate blacklist keyring restriction\n");
This prevents me from taking this to my pull request. In moderns standards,
no new BUG_ON(), panic() etc. should never added to the kernel.
I missed this in my review.
This should rather be e.g.
restriction = kzalloc(sizeof(*restriction), GFP_KERNEL);
if (!restriction) {
pr_err("Can't allocate blacklist keyring restriction\n");
return 0;
}
Unfortunately I need to drop this patch set, because adding new panic()
is simply a no-go.
I agree that panic() is not great in general, but I followed the other part
of the code (just above) that do the same. This part of the kernel should
failed if critical memory allocation failed at boot time (only). It doesn't
impact the kernel once it is running. I don't think that just ignoring this
error with return 0 is fine, after all it's a critical error right?
It's not good reason enough to crash the whole kernel, even if it is a
critical error (e.g. run-time foresincs). Even WARN() is not recommended
these days [*].
I think that what Greg said in this email is that WARN*() should only be used for cases that should never happen, it is definitely not deprecated, but WARN_ON_ONCE() may be a better idea though. WARN*() helps detect such thought-to-be-impossible cases, that can happen e.g. with code refactoring.
A lot of initialization/boot code (e.g. without user space nor external interactions, mostly __init functions) do panic if there is unexpected and unrecoverable errors like failed memory allocations. I think handling such errors otherwise would be more complex for no benefit. Moreover, delegating such error handling to user space could create new (silent) issues.
For the existing panic()-statements: I'm happy to review patches that
render them out. >
Not sure tho, if this fails should it be then "everything blacklisted".
Just one thing to consider.
Well, if it fail it will be "nothing will work afterwards". Do you have a working and useful scenario for this kind of error?
quoted
Calling panic() seems OK here. Is there a better way to stop the kernel for
such critical error? If the kernel cannot allocate memory at this time, it
would be useless to try continuing booting.
From: Jarkko Sakkinen <jarkko@kernel.org> Date: 2022-03-09 16:04:54
On Tue, Mar 08, 2022 at 05:02:23PM +0100, Mickaël Salaün wrote:
On 08/03/2022 14:19, Jarkko Sakkinen wrote:
quoted
On Tue, Mar 08, 2022 at 01:18:28PM +0100, Mickaël Salaün wrote:
quoted
On 08/03/2022 12:53, Jarkko Sakkinen wrote:
quoted
On Mon, Jul 12, 2021 at 07:03:13PM +0200, Mickaël Salaün wrote:
quoted
From: Mickaël Salaün <redacted>
Add a kernel option SYSTEM_BLACKLIST_AUTH_UPDATE to enable the root user
to dynamically add new keys to the blacklist keyring. This enables to
invalidate new certificates, either from being loaded in a keyring, or
from being trusted in a PKCS#7 certificate chain. This also enables to
add new file hashes to be denied by the integrity infrastructure.
Being able to untrust a certificate which could have normaly been
trusted is a sensitive operation. This is why adding new hashes to the
blacklist keyring is only allowed when these hashes are signed and
vouched by the builtin trusted keyring. A blacklist hash is stored as a
key description. The PKCS#7 signature of this description must be
provided as the key payload.
Marking a certificate as untrusted should be enforced while the system
is running. It is then forbiden to remove such blacklist keys.
Update blacklist keyring, blacklist key and revoked certificate access rights:
* allows the root user to search for a specific blacklisted hash, which
make sense because the descriptions are already viewable;
* forbids key update (blacklist and asymmetric ones);
* restricts kernel rights on the blacklist keyring to align with the
root user rights.
See help in tools/certs/print-cert-tbs-hash.sh .
Cc: David Howells <dhowells@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Eric Snowberg <eric.snowberg@oracle.com>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Mickaël Salaün <redacted>
Link: https://lore.kernel.org/r/20210712170313.884724-6-mic@digikod.net
---
Changes since v6:
* Rebase on keys-cve-2020-26541-v3: commit ebd9c2ae369a ("integrity:
Load mokx variables into the blacklist keyring").
Changes since v5:
* Rebase on keys-next, fix Kconfig conflict, and update the asymmetric
key rights added to the blacklist keyring by the new
add_key_to_revocation_list(): align with blacklist key rights by
removing KEY_POS_WRITE as a safeguard, and add
KEY_ALLOC_BYPASS_RESTRICTION to not be subject to
restrict_link_for_blacklist() that only allows blacklist key types to
be added to the keyring.
* Change the return code for restrict_link_for_blacklist() from -EPERM
to -EOPNOTSUPP to align with asymmetric key keyrings.
Changes since v3:
* Update commit message for print-cert-tbs-hash.sh .
Changes since v2:
* Add comment for blacklist_key_instantiate().
---
certs/Kconfig | 10 +++++
certs/blacklist.c | 96 ++++++++++++++++++++++++++++++++++++-----------
2 files changed, 85 insertions(+), 21 deletions(-)
@@ -154,8 +189,7 @@ static int mark_raw_hash_blacklisted(const char *hash)hash,NULL,0,-((KEY_POS_ALL&~KEY_POS_SETATTR)|-KEY_USR_VIEW),+BLACKLIST_KEY_PERM,KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN);if(IS_ERR(key)){
@@ -232,8 +266,10 @@ int add_key_to_revocation_list(const char *data, size_t size)NULL,data,size,-((KEY_POS_ALL&~KEY_POS_SETATTR)|KEY_USR_VIEW),-KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN);+KEY_POS_VIEW|KEY_POS_READ|KEY_POS_SEARCH+|KEY_USR_VIEW,+KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN+|KEY_ALLOC_BYPASS_RESTRICTION);if(IS_ERR(key)){pr_err("Problem with revocation key (%ld)\n",PTR_ERR(key));
@@ -260,25 +296,43 @@ int is_key_on_revocation_list(struct pkcs7_message *pkcs7)}#endif+staticintrestrict_link_for_blacklist(structkey*dest_keyring,+conststructkey_type*type,constunionkey_payload*payload,+structkey*restrict_key)+{+if(type==&key_type_blacklist)+return0;+return-EOPNOTSUPP;+}+/**Initialisetheblacklist*/staticint__initblacklist_init(void){constchar*const*bl;+structkey_restriction*restriction;if(register_key_type(&key_type_blacklist)<0)panic("Can't allocate system blacklist key type\n");+restriction=kzalloc(sizeof(*restriction),GFP_KERNEL);+if(!restriction)+panic("Can't allocate blacklist keyring restriction\n");
This prevents me from taking this to my pull request. In moderns standards,
no new BUG_ON(), panic() etc. should never added to the kernel.
I missed this in my review.
This should rather be e.g.
restriction = kzalloc(sizeof(*restriction), GFP_KERNEL);
if (!restriction) {
pr_err("Can't allocate blacklist keyring restriction\n");
return 0;
}
Unfortunately I need to drop this patch set, because adding new panic()
is simply a no-go.
I agree that panic() is not great in general, but I followed the other part
of the code (just above) that do the same. This part of the kernel should
failed if critical memory allocation failed at boot time (only). It doesn't
impact the kernel once it is running. I don't think that just ignoring this
error with return 0 is fine, after all it's a critical error right?
It's not good reason enough to crash the whole kernel, even if it is a
critical error (e.g. run-time foresincs). Even WARN() is not recommended
these days [*].
I think that what Greg said in this email is that WARN*() should only be
used for cases that should never happen, it is definitely not deprecated,
but WARN_ON_ONCE() may be a better idea though. WARN*() helps detect such
thought-to-be-impossible cases, that can happen e.g. with code refactoring.
A lot of initialization/boot code (e.g. without user space nor external
interactions, mostly __init functions) do panic if there is unexpected and
unrecoverable errors like failed memory allocations. I think handling such
errors otherwise would be more complex for no benefit. Moreover, delegating
such error handling to user space could create new (silent) issues.
To crash the whole kernel, you should be able to clearly explain why it
makes sense in the situation.
quoted
For the existing panic()-statements: I'm happy to review patches that
render them out. >
Not sure tho, if this fails should it be then "everything blacklisted".
Just one thing to consider.
Well, if it fail it will be "nothing will work afterwards". Do you have a
working and useful scenario for this kind of error?
So you have zero chances to get a shell without blacklist just to do
kernel forensics?
BR, Jarkko
On Tue, Mar 08, 2022 at 05:02:23PM +0100, Mickaël Salaün wrote:
quoted
On 08/03/2022 14:19, Jarkko Sakkinen wrote:
quoted
On Tue, Mar 08, 2022 at 01:18:28PM +0100, Mickaël Salaün wrote:
quoted
On 08/03/2022 12:53, Jarkko Sakkinen wrote:
quoted
On Mon, Jul 12, 2021 at 07:03:13PM +0200, Mickaël Salaün wrote:
quoted
From: Mickaël Salaün <redacted>
Add a kernel option SYSTEM_BLACKLIST_AUTH_UPDATE to enable the root user
to dynamically add new keys to the blacklist keyring. This enables to
invalidate new certificates, either from being loaded in a keyring, or
from being trusted in a PKCS#7 certificate chain. This also enables to
add new file hashes to be denied by the integrity infrastructure.
Being able to untrust a certificate which could have normaly been
trusted is a sensitive operation. This is why adding new hashes to the
blacklist keyring is only allowed when these hashes are signed and
vouched by the builtin trusted keyring. A blacklist hash is stored as a
key description. The PKCS#7 signature of this description must be
provided as the key payload.
Marking a certificate as untrusted should be enforced while the system
is running. It is then forbiden to remove such blacklist keys.
Update blacklist keyring, blacklist key and revoked certificate access rights:
* allows the root user to search for a specific blacklisted hash, which
make sense because the descriptions are already viewable;
* forbids key update (blacklist and asymmetric ones);
* restricts kernel rights on the blacklist keyring to align with the
root user rights.
See help in tools/certs/print-cert-tbs-hash.sh .
Cc: David Howells <dhowells@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Eric Snowberg <eric.snowberg@oracle.com>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Mickaël Salaün <redacted>
Link: https://lore.kernel.org/r/20210712170313.884724-6-mic@digikod.net
---
Changes since v6:
* Rebase on keys-cve-2020-26541-v3: commit ebd9c2ae369a ("integrity:
Load mokx variables into the blacklist keyring").
Changes since v5:
* Rebase on keys-next, fix Kconfig conflict, and update the asymmetric
key rights added to the blacklist keyring by the new
add_key_to_revocation_list(): align with blacklist key rights by
removing KEY_POS_WRITE as a safeguard, and add
KEY_ALLOC_BYPASS_RESTRICTION to not be subject to
restrict_link_for_blacklist() that only allows blacklist key types to
be added to the keyring.
* Change the return code for restrict_link_for_blacklist() from -EPERM
to -EOPNOTSUPP to align with asymmetric key keyrings.
Changes since v3:
* Update commit message for print-cert-tbs-hash.sh .
Changes since v2:
* Add comment for blacklist_key_instantiate().
---
certs/Kconfig | 10 +++++
certs/blacklist.c | 96 ++++++++++++++++++++++++++++++++++++-----------
2 files changed, 85 insertions(+), 21 deletions(-)
@@ -154,8 +189,7 @@ static int mark_raw_hash_blacklisted(const char *hash)hash,NULL,0,-((KEY_POS_ALL&~KEY_POS_SETATTR)|-KEY_USR_VIEW),+BLACKLIST_KEY_PERM,KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN);if(IS_ERR(key)){
@@ -232,8 +266,10 @@ int add_key_to_revocation_list(const char *data, size_t size)NULL,data,size,-((KEY_POS_ALL&~KEY_POS_SETATTR)|KEY_USR_VIEW),-KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN);+KEY_POS_VIEW|KEY_POS_READ|KEY_POS_SEARCH+|KEY_USR_VIEW,+KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN+|KEY_ALLOC_BYPASS_RESTRICTION);if(IS_ERR(key)){pr_err("Problem with revocation key (%ld)\n",PTR_ERR(key));
@@ -260,25 +296,43 @@ int is_key_on_revocation_list(struct pkcs7_message *pkcs7)}#endif+staticintrestrict_link_for_blacklist(structkey*dest_keyring,+conststructkey_type*type,constunionkey_payload*payload,+structkey*restrict_key)+{+if(type==&key_type_blacklist)+return0;+return-EOPNOTSUPP;+}+/**Initialisetheblacklist*/staticint__initblacklist_init(void){constchar*const*bl;+structkey_restriction*restriction;if(register_key_type(&key_type_blacklist)<0)panic("Can't allocate system blacklist key type\n");+restriction=kzalloc(sizeof(*restriction),GFP_KERNEL);+if(!restriction)+panic("Can't allocate blacklist keyring restriction\n");
This prevents me from taking this to my pull request. In moderns standards,
no new BUG_ON(), panic() etc. should never added to the kernel.
I missed this in my review.
This should rather be e.g.
restriction = kzalloc(sizeof(*restriction), GFP_KERNEL);
if (!restriction) {
pr_err("Can't allocate blacklist keyring restriction\n");
return 0;
}
Unfortunately I need to drop this patch set, because adding new panic()
is simply a no-go.
I agree that panic() is not great in general, but I followed the other part
of the code (just above) that do the same. This part of the kernel should
failed if critical memory allocation failed at boot time (only). It doesn't
impact the kernel once it is running. I don't think that just ignoring this
error with return 0 is fine, after all it's a critical error right?
It's not good reason enough to crash the whole kernel, even if it is a
critical error (e.g. run-time foresincs). Even WARN() is not recommended
these days [*].
I think that what Greg said in this email is that WARN*() should only be
used for cases that should never happen, it is definitely not deprecated,
but WARN_ON_ONCE() may be a better idea though. WARN*() helps detect such
thought-to-be-impossible cases, that can happen e.g. with code refactoring.
A lot of initialization/boot code (e.g. without user space nor external
interactions, mostly __init functions) do panic if there is unexpected and
unrecoverable errors like failed memory allocations. I think handling such
errors otherwise would be more complex for no benefit. Moreover, delegating
such error handling to user space could create new (silent) issues.
To crash the whole kernel, you should be able to clearly explain why it
makes sense in the situation.
If there is no enough memory to allocate 24 bytes (struct key_restriction) during early boot, I really doubt the kernel can do much.
quoted
quoted
For the existing panic()-statements: I'm happy to review patches that
render them out. >
Not sure tho, if this fails should it be then "everything blacklisted".
Just one thing to consider.
Well, if it fail it will be "nothing will work afterwards". Do you have a
working and useful scenario for this kind of error?
So you have zero chances to get a shell without blacklist just to do
kernel forensics?
Right, I don't think the kernel can launch any process (nor continue early boot) if it cannot allocate 24 bytes.
From: Jarkko Sakkinen <jarkko@kernel.org> Date: 2022-03-09 23:11:59
On Wed, Mar 09, 2022 at 07:36:50PM +0100, Mickaël Salaün wrote:
On 09/03/2022 17:01, Jarkko Sakkinen wrote:
quoted
On Tue, Mar 08, 2022 at 05:02:23PM +0100, Mickaël Salaün wrote:
quoted
On 08/03/2022 14:19, Jarkko Sakkinen wrote:
quoted
On Tue, Mar 08, 2022 at 01:18:28PM +0100, Mickaël Salaün wrote:
quoted
On 08/03/2022 12:53, Jarkko Sakkinen wrote:
quoted
On Mon, Jul 12, 2021 at 07:03:13PM +0200, Mickaël Salaün wrote:
quoted
From: Mickaël Salaün <redacted>
Add a kernel option SYSTEM_BLACKLIST_AUTH_UPDATE to enable the root user
to dynamically add new keys to the blacklist keyring. This enables to
invalidate new certificates, either from being loaded in a keyring, or
from being trusted in a PKCS#7 certificate chain. This also enables to
add new file hashes to be denied by the integrity infrastructure.
Being able to untrust a certificate which could have normaly been
trusted is a sensitive operation. This is why adding new hashes to the
blacklist keyring is only allowed when these hashes are signed and
vouched by the builtin trusted keyring. A blacklist hash is stored as a
key description. The PKCS#7 signature of this description must be
provided as the key payload.
Marking a certificate as untrusted should be enforced while the system
is running. It is then forbiden to remove such blacklist keys.
Update blacklist keyring, blacklist key and revoked certificate access rights:
* allows the root user to search for a specific blacklisted hash, which
make sense because the descriptions are already viewable;
* forbids key update (blacklist and asymmetric ones);
* restricts kernel rights on the blacklist keyring to align with the
root user rights.
See help in tools/certs/print-cert-tbs-hash.sh .
Cc: David Howells <dhowells@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Eric Snowberg <eric.snowberg@oracle.com>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Mickaël Salaün <redacted>
Link: https://lore.kernel.org/r/20210712170313.884724-6-mic@digikod.net
---
Changes since v6:
* Rebase on keys-cve-2020-26541-v3: commit ebd9c2ae369a ("integrity:
Load mokx variables into the blacklist keyring").
Changes since v5:
* Rebase on keys-next, fix Kconfig conflict, and update the asymmetric
key rights added to the blacklist keyring by the new
add_key_to_revocation_list(): align with blacklist key rights by
removing KEY_POS_WRITE as a safeguard, and add
KEY_ALLOC_BYPASS_RESTRICTION to not be subject to
restrict_link_for_blacklist() that only allows blacklist key types to
be added to the keyring.
* Change the return code for restrict_link_for_blacklist() from -EPERM
to -EOPNOTSUPP to align with asymmetric key keyrings.
Changes since v3:
* Update commit message for print-cert-tbs-hash.sh .
Changes since v2:
* Add comment for blacklist_key_instantiate().
---
certs/Kconfig | 10 +++++
certs/blacklist.c | 96 ++++++++++++++++++++++++++++++++++++-----------
2 files changed, 85 insertions(+), 21 deletions(-)
@@ -154,8 +189,7 @@ static int mark_raw_hash_blacklisted(const char *hash)hash,NULL,0,-((KEY_POS_ALL&~KEY_POS_SETATTR)|-KEY_USR_VIEW),+BLACKLIST_KEY_PERM,KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN);if(IS_ERR(key)){
@@ -232,8 +266,10 @@ int add_key_to_revocation_list(const char *data, size_t size)NULL,data,size,-((KEY_POS_ALL&~KEY_POS_SETATTR)|KEY_USR_VIEW),-KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN);+KEY_POS_VIEW|KEY_POS_READ|KEY_POS_SEARCH+|KEY_USR_VIEW,+KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN+|KEY_ALLOC_BYPASS_RESTRICTION);if(IS_ERR(key)){pr_err("Problem with revocation key (%ld)\n",PTR_ERR(key));
@@ -260,25 +296,43 @@ int is_key_on_revocation_list(struct pkcs7_message *pkcs7)}#endif+staticintrestrict_link_for_blacklist(structkey*dest_keyring,+conststructkey_type*type,constunionkey_payload*payload,+structkey*restrict_key)+{+if(type==&key_type_blacklist)+return0;+return-EOPNOTSUPP;+}+/**Initialisetheblacklist*/staticint__initblacklist_init(void){constchar*const*bl;+structkey_restriction*restriction;if(register_key_type(&key_type_blacklist)<0)panic("Can't allocate system blacklist key type\n");+restriction=kzalloc(sizeof(*restriction),GFP_KERNEL);+if(!restriction)+panic("Can't allocate blacklist keyring restriction\n");
This prevents me from taking this to my pull request. In moderns standards,
no new BUG_ON(), panic() etc. should never added to the kernel.
I missed this in my review.
This should rather be e.g.
restriction = kzalloc(sizeof(*restriction), GFP_KERNEL);
if (!restriction) {
pr_err("Can't allocate blacklist keyring restriction\n");
return 0;
}
Unfortunately I need to drop this patch set, because adding new panic()
is simply a no-go.
I agree that panic() is not great in general, but I followed the other part
of the code (just above) that do the same. This part of the kernel should
failed if critical memory allocation failed at boot time (only). It doesn't
impact the kernel once it is running. I don't think that just ignoring this
error with return 0 is fine, after all it's a critical error right?
It's not good reason enough to crash the whole kernel, even if it is a
critical error (e.g. run-time foresincs). Even WARN() is not recommended
these days [*].
I think that what Greg said in this email is that WARN*() should only be
used for cases that should never happen, it is definitely not deprecated,
but WARN_ON_ONCE() may be a better idea though. WARN*() helps detect such
thought-to-be-impossible cases, that can happen e.g. with code refactoring.
A lot of initialization/boot code (e.g. without user space nor external
interactions, mostly __init functions) do panic if there is unexpected and
unrecoverable errors like failed memory allocations. I think handling such
errors otherwise would be more complex for no benefit. Moreover, delegating
such error handling to user space could create new (silent) issues.
To crash the whole kernel, you should be able to clearly explain why it
makes sense in the situation.
If there is no enough memory to allocate 24 bytes (struct key_restriction)
during early boot, I really doubt the kernel can do much.
quoted
quoted
quoted
For the existing panic()-statements: I'm happy to review patches that
render them out. >
Not sure tho, if this fails should it be then "everything blacklisted".
Just one thing to consider.
Well, if it fail it will be "nothing will work afterwards". Do you have a
working and useful scenario for this kind of error?
So you have zero chances to get a shell without blacklist just to do
kernel forensics?
Right, I don't think the kernel can launch any process (nor continue early
boot) if it cannot allocate 24 bytes.
initcall is just wrong layer to choose to crash the kernel. It should be
either do_initcall_level() or do_one_initcall() that should care about
this (or not care). You can print error message and return -ENODEV;
BR, Jarkko
On Wed, Mar 09, 2022 at 07:36:50PM +0100, Mickaël Salaün wrote:
quoted
On 09/03/2022 17:01, Jarkko Sakkinen wrote:
quoted
On Tue, Mar 08, 2022 at 05:02:23PM +0100, Mickaël Salaün wrote:
quoted
On 08/03/2022 14:19, Jarkko Sakkinen wrote:
quoted
On Tue, Mar 08, 2022 at 01:18:28PM +0100, Mickaël Salaün wrote:
quoted
On 08/03/2022 12:53, Jarkko Sakkinen wrote:
quoted
On Mon, Jul 12, 2021 at 07:03:13PM +0200, Mickaël Salaün wrote:
quoted
From: Mickaël Salaün <redacted>
Add a kernel option SYSTEM_BLACKLIST_AUTH_UPDATE to enable the root user
to dynamically add new keys to the blacklist keyring. This enables to
invalidate new certificates, either from being loaded in a keyring, or
from being trusted in a PKCS#7 certificate chain. This also enables to
add new file hashes to be denied by the integrity infrastructure.
Being able to untrust a certificate which could have normaly been
trusted is a sensitive operation. This is why adding new hashes to the
blacklist keyring is only allowed when these hashes are signed and
vouched by the builtin trusted keyring. A blacklist hash is stored as a
key description. The PKCS#7 signature of this description must be
provided as the key payload.
Marking a certificate as untrusted should be enforced while the system
is running. It is then forbiden to remove such blacklist keys.
Update blacklist keyring, blacklist key and revoked certificate access rights:
* allows the root user to search for a specific blacklisted hash, which
make sense because the descriptions are already viewable;
* forbids key update (blacklist and asymmetric ones);
* restricts kernel rights on the blacklist keyring to align with the
root user rights.
See help in tools/certs/print-cert-tbs-hash.sh .
Cc: David Howells <dhowells@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Eric Snowberg <eric.snowberg@oracle.com>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Mickaël Salaün <redacted>
Link: https://lore.kernel.org/r/20210712170313.884724-6-mic@digikod.net
---
Changes since v6:
* Rebase on keys-cve-2020-26541-v3: commit ebd9c2ae369a ("integrity:
Load mokx variables into the blacklist keyring").
Changes since v5:
* Rebase on keys-next, fix Kconfig conflict, and update the asymmetric
key rights added to the blacklist keyring by the new
add_key_to_revocation_list(): align with blacklist key rights by
removing KEY_POS_WRITE as a safeguard, and add
KEY_ALLOC_BYPASS_RESTRICTION to not be subject to
restrict_link_for_blacklist() that only allows blacklist key types to
be added to the keyring.
* Change the return code for restrict_link_for_blacklist() from -EPERM
to -EOPNOTSUPP to align with asymmetric key keyrings.
Changes since v3:
* Update commit message for print-cert-tbs-hash.sh .
Changes since v2:
* Add comment for blacklist_key_instantiate().
---
certs/Kconfig | 10 +++++
certs/blacklist.c | 96 ++++++++++++++++++++++++++++++++++++-----------
2 files changed, 85 insertions(+), 21 deletions(-)
@@ -154,8 +189,7 @@ static int mark_raw_hash_blacklisted(const char *hash)hash,NULL,0,-((KEY_POS_ALL&~KEY_POS_SETATTR)|-KEY_USR_VIEW),+BLACKLIST_KEY_PERM,KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN);if(IS_ERR(key)){
@@ -232,8 +266,10 @@ int add_key_to_revocation_list(const char *data, size_t size)NULL,data,size,-((KEY_POS_ALL&~KEY_POS_SETATTR)|KEY_USR_VIEW),-KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN);+KEY_POS_VIEW|KEY_POS_READ|KEY_POS_SEARCH+|KEY_USR_VIEW,+KEY_ALLOC_NOT_IN_QUOTA|KEY_ALLOC_BUILT_IN+|KEY_ALLOC_BYPASS_RESTRICTION);if(IS_ERR(key)){pr_err("Problem with revocation key (%ld)\n",PTR_ERR(key));
@@ -260,25 +296,43 @@ int is_key_on_revocation_list(struct pkcs7_message *pkcs7)}#endif+staticintrestrict_link_for_blacklist(structkey*dest_keyring,+conststructkey_type*type,constunionkey_payload*payload,+structkey*restrict_key)+{+if(type==&key_type_blacklist)+return0;+return-EOPNOTSUPP;+}+/**Initialisetheblacklist*/staticint__initblacklist_init(void){constchar*const*bl;+structkey_restriction*restriction;if(register_key_type(&key_type_blacklist)<0)panic("Can't allocate system blacklist key type\n");+restriction=kzalloc(sizeof(*restriction),GFP_KERNEL);+if(!restriction)+panic("Can't allocate blacklist keyring restriction\n");
This prevents me from taking this to my pull request. In moderns standards,
no new BUG_ON(), panic() etc. should never added to the kernel.
I missed this in my review.
This should rather be e.g.
restriction = kzalloc(sizeof(*restriction), GFP_KERNEL);
if (!restriction) {
pr_err("Can't allocate blacklist keyring restriction\n");
return 0;
}
Unfortunately I need to drop this patch set, because adding new panic()
is simply a no-go.
I agree that panic() is not great in general, but I followed the other part
of the code (just above) that do the same. This part of the kernel should
failed if critical memory allocation failed at boot time (only). It doesn't
impact the kernel once it is running. I don't think that just ignoring this
error with return 0 is fine, after all it's a critical error right?
It's not good reason enough to crash the whole kernel, even if it is a
critical error (e.g. run-time foresincs). Even WARN() is not recommended
these days [*].
I think that what Greg said in this email is that WARN*() should only be
used for cases that should never happen, it is definitely not deprecated,
but WARN_ON_ONCE() may be a better idea though. WARN*() helps detect such
thought-to-be-impossible cases, that can happen e.g. with code refactoring.
A lot of initialization/boot code (e.g. without user space nor external
interactions, mostly __init functions) do panic if there is unexpected and
unrecoverable errors like failed memory allocations. I think handling such
errors otherwise would be more complex for no benefit. Moreover, delegating
such error handling to user space could create new (silent) issues.
To crash the whole kernel, you should be able to clearly explain why it
makes sense in the situation.
If there is no enough memory to allocate 24 bytes (struct key_restriction)
during early boot, I really doubt the kernel can do much.
quoted
quoted
quoted
For the existing panic()-statements: I'm happy to review patches that
render them out. >
Not sure tho, if this fails should it be then "everything blacklisted".
Just one thing to consider.
Well, if it fail it will be "nothing will work afterwards". Do you have a
working and useful scenario for this kind of error?
So you have zero chances to get a shell without blacklist just to do
kernel forensics?
Right, I don't think the kernel can launch any process (nor continue early
boot) if it cannot allocate 24 bytes.
initcall is just wrong layer to choose to crash the kernel. It should be
either do_initcall_level() or do_one_initcall() that should care about
this (or not care). You can print error message and return -ENODEV;
Ok, I'll do that. Is it OK if I send you a patch fixing all panic calls from blacklist_init() and system_trusted_keyring_init() to apply after this series (with the panic call)?
From: Jarkko Sakkinen <jarkko@kernel.org> Date: 2022-03-11 16:46:32
On Fri, 2022-03-11 at 17:36 +0100, Mickaël Salaün wrote:
On 10/03/2022 00:11, Jarkko Sakkinen wrote:
quoted
On Wed, Mar 09, 2022 at 07:36:50PM +0100, Mickaël Salaün wrote:
quoted
On 09/03/2022 17:01, Jarkko Sakkinen wrote:
quoted
On Tue, Mar 08, 2022 at 05:02:23PM +0100, Mickaël Salaün wrote:
quoted
On 08/03/2022 14:19, Jarkko Sakkinen wrote:
quoted
On Tue, Mar 08, 2022 at 01:18:28PM +0100, Mickaël Salaün wrote:
quoted
On 08/03/2022 12:53, Jarkko Sakkinen wrote:
quoted
On Mon, Jul 12, 2021 at 07:03:13PM +0200, Mickaël Salaün wrote:
quoted
From: Mickaël Salaün <redacted>
Add a kernel option SYSTEM_BLACKLIST_AUTH_UPDATE to enable the root user
to dynamically add new keys to the blacklist keyring. This enables to
invalidate new certificates, either from being loaded in a keyring, or
from being trusted in a PKCS#7 certificate chain. This also enables to
add new file hashes to be denied by the integrity infrastructure.
Being able to untrust a certificate which could have normaly been
trusted is a sensitive operation. This is why adding new hashes to the
blacklist keyring is only allowed when these hashes are signed and
vouched by the builtin trusted keyring. A blacklist hash is stored as a
key description. The PKCS#7 signature of this description must be
provided as the key payload.
Marking a certificate as untrusted should be enforced while the system
is running. It is then forbiden to remove such blacklist keys.
Update blacklist keyring, blacklist key and revoked certificate access rights:
* allows the root user to search for a specific blacklisted hash, which
make sense because the descriptions are already viewable;
* forbids key update (blacklist and asymmetric ones);
* restricts kernel rights on the blacklist keyring to align with the
root user rights.
See help in tools/certs/print-cert-tbs-hash.sh .
Cc: David Howells <dhowells@redhat.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Eric Snowberg <eric.snowberg@oracle.com>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Mickaël Salaün <redacted>
Link: https://lore.kernel.org/r/20210712170313.884724-6-mic@digikod.net
---
Changes since v6:
* Rebase on keys-cve-2020-26541-v3: commit ebd9c2ae369a ("integrity:
Load mokx variables into the blacklist keyring").
Changes since v5:
* Rebase on keys-next, fix Kconfig conflict, and update the asymmetric
key rights added to the blacklist keyring by the new
add_key_to_revocation_list(): align with blacklist key rights by
removing KEY_POS_WRITE as a safeguard, and add
KEY_ALLOC_BYPASS_RESTRICTION to not be subject to
restrict_link_for_blacklist() that only allows blacklist key types to
be added to the keyring.
* Change the return code for restrict_link_for_blacklist() from -EPERM
to -EOPNOTSUPP to align with asymmetric key keyrings.
Changes since v3:
* Update commit message for print-cert-tbs-hash.sh .
Changes since v2:
* Add comment for blacklist_key_instantiate().
---
certs/Kconfig | 10 +++++
certs/blacklist.c | 96 ++++++++++++++++++++++++++++++++++++-----------
2 files changed, 85 insertions(+), 21 deletions(-)
containing X.509 certificates to be included in the default blacklist
keyring.
+config SYSTEM_BLACKLIST_AUTH_UPDATE
+ bool "Allow root to add signed blacklist keys"
+ depends on SYSTEM_BLACKLIST_KEYRING
+ depends on SYSTEM_DATA_VERIFICATION
+ help
+ If set, provide the ability to load new blacklist keys at run time if
+ they are signed and vouched by a certificate from the builtin trusted
+ keyring. The PKCS#7 signature of the description is set in the key
+ payload. Blacklist keys cannot be removed.
+
endmenu
@@ -80,19 +84,51 @@ static int blacklist_vet_description(const char *desc)
return 0;
}
-/*
- * The hash to be blacklisted is expected to be in the description. There will
- * be no payload.
- */
-static int blacklist_preparse(struct key_preparsed_payload *prep)
+static int blacklist_key_instantiate(struct key *key,
+ struct key_preparsed_payload *prep)
{
- if (prep->datalen > 0)
- return -EINVAL;
- return 0;
+#ifdef CONFIG_SYSTEM_BLACKLIST_AUTH_UPDATE
+ int err;
+#endif
+
+ /* Sets safe default permissions for keys loaded by user space. */
+ key->perm = BLACKLIST_KEY_PERM;
+
+ /*
+ * Skips the authentication step for builtin hashes, they are not
+ * signed but still trusted.
+ */
+ if (key->flags & (1 << KEY_FLAG_BUILTIN))
+ goto out;
+
+#ifdef CONFIG_SYSTEM_BLACKLIST_AUTH_UPDATE
+ /*
+ * Verifies the description's PKCS#7 signature against the builtin
+ * trusted keyring.
+ */
+ err = verify_pkcs7_signature(key->description,
+ strlen(key->description), prep->data, prep->datalen,
+ NULL, VERIFYING_UNSPECIFIED_SIGNATURE, NULL, NULL);
+ if (err)
+ return err;
+#else
+ /*
+ * It should not be possible to come here because the keyring doesn't
+ * have KEY_USR_WRITE and the only other way to call this function is
+ * for builtin hashes.
+ */
+ WARN_ON_ONCE(1);
+ return -EPERM;
+#endif
+
+out:
+ return generic_key_instantiate(key, prep);
}
-static void blacklist_free_preparse(struct key_preparsed_payload *prep)
+static int blacklist_key_update(struct key *key,
+ struct key_preparsed_payload *prep)
{
+ return -EPERM;
}
static void blacklist_describe(const struct key *key, struct seq_file *m)
@@ -260,25 +296,43 @@ int is_key_on_revocation_list(struct pkcs7_message *pkcs7)
}
#endif
+static int restrict_link_for_blacklist(struct key *dest_keyring,
+ const struct key_type *type, const union key_payload *payload,
+ struct key *restrict_key)
+{
+ if (type == &key_type_blacklist)
+ return 0;
+ return -EOPNOTSUPP;
+}
+
/*
* Initialise the blacklist
*/
static int __init blacklist_init(void)
{
const char *const *bl;
+ struct key_restriction *restriction;
if (register_key_type(&key_type_blacklist) < 0)
panic("Can't allocate system blacklist key type\n");
+ restriction = kzalloc(sizeof(*restriction), GFP_KERNEL);
+ if (!restriction)
+ panic("Can't allocate blacklist keyring restriction\n");
This prevents me from taking this to my pull request. In moderns standards,
no new BUG_ON(), panic() etc. should never added to the kernel.
I missed this in my review.
This should rather be e.g.
restriction = kzalloc(sizeof(*restriction), GFP_KERNEL);
if (!restriction) {
pr_err("Can't allocate blacklist keyring restriction\n");
return 0;
}
Unfortunately I need to drop this patch set, because adding new panic()
is simply a no-go.
I agree that panic() is not great in general, but I followed the other part
of the code (just above) that do the same. This part of the kernel should
failed if critical memory allocation failed at boot time (only). It doesn't
impact the kernel once it is running. I don't think that just ignoring this
error with return 0 is fine, after all it's a critical error right?
It's not good reason enough to crash the whole kernel, even if it is a
critical error (e.g. run-time foresincs). Even WARN() is not recommended
these days [*].
I think that what Greg said in this email is that WARN*() should only be
used for cases that should never happen, it is definitely not deprecated,
but WARN_ON_ONCE() may be a better idea though. WARN*() helps detect such
thought-to-be-impossible cases, that can happen e.g. with code refactoring.
A lot of initialization/boot code (e.g. without user space nor external
interactions, mostly __init functions) do panic if there is unexpected and
unrecoverable errors like failed memory allocations. I think handling such
errors otherwise would be more complex for no benefit. Moreover, delegating
such error handling to user space could create new (silent) issues.
To crash the whole kernel, you should be able to clearly explain why it
makes sense in the situation.
If there is no enough memory to allocate 24 bytes (struct key_restriction)
during early boot, I really doubt the kernel can do much.
quoted
quoted
quoted
For the existing panic()-statements: I'm happy to review patches that
render them out. >
Not sure tho, if this fails should it be then "everything blacklisted".
Just one thing to consider.
Well, if it fail it will be "nothing will work afterwards". Do you have a
working and useful scenario for this kind of error?
So you have zero chances to get a shell without blacklist just to do
kernel forensics?
Right, I don't think the kernel can launch any process (nor continue early
boot) if it cannot allocate 24 bytes.
initcall is just wrong layer to choose to crash the kernel. It should be
either do_initcall_level() or do_one_initcall() that should care about
this (or not care). You can print error message and return -ENODEV;
Ok, I'll do that. Is it OK if I send you a patch fixing all panic calls
from blacklist_init() and system_trusted_keyring_init() to apply after
this series (with the panic call)?
Yes, and I still have not sent my PR, i.e. can include this if you
can provide me patches soonish (include that to the same series).
In the end of the day it comes to this: it's not a void function.
ATM the framework above does not do much at all but it is IMHO
going beyond the abstraction, which we should not do.
BR, Jarkko
From: David Howells <dhowells@redhat.com> Date: 2022-03-30 13:44:48
Jarkko Sakkinen [off-list ref] wrote:
quoted
/* * Initialise the blacklist */ static int __init blacklist_init(void) { const char *const *bl;+ struct key_restriction *restriction; if (register_key_type(&key_type_blacklist) < 0) panic("Can't allocate system blacklist key type\n");+ restriction = kzalloc(sizeof(*restriction), GFP_KERNEL);+ if (!restriction)+ panic("Can't allocate blacklist keyring restriction\n");
This prevents me from taking this to my pull request. In moderns standards,
no new BUG_ON(), panic() etc. should never added to the kernel.
I would argue that in this case, though, it is reasonable. This should only
be called during kernel initialisation and, as Mickaël points out, if you
can't allocate that small amount of memory, the kernel isn't going to boot
much further.
I missed this in my review.
This should rather be e.g.
restriction = kzalloc(sizeof(*restriction), GFP_KERNEL);
if (!restriction) {
pr_err("Can't allocate blacklist keyring restriction\n");
return 0;
}
You can't just return 0. That indicates success - but if by some miracle, the
kernel actually gets to a point where userspace can happen, it could mean that
we're missing the security restrictions of the blacklist.
Now, we could defer the panic to add_key_to_revocation_list(), but if you
can't set in place the required security restrictions, I think it's arguable
that the kernel either needs to panic or it needs to blacklist everything.
David