summaryrefslogtreecommitdiffstats
path: root/security/keys/key.c
diff options
context:
space:
mode:
authorMat Martineau <mathew.j.martineau@linux.intel.com>2016-10-04 19:27:32 -0400
committerMat Martineau <mathew.j.martineau@linux.intel.com>2017-04-04 17:10:11 -0400
commit4a420896f12d2d043602f134ae18ad6be5b9d9dd (patch)
treee94fefe0dd32c3bbe3a3585277305ce8b270201f /security/keys/key.c
parentefba797b977c99bc6e0c301299272c80fb8b287f (diff)
KEYS: Consistent ordering for __key_link_begin and restrict check
The keyring restrict callback was sometimes called before __key_link_begin and sometimes after, which meant that the keyring semaphores were not always held during the restrict callback. If the semaphores are consistently acquired before checking link restrictions, keyring contents cannot be changed after the restrict check is complete but before the evaluated key is linked to the keyring. Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Diffstat (limited to 'security/keys/key.c')
-rw-r--r--security/keys/key.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/security/keys/key.c b/security/keys/key.c
index 2ea5967121de..455c04d80bbb 100644
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -500,21 +500,23 @@ int key_instantiate_and_link(struct key *key,
500 } 500 }
501 501
502 if (keyring) { 502 if (keyring) {
503 ret = __key_link_begin(keyring, &key->index_key, &edit);
504 if (ret < 0)
505 goto error;
506
503 if (keyring->restrict_link && keyring->restrict_link->check) { 507 if (keyring->restrict_link && keyring->restrict_link->check) {
504 struct key_restriction *keyres = keyring->restrict_link; 508 struct key_restriction *keyres = keyring->restrict_link;
505 509
506 ret = keyres->check(keyring, key->type, &prep.payload, 510 ret = keyres->check(keyring, key->type, &prep.payload,
507 keyres->key); 511 keyres->key);
508 if (ret < 0) 512 if (ret < 0)
509 goto error; 513 goto error_link_end;
510 } 514 }
511 ret = __key_link_begin(keyring, &key->index_key, &edit);
512 if (ret < 0)
513 goto error;
514 } 515 }
515 516
516 ret = __key_instantiate_and_link(key, &prep, keyring, authkey, &edit); 517 ret = __key_instantiate_and_link(key, &prep, keyring, authkey, &edit);
517 518
519error_link_end:
518 if (keyring) 520 if (keyring)
519 __key_link_end(keyring, &key->index_key, edit); 521 __key_link_end(keyring, &key->index_key, edit);
520 522
@@ -855,21 +857,21 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
855 } 857 }
856 index_key.desc_len = strlen(index_key.description); 858 index_key.desc_len = strlen(index_key.description);
857 859
860 ret = __key_link_begin(keyring, &index_key, &edit);
861 if (ret < 0) {
862 key_ref = ERR_PTR(ret);
863 goto error_free_prep;
864 }
865
858 if (restrict_link && restrict_link->check) { 866 if (restrict_link && restrict_link->check) {
859 ret = restrict_link->check(keyring, index_key.type, 867 ret = restrict_link->check(keyring, index_key.type,
860 &prep.payload, restrict_link->key); 868 &prep.payload, restrict_link->key);
861 if (ret < 0) { 869 if (ret < 0) {
862 key_ref = ERR_PTR(ret); 870 key_ref = ERR_PTR(ret);
863 goto error_free_prep; 871 goto error_link_end;
864 } 872 }
865 } 873 }
866 874
867 ret = __key_link_begin(keyring, &index_key, &edit);
868 if (ret < 0) {
869 key_ref = ERR_PTR(ret);
870 goto error_free_prep;
871 }
872
873 /* if we're going to allocate a new key, we're going to have 875 /* if we're going to allocate a new key, we're going to have
874 * to modify the keyring */ 876 * to modify the keyring */
875 ret = key_permission(keyring_ref, KEY_NEED_WRITE); 877 ret = key_permission(keyring_ref, KEY_NEED_WRITE);