For keys stored in shmem only the ChaCha20-Poly1305 key is reachable here,
so wiping it is enough to render the payload unreadable.

Used by CONFIG_CRASH_WIPE_SECRETS.

Signed-off-by: Jan Sebastian Götte <[email protected]>
---
 security/keys/big_key.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/security/keys/big_key.c b/security/keys/big_key.c
index 268f702df380..c01a212bec90 100644
--- a/security/keys/big_key.c
+++ b/security/keys/big_key.c
@@ -8,6 +8,7 @@
 
 #define pr_fmt(fmt) "big_key: "fmt
 #include <linux/init.h>
+#include <linux/crash_core.h>
 #include <linux/seq_file.h>
 #include <linux/file.h>
 #include <linux/shmem_fs.h>
@@ -35,6 +36,8 @@ struct big_key_payload {
  */
 #define BIG_KEY_FILE_THRESHOLD (sizeof(struct inode) + sizeof(struct dentry))
 
+static void big_key_wipe(struct key *key);
+
 /*
  * big_key defined keys take an arbitrary string as the description and an
  * arbitrary blob of data as the payload
@@ -46,6 +49,7 @@ struct key_type key_type_big_key = {
        .instantiate            = generic_key_instantiate,
        .revoke                 = big_key_revoke,
        .destroy                = big_key_destroy,
+       .wipe                   = big_key_wipe,
        .describe               = big_key_describe,
        .read                   = big_key_read,
        .update                 = big_key_update,
@@ -279,6 +283,19 @@ long big_key_read(const struct key *key, char *buffer, 
size_t buflen)
        return ret;
 }
 
+static void big_key_wipe(struct key *key)
+{
+       struct big_key_payload *payload = to_big_key_payload(key->payload);
+
+       if (payload->data) {
+               if (payload->length > BIG_KEY_FILE_THRESHOLD)
+                       crash_wipe_memzero(payload->data,
+                                          CHACHA20POLY1305_KEY_SIZE);
+               else
+                       crash_wipe_memzero(payload->data, payload->length);
+       }
+}
+
 /*
  * Register key type
  */

-- 
2.53.0


Reply via email to