Skip to content

Commit

Permalink
keys: Fix request_key() lack of Link perm check on found key
Browse files Browse the repository at this point in the history
The request_key() syscall allows a process to gain access to the 'possessor'
permits of any key that grants it Search permission by virtue of request_key()
not checking whether a key it finds grants Link permission to the caller.

Signed-off-by: David Howells <dhowells@redhat.com>
  • Loading branch information
David Howells committed Jun 19, 2019
1 parent 45e0f30 commit 504b69e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Documentation/security/keys/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ The main syscalls are:
/sbin/request-key will be invoked in an attempt to obtain a key. The
callout_info string will be passed as an argument to the program.

To link a key into the destination keyring the key must grant link
permission on the key to the caller and the keyring must grant write
permission.

See also Documentation/security/keys/request-key.rst.


Expand Down
10 changes: 10 additions & 0 deletions security/keys/request_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,16 @@ struct key *request_key_and_link(struct key_type *type,
key_ref = search_process_keyrings(&ctx);

if (!IS_ERR(key_ref)) {
if (dest_keyring) {
ret = key_task_permission(key_ref, current_cred(),
KEY_NEED_LINK);
if (ret < 0) {
key_ref_put(key_ref);
key = ERR_PTR(ret);
goto error_free;
}
}

key = key_ref_to_ptr(key_ref);
if (dest_keyring) {
ret = key_link(dest_keyring, key);
Expand Down

0 comments on commit 504b69e

Please sign in to comment.