Commit 7df036ef authored by Eric Biggers's avatar Eric Biggers Committed by David Howells

KEYS: sanitize add_key() and keyctl() key payloads

Before returning from add_key() or one of the keyctl() commands that
takes in a key payload, zero the temporary buffer that was allocated to
hold the key payload copied from userspace.  This may contain sensitive
key material that should not be kept around in the slab caches.
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
parent dcedad31
...@@ -132,7 +132,10 @@ SYSCALL_DEFINE5(add_key, const char __user *, _type, ...@@ -132,7 +132,10 @@ SYSCALL_DEFINE5(add_key, const char __user *, _type,
key_ref_put(keyring_ref); key_ref_put(keyring_ref);
error3: error3:
if (payload) {
memzero_explicit(payload, plen);
kvfree(payload); kvfree(payload);
}
error2: error2:
kfree(description); kfree(description);
error: error:
...@@ -347,7 +350,7 @@ long keyctl_update_key(key_serial_t id, ...@@ -347,7 +350,7 @@ long keyctl_update_key(key_serial_t id,
key_ref_put(key_ref); key_ref_put(key_ref);
error2: error2:
kfree(payload); kzfree(payload);
error: error:
return ret; return ret;
} }
...@@ -1093,7 +1096,10 @@ long keyctl_instantiate_key_common(key_serial_t id, ...@@ -1093,7 +1096,10 @@ long keyctl_instantiate_key_common(key_serial_t id,
keyctl_change_reqkey_auth(NULL); keyctl_change_reqkey_auth(NULL);
error2: error2:
if (payload) {
memzero_explicit(payload, plen);
kvfree(payload); kvfree(payload);
}
error: error:
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment