Skip to content

Commit

Permalink
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/jmorris/security-testing-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6:
  KEYS: Fix RCU handling in key_gc_keyring()
  KEYS: Fix an RCU warning in the reading of user keys
  • Loading branch information
Linus Torvalds committed May 5, 2010
2 parents 7572e56 + cf8304e commit 67bff7c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions security/keys/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ static bool key_gc_keyring(struct key *keyring, time_t limit)
goto dont_gc;

/* scan the keyring looking for dead keys */
klist = rcu_dereference_check(keyring->payload.subscriptions,
lockdep_is_held(&key_serial_lock));
rcu_read_lock();
klist = rcu_dereference(keyring->payload.subscriptions);
if (!klist)
goto dont_gc;
goto unlock_dont_gc;

for (loop = klist->nkeys - 1; loop >= 0; loop--) {
key = klist->keys[loop];
Expand All @@ -89,11 +89,14 @@ static bool key_gc_keyring(struct key *keyring, time_t limit)
goto do_gc;
}

unlock_dont_gc:
rcu_read_unlock();
dont_gc:
kleave(" = false");
return false;

do_gc:
rcu_read_unlock();
key_gc_cursor = keyring->serial;
key_get(keyring);
spin_unlock(&key_serial_lock);
Expand Down
3 changes: 2 additions & 1 deletion security/keys/user_defined.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ long user_read(const struct key *key, char __user *buffer, size_t buflen)
struct user_key_payload *upayload;
long ret;

upayload = rcu_dereference(key->payload.data);
upayload = rcu_dereference_protected(
key->payload.data, rwsem_is_locked(&((struct key *)key)->sem));
ret = upayload->datalen;

/* we can return the data as is */
Expand Down

0 comments on commit 67bff7c

Please sign in to comment.