blob: 62f13d533439564301e471af8dbe1c4eb331e64c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07002/*
3 * This contains functions for filename crypto management
4 *
5 * Copyright (C) 2015, Google, Inc.
6 * Copyright (C) 2015, Motorola Mobility
7 *
8 * Written by Uday Savagaonkar, 2014.
9 * Modified by Jaegeuk Kim, 2015.
10 *
11 * This has not yet undergone a rigorous security audit.
12 */
13
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070014#include <linux/scatterlist.h>
15#include <linux/ratelimit.h>
Eric Biggersa5757842018-01-05 10:45:00 -080016#include <crypto/skcipher.h>
Theodore Ts'o3325bea2016-11-26 20:32:46 -050017#include "fscrypt_private.h"
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070018
Eric Biggersdcf0db92018-01-05 10:44:59 -080019static inline bool fscrypt_is_dot_dotdot(const struct qstr *str)
20{
21 if (str->len == 1 && str->name[0] == '.')
22 return true;
23
24 if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.')
25 return true;
26
27 return false;
28}
29
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070030/**
Eric Biggersef1eb3a2016-09-15 17:25:55 -040031 * fname_encrypt() - encrypt a filename
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070032 *
Eric Biggersef1eb3a2016-09-15 17:25:55 -040033 * The caller must have allocated sufficient memory for the @oname string.
34 *
35 * Return: 0 on success, -errno on failure
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070036 */
Eric Biggers76e81d62018-01-05 10:45:01 -080037int fname_encrypt(struct inode *inode,
38 const struct qstr *iname, struct fscrypt_str *oname)
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070039{
Linus Torvaldsd4075742016-03-21 11:03:02 -070040 struct skcipher_request *req = NULL;
Gilad Ben-Yossefd0082e12017-10-18 08:00:44 +010041 DECLARE_CRYPTO_WAIT(wait);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070042 struct fscrypt_info *ci = inode->i_crypt_info;
Linus Torvaldsd4075742016-03-21 11:03:02 -070043 struct crypto_skcipher *tfm = ci->ci_ctfm;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070044 int res = 0;
45 char iv[FS_CRYPTO_BLOCK_SIZE];
Eric Biggers08ae8772016-11-13 20:35:52 -050046 struct scatterlist sg;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070047 int padding = 4 << (ci->ci_flags & FS_POLICY_FLAGS_PAD_MASK);
Eric Biggers08ae8772016-11-13 20:35:52 -050048 unsigned int lim;
49 unsigned int cryptlen;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070050
51 lim = inode->i_sb->s_cop->max_namelen(inode);
52 if (iname->len <= 0 || iname->len > lim)
53 return -EIO;
54
Eric Biggers08ae8772016-11-13 20:35:52 -050055 /*
56 * Copy the filename to the output buffer for encrypting in-place and
57 * pad it with the needed number of NUL bytes.
58 */
Eric Biggers76e81d62018-01-05 10:45:01 -080059 if (WARN_ON(oname->len < iname->len))
60 return -ENOBUFS;
Eric Biggers08ae8772016-11-13 20:35:52 -050061 cryptlen = max_t(unsigned int, iname->len, FS_CRYPTO_BLOCK_SIZE);
62 cryptlen = round_up(cryptlen, padding);
Eric Biggers76e81d62018-01-05 10:45:01 -080063 cryptlen = min3(cryptlen, lim, oname->len);
Eric Biggers08ae8772016-11-13 20:35:52 -050064 memcpy(oname->name, iname->name, iname->len);
65 memset(oname->name + iname->len, 0, cryptlen - iname->len);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070066
Eric Biggers08ae8772016-11-13 20:35:52 -050067 /* Initialize the IV */
68 memset(iv, 0, FS_CRYPTO_BLOCK_SIZE);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070069
Eric Biggers08ae8772016-11-13 20:35:52 -050070 /* Set up the encryption request */
Linus Torvaldsd4075742016-03-21 11:03:02 -070071 req = skcipher_request_alloc(tfm, GFP_NOFS);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070072 if (!req) {
73 printk_ratelimited(KERN_ERR
Eric Biggers08ae8772016-11-13 20:35:52 -050074 "%s: skcipher_request_alloc() failed\n", __func__);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070075 return -ENOMEM;
76 }
Linus Torvaldsd4075742016-03-21 11:03:02 -070077 skcipher_request_set_callback(req,
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070078 CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
Gilad Ben-Yossefd0082e12017-10-18 08:00:44 +010079 crypto_req_done, &wait);
Eric Biggers08ae8772016-11-13 20:35:52 -050080 sg_init_one(&sg, oname->name, cryptlen);
81 skcipher_request_set_crypt(req, &sg, &sg, cryptlen, iv);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070082
Eric Biggers08ae8772016-11-13 20:35:52 -050083 /* Do the encryption */
Gilad Ben-Yossefd0082e12017-10-18 08:00:44 +010084 res = crypto_wait_req(crypto_skcipher_encrypt(req), &wait);
Linus Torvaldsd4075742016-03-21 11:03:02 -070085 skcipher_request_free(req);
Eric Biggersef1eb3a2016-09-15 17:25:55 -040086 if (res < 0) {
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070087 printk_ratelimited(KERN_ERR
88 "%s: Error (error code %d)\n", __func__, res);
Eric Biggersef1eb3a2016-09-15 17:25:55 -040089 return res;
90 }
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070091
Eric Biggers08ae8772016-11-13 20:35:52 -050092 oname->len = cryptlen;
Eric Biggersef1eb3a2016-09-15 17:25:55 -040093 return 0;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -070094}
95
Eric Biggersef1eb3a2016-09-15 17:25:55 -040096/**
97 * fname_decrypt() - decrypt a filename
98 *
99 * The caller must have allocated sufficient memory for the @oname string.
100 *
101 * Return: 0 on success, -errno on failure
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700102 */
103static int fname_decrypt(struct inode *inode,
104 const struct fscrypt_str *iname,
105 struct fscrypt_str *oname)
106{
Linus Torvaldsd4075742016-03-21 11:03:02 -0700107 struct skcipher_request *req = NULL;
Gilad Ben-Yossefd0082e12017-10-18 08:00:44 +0100108 DECLARE_CRYPTO_WAIT(wait);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700109 struct scatterlist src_sg, dst_sg;
110 struct fscrypt_info *ci = inode->i_crypt_info;
Linus Torvaldsd4075742016-03-21 11:03:02 -0700111 struct crypto_skcipher *tfm = ci->ci_ctfm;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700112 int res = 0;
113 char iv[FS_CRYPTO_BLOCK_SIZE];
114 unsigned lim;
115
116 lim = inode->i_sb->s_cop->max_namelen(inode);
117 if (iname->len <= 0 || iname->len > lim)
118 return -EIO;
119
120 /* Allocate request */
Linus Torvaldsd4075742016-03-21 11:03:02 -0700121 req = skcipher_request_alloc(tfm, GFP_NOFS);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700122 if (!req) {
123 printk_ratelimited(KERN_ERR
124 "%s: crypto_request_alloc() failed\n", __func__);
125 return -ENOMEM;
126 }
Linus Torvaldsd4075742016-03-21 11:03:02 -0700127 skcipher_request_set_callback(req,
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700128 CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
Gilad Ben-Yossefd0082e12017-10-18 08:00:44 +0100129 crypto_req_done, &wait);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700130
131 /* Initialize IV */
132 memset(iv, 0, FS_CRYPTO_BLOCK_SIZE);
133
134 /* Create decryption request */
135 sg_init_one(&src_sg, iname->name, iname->len);
136 sg_init_one(&dst_sg, oname->name, oname->len);
Linus Torvaldsd4075742016-03-21 11:03:02 -0700137 skcipher_request_set_crypt(req, &src_sg, &dst_sg, iname->len, iv);
Gilad Ben-Yossefd0082e12017-10-18 08:00:44 +0100138 res = crypto_wait_req(crypto_skcipher_decrypt(req), &wait);
Linus Torvaldsd4075742016-03-21 11:03:02 -0700139 skcipher_request_free(req);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700140 if (res < 0) {
141 printk_ratelimited(KERN_ERR
142 "%s: Error (error code %d)\n", __func__, res);
143 return res;
144 }
145
146 oname->len = strnlen(oname->name, iname->len);
Eric Biggersef1eb3a2016-09-15 17:25:55 -0400147 return 0;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700148}
149
150static const char *lookup_table =
151 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
152
Eric Biggers17159422017-04-24 10:00:10 -0700153#define BASE64_CHARS(nbytes) DIV_ROUND_UP((nbytes) * 4, 3)
154
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700155/**
156 * digest_encode() -
157 *
158 * Encodes the input digest using characters from the set [a-zA-Z0-9_+].
159 * The encoded string is roughly 4/3 times the size of the input string.
160 */
161static int digest_encode(const char *src, int len, char *dst)
162{
163 int i = 0, bits = 0, ac = 0;
164 char *cp = dst;
165
166 while (i < len) {
167 ac += (((unsigned char) src[i]) << bits);
168 bits += 8;
169 do {
170 *cp++ = lookup_table[ac & 0x3f];
171 ac >>= 6;
172 bits -= 6;
173 } while (bits >= 6);
174 i++;
175 }
176 if (bits)
177 *cp++ = lookup_table[ac & 0x3f];
178 return cp - dst;
179}
180
181static int digest_decode(const char *src, int len, char *dst)
182{
183 int i = 0, bits = 0, ac = 0;
184 const char *p;
185 char *cp = dst;
186
187 while (i < len) {
188 p = strchr(lookup_table, src[i]);
189 if (p == NULL || src[i] == 0)
190 return -2;
191 ac += (p - lookup_table) << bits;
192 bits += 6;
193 if (bits >= 8) {
194 *cp++ = ac & 0xff;
195 ac >>= 8;
196 bits -= 8;
197 }
198 i++;
199 }
200 if (ac)
201 return -1;
202 return cp - dst;
203}
204
David Gstir0b93e1b2016-11-13 22:20:47 +0100205u32 fscrypt_fname_encrypted_size(const struct inode *inode, u32 ilen)
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700206{
207 int padding = 32;
208 struct fscrypt_info *ci = inode->i_crypt_info;
209
210 if (ci)
211 padding = 4 << (ci->ci_flags & FS_POLICY_FLAGS_PAD_MASK);
Eric Biggers55be3142016-09-30 01:46:18 -0400212 ilen = max(ilen, (u32)FS_CRYPTO_BLOCK_SIZE);
213 return round_up(ilen, padding);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700214}
215EXPORT_SYMBOL(fscrypt_fname_encrypted_size);
216
217/**
218 * fscrypt_fname_crypto_alloc_obuff() -
219 *
220 * Allocates an output buffer that is sufficient for the crypto operation
221 * specified by the context and the direction.
222 */
David Gstir0b93e1b2016-11-13 22:20:47 +0100223int fscrypt_fname_alloc_buffer(const struct inode *inode,
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700224 u32 ilen, struct fscrypt_str *crypto_str)
225{
Eric Biggers17159422017-04-24 10:00:10 -0700226 u32 olen = fscrypt_fname_encrypted_size(inode, ilen);
227 const u32 max_encoded_len =
228 max_t(u32, BASE64_CHARS(FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE),
229 1 + BASE64_CHARS(sizeof(struct fscrypt_digested_name)));
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700230
231 crypto_str->len = olen;
Eric Biggers17159422017-04-24 10:00:10 -0700232 olen = max(olen, max_encoded_len);
233
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700234 /*
235 * Allocated buffer can hold one more character to null-terminate the
236 * string
237 */
238 crypto_str->name = kmalloc(olen + 1, GFP_NOFS);
239 if (!(crypto_str->name))
240 return -ENOMEM;
241 return 0;
242}
243EXPORT_SYMBOL(fscrypt_fname_alloc_buffer);
244
245/**
246 * fscrypt_fname_crypto_free_buffer() -
247 *
248 * Frees the buffer allocated for crypto operation.
249 */
250void fscrypt_fname_free_buffer(struct fscrypt_str *crypto_str)
251{
252 if (!crypto_str)
253 return;
254 kfree(crypto_str->name);
255 crypto_str->name = NULL;
256}
257EXPORT_SYMBOL(fscrypt_fname_free_buffer);
258
259/**
260 * fscrypt_fname_disk_to_usr() - converts a filename from disk space to user
261 * space
Eric Biggersef1eb3a2016-09-15 17:25:55 -0400262 *
263 * The caller must have allocated sufficient memory for the @oname string.
264 *
Eric Biggers17159422017-04-24 10:00:10 -0700265 * If the key is available, we'll decrypt the disk name; otherwise, we'll encode
266 * it for presentation. Short names are directly base64-encoded, while long
267 * names are encoded in fscrypt_digested_name format.
268 *
Eric Biggersef1eb3a2016-09-15 17:25:55 -0400269 * Return: 0 on success, -errno on failure
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700270 */
271int fscrypt_fname_disk_to_usr(struct inode *inode,
272 u32 hash, u32 minor_hash,
273 const struct fscrypt_str *iname,
274 struct fscrypt_str *oname)
275{
276 const struct qstr qname = FSTR_TO_QSTR(iname);
Eric Biggers17159422017-04-24 10:00:10 -0700277 struct fscrypt_digested_name digested_name;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700278
279 if (fscrypt_is_dot_dotdot(&qname)) {
280 oname->name[0] = '.';
281 oname->name[iname->len - 1] = '.';
282 oname->len = iname->len;
Eric Biggersef1eb3a2016-09-15 17:25:55 -0400283 return 0;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700284 }
285
286 if (iname->len < FS_CRYPTO_BLOCK_SIZE)
287 return -EUCLEAN;
288
289 if (inode->i_crypt_info)
290 return fname_decrypt(inode, iname, oname);
291
Eric Biggers17159422017-04-24 10:00:10 -0700292 if (iname->len <= FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE) {
Eric Biggersef1eb3a2016-09-15 17:25:55 -0400293 oname->len = digest_encode(iname->name, iname->len,
294 oname->name);
295 return 0;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700296 }
297 if (hash) {
Eric Biggers17159422017-04-24 10:00:10 -0700298 digested_name.hash = hash;
299 digested_name.minor_hash = minor_hash;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700300 } else {
Eric Biggers17159422017-04-24 10:00:10 -0700301 digested_name.hash = 0;
302 digested_name.minor_hash = 0;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700303 }
Eric Biggers17159422017-04-24 10:00:10 -0700304 memcpy(digested_name.digest,
305 FSCRYPT_FNAME_DIGEST(iname->name, iname->len),
306 FSCRYPT_FNAME_DIGEST_SIZE);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700307 oname->name[0] = '_';
Eric Biggers17159422017-04-24 10:00:10 -0700308 oname->len = 1 + digest_encode((const char *)&digested_name,
309 sizeof(digested_name), oname->name + 1);
Eric Biggersef1eb3a2016-09-15 17:25:55 -0400310 return 0;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700311}
312EXPORT_SYMBOL(fscrypt_fname_disk_to_usr);
313
314/**
315 * fscrypt_fname_usr_to_disk() - converts a filename from user space to disk
316 * space
Eric Biggersef1eb3a2016-09-15 17:25:55 -0400317 *
318 * The caller must have allocated sufficient memory for the @oname string.
319 *
320 * Return: 0 on success, -errno on failure
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700321 */
322int fscrypt_fname_usr_to_disk(struct inode *inode,
323 const struct qstr *iname,
324 struct fscrypt_str *oname)
325{
326 if (fscrypt_is_dot_dotdot(iname)) {
327 oname->name[0] = '.';
328 oname->name[iname->len - 1] = '.';
329 oname->len = iname->len;
Eric Biggersef1eb3a2016-09-15 17:25:55 -0400330 return 0;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700331 }
332 if (inode->i_crypt_info)
333 return fname_encrypt(inode, iname, oname);
334 /*
335 * Without a proper key, a user is not allowed to modify the filenames
336 * in a directory. Consequently, a user space name cannot be mapped to
337 * a disk-space name
338 */
Eric Biggers54475f52016-12-05 11:12:44 -0800339 return -ENOKEY;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700340}
341EXPORT_SYMBOL(fscrypt_fname_usr_to_disk);
342
Eric Biggers17159422017-04-24 10:00:10 -0700343/**
344 * fscrypt_setup_filename() - prepare to search a possibly encrypted directory
345 * @dir: the directory that will be searched
346 * @iname: the user-provided filename being searched for
347 * @lookup: 1 if we're allowed to proceed without the key because it's
348 * ->lookup() or we're finding the dir_entry for deletion; 0 if we cannot
349 * proceed without the key because we're going to create the dir_entry.
350 * @fname: the filename information to be filled in
351 *
352 * Given a user-provided filename @iname, this function sets @fname->disk_name
353 * to the name that would be stored in the on-disk directory entry, if possible.
354 * If the directory is unencrypted this is simply @iname. Else, if we have the
355 * directory's encryption key, then @iname is the plaintext, so we encrypt it to
356 * get the disk_name.
357 *
358 * Else, for keyless @lookup operations, @iname is the presented ciphertext, so
359 * we decode it to get either the ciphertext disk_name (for short names) or the
360 * fscrypt_digested_name (for long names). Non-@lookup operations will be
361 * impossible in this case, so we fail them with ENOKEY.
362 *
363 * If successful, fscrypt_free_filename() must be called later to clean up.
364 *
365 * Return: 0 on success, -errno on failure
366 */
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700367int fscrypt_setup_filename(struct inode *dir, const struct qstr *iname,
368 int lookup, struct fscrypt_name *fname)
369{
Eric Biggers17159422017-04-24 10:00:10 -0700370 int ret;
371 int digested;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700372
373 memset(fname, 0, sizeof(struct fscrypt_name));
374 fname->usr_fname = iname;
375
Eric Biggerse0428a22017-10-09 12:15:36 -0700376 if (!IS_ENCRYPTED(dir) || fscrypt_is_dot_dotdot(iname)) {
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700377 fname->disk_name.name = (unsigned char *)iname->name;
378 fname->disk_name.len = iname->len;
379 return 0;
380 }
Eric Biggers1b53cf92017-02-21 15:07:11 -0800381 ret = fscrypt_get_encryption_info(dir);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700382 if (ret && ret != -EOPNOTSUPP)
383 return ret;
384
385 if (dir->i_crypt_info) {
386 ret = fscrypt_fname_alloc_buffer(dir, iname->len,
387 &fname->crypto_buf);
Eric Biggersef1eb3a2016-09-15 17:25:55 -0400388 if (ret)
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700389 return ret;
390 ret = fname_encrypt(dir, iname, &fname->crypto_buf);
Eric Biggersef1eb3a2016-09-15 17:25:55 -0400391 if (ret)
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700392 goto errout;
393 fname->disk_name.name = fname->crypto_buf.name;
394 fname->disk_name.len = fname->crypto_buf.len;
395 return 0;
396 }
397 if (!lookup)
Eric Biggers54475f52016-12-05 11:12:44 -0800398 return -ENOKEY;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700399
400 /*
401 * We don't have the key and we are doing a lookup; decode the
402 * user-supplied name
403 */
Eric Biggers17159422017-04-24 10:00:10 -0700404 if (iname->name[0] == '_') {
405 if (iname->len !=
406 1 + BASE64_CHARS(sizeof(struct fscrypt_digested_name)))
407 return -ENOENT;
408 digested = 1;
409 } else {
410 if (iname->len >
411 BASE64_CHARS(FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE))
412 return -ENOENT;
413 digested = 0;
414 }
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700415
Eric Biggers17159422017-04-24 10:00:10 -0700416 fname->crypto_buf.name =
417 kmalloc(max_t(size_t, FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE,
418 sizeof(struct fscrypt_digested_name)),
419 GFP_KERNEL);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700420 if (fname->crypto_buf.name == NULL)
421 return -ENOMEM;
422
Eric Biggers17159422017-04-24 10:00:10 -0700423 ret = digest_decode(iname->name + digested, iname->len - digested,
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700424 fname->crypto_buf.name);
425 if (ret < 0) {
426 ret = -ENOENT;
427 goto errout;
428 }
429 fname->crypto_buf.len = ret;
Eric Biggers17159422017-04-24 10:00:10 -0700430 if (digested) {
431 const struct fscrypt_digested_name *n =
432 (const void *)fname->crypto_buf.name;
433 fname->hash = n->hash;
434 fname->minor_hash = n->minor_hash;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700435 } else {
436 fname->disk_name.name = fname->crypto_buf.name;
437 fname->disk_name.len = fname->crypto_buf.len;
438 }
439 return 0;
440
441errout:
442 fscrypt_fname_free_buffer(&fname->crypto_buf);
443 return ret;
444}
445EXPORT_SYMBOL(fscrypt_setup_filename);