2019-06-01 16:08:55 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2015-12-02 23:47:55 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Juniper Networks, Inc.
|
|
|
|
*
|
|
|
|
* Author:
|
|
|
|
* Petko Manolov <petko.manolov@konsulko.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/export.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/cred.h>
|
|
|
|
#include <linux/err.h>
|
2015-12-10 06:37:16 +08:00
|
|
|
#include <linux/init.h>
|
2016-09-01 07:05:43 +08:00
|
|
|
#include <linux/slab.h>
|
KEYS: Move the point of trust determination to __key_link()
Move the point at which a key is determined to be trustworthy to
__key_link() so that we use the contents of the keyring being linked in to
to determine whether the key being linked in is trusted or not.
What is 'trusted' then becomes a matter of what's in the keyring.
Currently, the test is done when the key is parsed, but given that at that
point we can only sensibly refer to the contents of the system trusted
keyring, we can only use that as the basis for working out the
trustworthiness of a new key.
With this change, a trusted keyring is a set of keys that once the
trusted-only flag is set cannot be added to except by verification through
one of the contained keys.
Further, adding a key into a trusted keyring, whilst it might grant
trustworthiness in the context of that keyring, does not automatically
grant trustworthiness in the context of a second keyring to which it could
be secondarily linked.
To accomplish this, the authentication data associated with the key source
must now be retained. For an X.509 cert, this means the contents of the
AuthorityKeyIdentifier and the signature data.
If system keyrings are disabled then restrict_link_by_builtin_trusted()
resolves to restrict_link_reject(). The integrity digital signature code
still works correctly with this as it was previously using
KEY_FLAG_TRUSTED_ONLY, which doesn't permit anything to be added if there
is no system keyring against which trust can be determined.
Signed-off-by: David Howells <dhowells@redhat.com>
2016-04-06 23:14:26 +08:00
|
|
|
#include <keys/system_keyring.h>
|
2015-12-02 23:47:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
struct key *ima_blacklist_keyring;
|
|
|
|
|
|
|
|
/*
|
2016-04-07 16:45:23 +08:00
|
|
|
* Allocate the IMA blacklist keyring
|
2015-12-02 23:47:55 +08:00
|
|
|
*/
|
|
|
|
__init int ima_mok_init(void)
|
|
|
|
{
|
2016-09-01 07:05:43 +08:00
|
|
|
struct key_restriction *restriction;
|
|
|
|
|
2016-04-07 16:45:23 +08:00
|
|
|
pr_notice("Allocating IMA blacklist keyring.\n");
|
2015-12-02 23:47:55 +08:00
|
|
|
|
2016-09-01 07:05:43 +08:00
|
|
|
restriction = kzalloc(sizeof(struct key_restriction), GFP_KERNEL);
|
|
|
|
if (!restriction)
|
|
|
|
panic("Can't allocate IMA blacklist restriction.");
|
|
|
|
|
|
|
|
restriction->check = restrict_link_by_builtin_trusted;
|
|
|
|
|
2015-12-02 23:47:55 +08:00
|
|
|
ima_blacklist_keyring = keyring_alloc(".ima_blacklist",
|
|
|
|
KUIDT_INIT(0), KGIDT_INIT(0), current_cred(),
|
2019-07-11 09:43:43 +08:00
|
|
|
(KEY_POS_ALL & ~KEY_POS_SETATTR) |
|
|
|
|
KEY_USR_VIEW | KEY_USR_READ |
|
|
|
|
KEY_USR_WRITE | KEY_USR_SEARCH,
|
2020-11-21 02:04:23 +08:00
|
|
|
KEY_ALLOC_NOT_IN_QUOTA |
|
|
|
|
KEY_ALLOC_SET_KEEP,
|
2016-09-01 07:05:43 +08:00
|
|
|
restriction, NULL);
|
2015-12-02 23:47:55 +08:00
|
|
|
|
2016-04-07 16:45:23 +08:00
|
|
|
if (IS_ERR(ima_blacklist_keyring))
|
|
|
|
panic("Can't allocate IMA blacklist keyring.");
|
2015-12-02 23:47:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2015-12-10 06:37:16 +08:00
|
|
|
device_initcall(ima_mok_init);
|