Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1252366pxb; Wed, 10 Feb 2021 04:08:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxF9t+GzDfds/uFEV6DjjsLll6CSMwNqVHf9S1ec820PeJL81Ct+QMX5FAkv0lddB3bMSCb X-Received: by 2002:a05:6402:1589:: with SMTP id c9mr2926396edv.282.1612958913396; Wed, 10 Feb 2021 04:08:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612958913; cv=none; d=google.com; s=arc-20160816; b=ostF0To5i6Ydw1Wm/Dq3IKVrQO2tsWwKozePW4o9XgcCIByQ8X3+6Vpl2+XcZgahI2 HCO2VakWTAu5xwgVXc1YYN2Cc/Sy/6AcXmWPlUCZlqX7lnnEZmLghCB/9wcMXJc0yYPw 1iKrHD3lklL64BaCQgg2RjyTRVbFQzYmvDH0ScXPevIoBsDWKIVaH6YgXIdKAJZbAMGc kgoZE3E3idJkHvqIMWIrdXSWDlRsX1R4v1pZRSTyZ6c6IiUpSXFLrl/mPmxGgIuBXUNu 7pAcwvHt4qTl0R4PWTeJHBHWRmwZgCcXdrOOGWCaGjLl8KNnVNPty9oTzTgMc2P5PbJ8 yVHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=II9I4PpAgSqI+h4IjqTD/sE+e/QX3LqZfAhNJ6L9xgs=; b=N+Bkr/2Y3y+obz9nyKU0Yi3d5iPdvIxgKmp+FVj3HUyhS7guLXdurvGBP9h/hnhSnd 3QVlJxRsC/cydS/OWK/WQQDq1wPAzBjNhfoumA7aGg9bI9XZ4ECNHwPFqKoCNP5PNlTE gmGtj2LDq7j+rctLehFiFvOvN1dB3FHDN+m75WKRB73V6IEQ4VhfX0OvWpCDrE4ScpBL 66oAnBd1VHyycGHcxuojPwqRSWKgqsZetUsVj41yRKXSA0fnKw3ZGu5owRl7MjvjG8zH kYhV6Wg56xFLVNlKUOE+uXRdoc68olniCI5YZtwh3vnAWuLKzcj/WkA9sDgVePmcnqVo T4gg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t15si1118989ejj.506.2021.02.10.04.08.03; Wed, 10 Feb 2021 04:08:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230470AbhBJMHL (ORCPT + 99 others); Wed, 10 Feb 2021 07:07:11 -0500 Received: from smtp-bc0e.mail.infomaniak.ch ([45.157.188.14]:58901 "EHLO smtp-bc0e.mail.infomaniak.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231195AbhBJMFD (ORCPT ); Wed, 10 Feb 2021 07:05:03 -0500 Received: from smtp-3-0000.mail.infomaniak.ch (unknown [10.4.36.107]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4DbJMJ3SkwzMpnnY; Wed, 10 Feb 2021 13:03:56 +0100 (CET) Received: from localhost (unknown [23.97.221.149]) by smtp-3-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4DbJMJ1RH9zlh8TM; Wed, 10 Feb 2021 13:03:56 +0100 (CET) From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: David Howells , David Woodhouse , Jarkko Sakkinen Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , "David S . Miller" , Eric Snowberg , Herbert Xu , James Morris , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Mimi Zohar , "Serge E . Hallyn" , Tyler Hicks , keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH v6 5/5] certs: Allow root user to append signed hashes to the blacklist keyring Date: Wed, 10 Feb 2021 13:04:10 +0100 Message-Id: <20210210120410.471693-6-mic@digikod.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210210120410.471693-1-mic@digikod.net> References: <20210210120410.471693-1-mic@digikod.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Mickaël Salaün 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 Cc: David Woodhouse Cc: Eric Snowberg Cc: Jarkko Sakkinen Signed-off-by: Mickaël Salaün --- 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(-) diff --git a/certs/Kconfig b/certs/Kconfig index 139940b54207..555491fdde0e 100644 --- a/certs/Kconfig +++ b/certs/Kconfig @@ -94,4 +94,14 @@ config SYSTEM_REVOCATION_KEYS 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 diff --git a/certs/blacklist.c b/certs/blacklist.c index 9fe79597bda7..731e8e5bb6d8 100644 --- a/certs/blacklist.c +++ b/certs/blacklist.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "blacklist.h" #include "common.h" @@ -26,6 +27,9 @@ */ #define MAX_HASH_LEN 128 +#define BLACKLIST_KEY_PERM (KEY_POS_SEARCH | KEY_POS_VIEW | \ + KEY_USR_SEARCH | KEY_USR_VIEW) + static const char tbs_prefix[] = "tbs"; static const char bin_prefix[] = "bin"; @@ -78,19 +82,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) @@ -101,9 +137,8 @@ static void blacklist_describe(const struct key *key, struct seq_file *m) static struct key_type key_type_blacklist = { .name = "blacklist", .vet_description = blacklist_vet_description, - .preparse = blacklist_preparse, - .free_preparse = blacklist_free_preparse, - .instantiate = generic_key_instantiate, + .instantiate = blacklist_key_instantiate, + .update = blacklist_key_update, .describe = blacklist_describe, }; @@ -152,8 +187,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)) { @@ -172,8 +206,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)); @@ -247,25 +283,43 @@ int is_binary_blacklisted(const u8 *hash, size_t hash_len) } EXPORT_SYMBOL_GPL(is_binary_blacklisted); +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"); + restriction->check = restrict_link_for_blacklist; + blacklist_keyring = keyring_alloc(".blacklist", GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, current_cred(), - (KEY_POS_ALL & ~KEY_POS_SETATTR) | - KEY_USR_VIEW | KEY_USR_READ | - KEY_USR_SEARCH, - KEY_ALLOC_NOT_IN_QUOTA | + KEY_POS_VIEW | KEY_POS_READ | KEY_POS_SEARCH | + KEY_POS_WRITE | + KEY_USR_VIEW | KEY_USR_READ | KEY_USR_SEARCH +#ifdef CONFIG_SYSTEM_BLACKLIST_AUTH_UPDATE + | KEY_USR_WRITE +#endif + , KEY_ALLOC_NOT_IN_QUOTA | KEY_ALLOC_SET_KEEP, - NULL, NULL); + restriction, NULL); if (IS_ERR(blacklist_keyring)) panic("Can't allocate system blacklist keyring\n"); -- 2.30.0