Skip to content

Commit

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

Pull key handling bugfix from James Morris:
 "Fix a race between keyctl_read() and keyctl_revoke()"

* 'for-linus2' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
  KEYS: Fix race between read and revoke
  • Loading branch information
Linus Torvalds committed Dec 28, 2015
2 parents 74bf8ef + b4a1b4f commit 2c7143d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions security/keys/keyctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,16 +751,16 @@ long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)

/* the key is probably readable - now try to read it */
can_read_key:
ret = key_validate(key);
if (ret == 0) {
ret = -EOPNOTSUPP;
if (key->type->read) {
/* read the data with the semaphore held (since we
* might sleep) */
down_read(&key->sem);
ret = -EOPNOTSUPP;
if (key->type->read) {
/* Read the data with the semaphore held (since we might sleep)
* to protect against the key being updated or revoked.
*/
down_read(&key->sem);
ret = key_validate(key);
if (ret == 0)
ret = key->type->read(key, buffer, buflen);
up_read(&key->sem);
}
up_read(&key->sem);
}

error2:
Expand Down

0 comments on commit 2c7143d

Please sign in to comment.