aboutsummaryrefslogtreecommitdiffstats
path: root/security/keys
diff options
context:
space:
mode:
Diffstat (limited to 'security/keys')
-rw-r--r--security/keys/keyring.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/security/keys/keyring.c b/security/keys/keyring.c
index dd7cd0f8e13..0b27271c670 100644
--- a/security/keys/keyring.c
+++ b/security/keys/keyring.c
@@ -526,9 +526,8 @@ struct key *find_keyring_by_name(const char *name, bool skip_perm_check)
526 struct key *keyring; 526 struct key *keyring;
527 int bucket; 527 int bucket;
528 528
529 keyring = ERR_PTR(-EINVAL);
530 if (!name) 529 if (!name)
531 goto error; 530 return ERR_PTR(-EINVAL);
532 531
533 bucket = keyring_hash(name); 532 bucket = keyring_hash(name);
534 533
@@ -555,17 +554,18 @@ struct key *find_keyring_by_name(const char *name, bool skip_perm_check)
555 KEY_SEARCH) < 0) 554 KEY_SEARCH) < 0)
556 continue; 555 continue;
557 556
558 /* we've got a match */ 557 /* we've got a match but we might end up racing with
559 atomic_inc(&keyring->usage); 558 * key_cleanup() if the keyring is currently 'dead'
560 read_unlock(&keyring_name_lock); 559 * (ie. it has a zero usage count) */
561 goto error; 560 if (!atomic_inc_not_zero(&keyring->usage))
561 continue;
562 goto out;
562 } 563 }
563 } 564 }
564 565
565 read_unlock(&keyring_name_lock);
566 keyring = ERR_PTR(-ENOKEY); 566 keyring = ERR_PTR(-ENOKEY);
567 567out:
568 error: 568 read_unlock(&keyring_name_lock);
569 return keyring; 569 return keyring;
570 570
571} /* end find_keyring_by_name() */ 571} /* end find_keyring_by_name() */