Skip to content

Commit

Permalink
KEYS: refcount bug fix
Browse files Browse the repository at this point in the history
This patch fixes the key_ref leak, removes the unnecessary KEY_FLAG_KEEP
test before setting the flag, and cleans up the if/then brackets style
introduced in commit:
d3600bc KEYS: prevent keys from being removed from specified keyrings

Reported-by: David Howells <[email protected]>
Signed-off-by: Mimi Zohar <[email protected]>
Acked-by: David Howells <[email protected]>
  • Loading branch information
Mimi Zohar committed Jan 7, 2016
1 parent 6427e6c commit 1d6d167
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
3 changes: 1 addition & 2 deletions security/keys/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,7 @@ static int __key_instantiate_and_link(struct key *key,

/* and link it into the destination keyring */
if (keyring) {
if (test_bit(KEY_FLAG_KEEP, &keyring->flags))
set_bit(KEY_FLAG_KEEP, &key->flags);
set_bit(KEY_FLAG_KEEP, &key->flags);

__key_link(key, _edit);
}
Expand Down
17 changes: 7 additions & 10 deletions security/keys/keyctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,11 @@ long keyctl_revoke_key(key_serial_t id)
}

key = key_ref_to_ptr(key_ref);
ret = 0;
if (test_bit(KEY_FLAG_KEEP, &key->flags))
return -EPERM;
else {
ret = -EPERM;
else
key_revoke(key);
ret = 0;
}

key_ref_put(key_ref);
error:
Expand Down Expand Up @@ -432,12 +431,11 @@ long keyctl_invalidate_key(key_serial_t id)

invalidate:
key = key_ref_to_ptr(key_ref);
ret = 0;
if (test_bit(KEY_FLAG_KEEP, &key->flags))
ret = -EPERM;
else {
else
key_invalidate(key);
ret = 0;
}
error_put:
key_ref_put(key_ref);
error:
Expand Down Expand Up @@ -1352,12 +1350,11 @@ long keyctl_set_timeout(key_serial_t id, unsigned timeout)

okay:
key = key_ref_to_ptr(key_ref);
ret = 0;
if (test_bit(KEY_FLAG_KEEP, &key->flags))
ret = -EPERM;
else {
else
key_set_timeout(key, timeout);
ret = 0;
}
key_put(key);

error:
Expand Down

0 comments on commit 1d6d167

Please sign in to comment.