KEYS: Fix UID check in keyctl_get_persistent()
authorDavid Howells <dhowells@redhat.com>
Wed, 6 Nov 2013 14:01:51 +0000 (14:01 +0000)
committerDavid Howells <dhowells@redhat.com>
Wed, 6 Nov 2013 14:01:51 +0000 (14:01 +0000)
commitfbf8c53f1a2ac7610ed124043600dc074992e71b
treef0a6e0226507a85389737e650879aa6ee0dfe4ad
parentdbed71416332d24e4e9ba26dcf90cd86a93c06f1
KEYS: Fix UID check in keyctl_get_persistent()

If the UID is specified by userspace when calling the KEYCTL_GET_PERSISTENT
function and the process does not have the CAP_SETUID capability, then the
function will return -EPERM if the current process's uid, suid, euid and fsuid
all match the requested UID.  This is incorrect.

Fix it such that when a non-privileged caller requests a persistent keyring by
a specific UID they can only request their own (ie. the specified UID matches
either then process's UID or the process's EUID).

This can be tested by logging in as the user and doing:

keyctl get_persistent @p
keyctl get_persistent @p `id -u`
keyctl get_persistent @p 0

The first two should successfully print the same key ID.  The third should do
the same if called by UID 0 or indicate Operation Not Permitted otherwise.

Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Stephen Gallagher <sgallagh@redhat.com>
security/keys/persistent.c