keys: Implement update for the big_key type
authorDavid Howells <dhowells@redhat.com>
Tue, 12 May 2020 13:03:53 +0000 (14:03 +0100)
committerDavid Howells <dhowells@redhat.com>
Tue, 2 Jun 2020 16:22:31 +0000 (17:22 +0100)
Implement the ->update op for the big_key type.

Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Jason A. Donenfeld <Jason@zx2c4.com>
include/keys/big_key-type.h
security/keys/big_key.c

index 3fee04f..988d90d 100644 (file)
@@ -18,5 +18,6 @@ extern void big_key_revoke(struct key *key);
 extern void big_key_destroy(struct key *key);
 extern void big_key_describe(const struct key *big_key, struct seq_file *m);
 extern long big_key_read(const struct key *key, char *buffer, size_t buflen);
+extern int big_key_update(struct key *key, struct key_preparsed_payload *prep);
 
 #endif /* _KEYS_BIG_KEY_TYPE_H */
index d43f3da..dd708e8 100644 (file)
@@ -47,7 +47,7 @@ struct key_type key_type_big_key = {
        .destroy                = big_key_destroy,
        .describe               = big_key_describe,
        .read                   = big_key_read,
-       /* no ->update(); don't add it without changing chacha20poly1305's nonce */
+       .update                 = big_key_update,
 };
 
 /*
@@ -191,6 +191,23 @@ void big_key_destroy(struct key *key)
        key->payload.data[big_key_data] = NULL;
 }
 
+/*
+ * Update a big key
+ */
+int big_key_update(struct key *key, struct key_preparsed_payload *prep)
+{
+       int ret;
+
+       ret = key_payload_reserve(key, prep->datalen);
+       if (ret < 0)
+               return ret;
+
+       if (key_is_positive(key))
+               big_key_destroy(key);
+
+       return generic_key_instantiate(key, prep);
+}
+
 /*
  * describe the big_key key
  */