Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 190620
b: refs/heads/master
c: f0641cb
h: refs/heads/master
v: v3
  • Loading branch information
David Howells authored and James Morris committed May 5, 2010
1 parent c1a9d36 commit 299a550
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: cea7daa3589d6b550546a8c8963599f7c1a3ae5c
refs/heads/master: f0641cba7729e5e14f82d2eedc398103f5fa31b1
23 changes: 13 additions & 10 deletions trunk/security/keys/keyring.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
#include <asm/uaccess.h>
#include "internal.h"

#define rcu_dereference_locked_keyring(keyring) \
(rcu_dereference_protected( \
(keyring)->payload.subscriptions, \
rwsem_is_locked((struct rw_semaphore *)&(keyring)->sem)))

/*
* when plumbing the depths of the key tree, this sets a hard limit set on how
* deep we're willing to go
Expand Down Expand Up @@ -201,8 +206,7 @@ static long keyring_read(const struct key *keyring,
int loop, ret;

ret = 0;
klist = keyring->payload.subscriptions;

klist = rcu_dereference_locked_keyring(keyring);
if (klist) {
/* calculate how much data we could return */
qty = klist->nkeys * sizeof(key_serial_t);
Expand Down Expand Up @@ -720,8 +724,7 @@ int __key_link(struct key *keyring, struct key *key)
}

/* see if there's a matching key we can displace */
klist = keyring->payload.subscriptions;

klist = rcu_dereference_locked_keyring(keyring);
if (klist && klist->nkeys > 0) {
struct key_type *type = key->type;

Expand Down Expand Up @@ -765,8 +768,6 @@ int __key_link(struct key *keyring, struct key *key)
if (ret < 0)
goto error2;

klist = keyring->payload.subscriptions;

if (klist && klist->nkeys < klist->maxkeys) {
/* there's sufficient slack space to add directly */
atomic_inc(&key->usage);
Expand Down Expand Up @@ -868,7 +869,7 @@ int key_unlink(struct key *keyring, struct key *key)

down_write(&keyring->sem);

klist = keyring->payload.subscriptions;
klist = rcu_dereference_locked_keyring(keyring);
if (klist) {
/* search the keyring for the key */
for (loop = 0; loop < klist->nkeys; loop++)
Expand Down Expand Up @@ -959,7 +960,7 @@ int keyring_clear(struct key *keyring)
/* detach the pointer block with the locks held */
down_write(&keyring->sem);

klist = keyring->payload.subscriptions;
klist = rcu_dereference_locked_keyring(keyring);
if (klist) {
/* adjust the quota */
key_payload_reserve(keyring,
Expand Down Expand Up @@ -991,7 +992,9 @@ EXPORT_SYMBOL(keyring_clear);
*/
static void keyring_revoke(struct key *keyring)
{
struct keyring_list *klist = keyring->payload.subscriptions;
struct keyring_list *klist;

klist = rcu_dereference_locked_keyring(keyring);

/* adjust the quota */
key_payload_reserve(keyring, 0);
Expand Down Expand Up @@ -1025,7 +1028,7 @@ void keyring_gc(struct key *keyring, time_t limit)

down_write(&keyring->sem);

klist = keyring->payload.subscriptions;
klist = rcu_dereference_locked_keyring(keyring);
if (!klist)
goto no_klist;

Expand Down

0 comments on commit 299a550

Please sign in to comment.