security/keys: use kvfree_sensitive()
authorDenis Efremov <efremov@linux.com>
Thu, 27 Aug 2020 07:29:23 +0000 (10:29 +0300)
committerDavid Howells <dhowells@redhat.com>
Thu, 21 Jan 2021 16:16:09 +0000 (16:16 +0000)
Use kvfree_sensitive() instead of open-coding it.

Signed-off-by: Denis Efremov <efremov@linux.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Reviewed-by: Ben Boeckel <mathstuf@gmail.com>
security/keys/big_key.c

index 691347d..d17e5f0 100644 (file)
@@ -121,8 +121,7 @@ int big_key_preparse(struct key_preparsed_payload *prep)
                *path = file->f_path;
                path_get(path);
                fput(file);
-               memzero_explicit(buf, enclen);
-               kvfree(buf);
+               kvfree_sensitive(buf, enclen);
        } else {
                /* Just store the data in a buffer */
                void *data = kmalloc(datalen, GFP_KERNEL);
@@ -140,8 +139,7 @@ err_fput:
 err_enckey:
        kfree_sensitive(enckey);
 error:
-       memzero_explicit(buf, enclen);
-       kvfree(buf);
+       kvfree_sensitive(buf, enclen);
        return ret;
 }
 
@@ -273,8 +271,7 @@ long big_key_read(const struct key *key, char *buffer, size_t buflen)
 err_fput:
                fput(file);
 error:
-               memzero_explicit(buf, enclen);
-               kvfree(buf);
+               kvfree_sensitive(buf, enclen);
        } else {
                ret = datalen;
                memcpy(buffer, key->payload.data[big_key_data], datalen);