linux/security/integrity/ima
David Howells 0fec3272ab certs: Fix blacklist flag type confusion
[ Upstream commit 4993e1f9479a4161fd7d93e2b8b30b438f00cb0f ]

KEY_FLAG_KEEP is not meant to be passed to keyring_alloc() or key_alloc(),
as these only take KEY_ALLOC_* flags.  KEY_FLAG_KEEP has the same value as
KEY_ALLOC_BYPASS_RESTRICTION, but fortunately only key_create_or_update()
uses it.  LSMs using the key_alloc hook don't check that flag.

KEY_FLAG_KEEP is then ignored but fortunately (again) the root user cannot
write to the blacklist keyring, so it is not possible to remove a key/hash
from it.

Fix this by adding a KEY_ALLOC_SET_KEEP flag that tells key_alloc() to set
KEY_FLAG_KEEP on the new key.  blacklist_init() can then, correctly, pass
this to keyring_alloc().

We can also use this in ima_mok_init() rather than setting the flag
manually.

Note that this doesn't fix an observable bug with the current
implementation but it is required to allow addition of new hashes to the
blacklist in the future without making it possible for them to be removed.

Fixes: 734114f878 ("KEYS: Add a system blacklist keyring")
Reported-by: Mickaël Salaün <mic@linux.microsoft.com>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Mickaël Salaün <mic@linux.microsoft.com>
cc: Mimi Zohar <zohar@linux.vnet.ibm.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-03-04 10:26:29 +01:00
..
Kconfig ima: move APPRAISE_BOOTPARAM dependency on ARCH_POLICY to runtime 2020-08-11 15:33:41 +02:00
Makefile ima: Add modsig appraise_type option for module-style appended signatures 2019-08-05 18:40:21 -04:00
ima.h ima: extend boot_aggregate with kernel measurements 2020-12-08 10:40:24 +01:00
ima_api.c ima: ima_api: Use struct_size() in kzalloc() 2019-08-29 14:23:30 -04:00
ima_appraise.c ima: move APPRAISE_BOOTPARAM dependency on ARCH_POLICY to runtime 2020-08-11 15:33:41 +02:00
ima_crypto.c ima: Don't modify file descriptor mode on the fly 2020-12-30 11:51:39 +01:00
ima_fs.c ima: Fix return value of ima_write_policy() 2020-05-27 17:46:08 +02:00
ima_init.c ima: Call ima_calc_boot_aggregate() in ima_eventdigest_init() 2020-06-22 09:31:15 +02:00
ima_kexec.c ima: Free IMA measurement buffer after kexec syscall 2021-03-04 10:26:25 +01:00
ima_main.c ima: Evaluate error in init_ima() 2020-06-22 09:31:14 +02:00
ima_modsig.c ima: Fix use after free in ima_read_modsig() 2019-08-28 15:01:24 -04:00
ima_mok.c certs: Fix blacklist flag type confusion 2021-03-04 10:26:29 +01:00
ima_policy.c ima: Have the LSM free its audit rule 2020-08-19 08:16:12 +02:00
ima_queue.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 441 2019-06-05 17:37:17 +02:00
ima_template.c ima: use struct_size() in kzalloc() 2019-08-29 14:23:22 -04:00
ima_template_lib.c ima: Call ima_calc_boot_aggregate() in ima_eventdigest_init() 2020-06-22 09:31:15 +02:00
ima_template_lib.h ima: Define ima-modsig template 2019-08-05 18:40:25 -04:00