Skip to content

Commit

Permalink
KEYS: Authorise keyctl_set_timeout() on a key if we have its authoris…
Browse files Browse the repository at this point in the history
…ation key

Authorise a process to perform keyctl_set_timeout() on an uninstantiated key if
that process has the authorisation key for it.

This allows the instantiator to set the timeout on a key it is instantiating -
provided it does it before instantiating the key.

For instance, the test upcall script provided with the keyutils package could
be modified to set the expiry to an hour hence before instantiating the key:

	[/usr/share/keyutils/request-key-debug.sh]
	 if [ "$3" != "neg" ]
	 then
	+    keyctl timeout $1 3600
	     keyctl instantiate $1 "Debug $3" $4 || exit 1
	 else

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
  • Loading branch information
David Howells authored and James Morris committed Aug 2, 2010
1 parent 57c2590 commit 9156235
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion security/keys/keyctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1091,18 +1091,33 @@ long keyctl_set_reqkey_keyring(int reqkey_defl)
long keyctl_set_timeout(key_serial_t id, unsigned timeout)
{
struct timespec now;
struct key *key;
struct key *key, *instkey;
key_ref_t key_ref;
time_t expiry;
long ret;

key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL,
KEY_SETATTR);
if (IS_ERR(key_ref)) {
/* setting the timeout on a key under construction is permitted
* if we have the authorisation token handy */
if (PTR_ERR(key_ref) == -EACCES) {
instkey = key_get_instantiation_authkey(id);
if (!IS_ERR(instkey)) {
key_put(instkey);
key_ref = lookup_user_key(id,
KEY_LOOKUP_PARTIAL,
0);
if (!IS_ERR(key_ref))
goto okay;
}
}

ret = PTR_ERR(key_ref);
goto error;
}

okay:
key = key_ref_to_ptr(key_ref);

/* make the changes with the locks held to prevent races */
Expand Down

0 comments on commit 9156235

Please sign in to comment.