Lines Matching +full:data +full:- +full:path
1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 2017-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
16 #include <keys/user-type.h>
17 #include <keys/big_key-type.h>
24 u8 *data; member
25 struct path path; member
29 (struct big_key_payload *)((payload).data)
32 * If the data is under this limit, there's no point creating a shm file to
34 * least as large as the data.
40 * arbitrary blob of data as the payload
59 struct big_key_payload *payload = to_big_key_payload(prep->payload); in big_key_preparse()
63 size_t datalen = prep->datalen; in big_key_preparse()
67 BUILD_BUG_ON(sizeof(*payload) != sizeof(prep->payload.data)); in big_key_preparse()
69 if (datalen <= 0 || datalen > 1024 * 1024 || !prep->data) in big_key_preparse()
70 return -EINVAL; in big_key_preparse()
73 prep->quotalen = 16; in big_key_preparse()
75 payload->length = datalen; in big_key_preparse()
78 /* Create a shmem file to store the data in. This will permit the data in big_key_preparse()
83 * to zero, provided we never define a ->update() call. in big_key_preparse()
89 return -ENOMEM; in big_key_preparse()
94 ret = -ENOMEM; in big_key_preparse()
101 /* encrypt data */ in big_key_preparse()
102 chacha20poly1305_encrypt(buf, prep->data, datalen, NULL, 0, in big_key_preparse()
105 /* save aligned data to file */ in big_key_preparse()
116 ret = -EIO; in big_key_preparse()
123 payload->data = enckey; in big_key_preparse()
124 payload->path = file->f_path; in big_key_preparse()
125 path_get(&payload->path); in big_key_preparse()
129 /* Just store the data in a buffer */ in big_key_preparse()
130 void *data = kmalloc(datalen, GFP_KERNEL); in big_key_preparse() local
132 if (!data) in big_key_preparse()
133 return -ENOMEM; in big_key_preparse()
135 payload->data = data; in big_key_preparse()
136 memcpy(data, prep->data, prep->datalen); in big_key_preparse()
154 struct big_key_payload *payload = to_big_key_payload(prep->payload); in big_key_free_preparse()
156 if (prep->datalen > BIG_KEY_FILE_THRESHOLD) in big_key_free_preparse()
157 path_put(&payload->path); in big_key_free_preparse()
158 kfree_sensitive(payload->data); in big_key_free_preparse()
163 * - called with the key sem write-locked
167 struct big_key_payload *payload = to_big_key_payload(key->payload); in big_key_revoke()
171 if (key_is_positive(key) && payload->length > BIG_KEY_FILE_THRESHOLD) in big_key_revoke()
172 vfs_truncate(&payload->path, 0); in big_key_revoke()
176 * dispose of the data dangling from the corpse of a big_key key
180 struct big_key_payload *payload = to_big_key_payload(key->payload); in big_key_destroy()
182 if (payload->length > BIG_KEY_FILE_THRESHOLD) { in big_key_destroy()
183 path_put(&payload->path); in big_key_destroy()
184 payload->path.mnt = NULL; in big_key_destroy()
185 payload->path.dentry = NULL; in big_key_destroy()
187 kfree_sensitive(payload->data); in big_key_destroy()
188 payload->data = NULL; in big_key_destroy()
198 ret = key_payload_reserve(key, prep->datalen); in big_key_update()
213 struct big_key_payload *payload = to_big_key_payload(key->payload); in big_key_describe()
215 seq_puts(m, key->description); in big_key_describe()
219 payload->length, in big_key_describe()
220 payload->length > BIG_KEY_FILE_THRESHOLD ? "file" : "buff"); in big_key_describe()
224 * read the key data
225 * - the key's semaphore is read-locked
229 struct big_key_payload *payload = to_big_key_payload(key->payload); in big_key_read()
230 size_t datalen = payload->length; in big_key_read()
238 u8 *buf, *enckey = payload->data; in big_key_read()
244 return -ENOMEM; in big_key_read()
246 file = dentry_open(&payload->path, O_RDONLY, current_cred()); in big_key_read()
256 ret = -EIO; in big_key_read()
261 enckey) ? 0 : -EBADMSG; in big_key_read()
267 /* copy out decrypted data */ in big_key_read()
276 memcpy(buffer, payload->data, datalen); in big_key_read()