]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
KEYS: sanitize add_key() and keyctl() key payloads
authorEric Biggers <ebiggers@google.com>
Thu, 8 Jun 2017 13:48:57 +0000 (14:48 +0100)
committerJames Morris <james.l.morris@oracle.com>
Fri, 9 Jun 2017 03:29:48 +0000 (13:29 +1000)
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: Eric Biggers <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <james.l.morris@oracle.com>
security/keys/keyctl.c

index 94c2790f82839adb260dc2af00907c24c5f40826..ab0b337c84b4c02e4856719398edb94d1caf101a 100644 (file)
@@ -132,7 +132,10 @@ SYSCALL_DEFINE5(add_key, const char __user *, _type,
 
        key_ref_put(keyring_ref);
  error3:
-       kvfree(payload);
+       if (payload) {
+               memzero_explicit(payload, plen);
+               kvfree(payload);
+       }
  error2:
        kfree(description);
  error:
@@ -347,7 +350,7 @@ long keyctl_update_key(key_serial_t id,
 
        key_ref_put(key_ref);
 error2:
-       kfree(payload);
+       kzfree(payload);
 error:
        return ret;
 }
@@ -1093,7 +1096,10 @@ long keyctl_instantiate_key_common(key_serial_t id,
                keyctl_change_reqkey_auth(NULL);
 
 error2:
-       kvfree(payload);
+       if (payload) {
+               memzero_explicit(payload, plen);
+               kvfree(payload);
+       }
 error:
        return ret;
 }