blob: d173236b23eda4fdfdf1dae0ed3baa0b9e30746c [file] [log] [blame]
Jaegeuk Kime6b120d2017-07-10 12:55:09 -07001/*
Dave Chinner16179292017-10-09 12:15:34 -07002 * fscrypt.h: declarations for per-file encryption
3 *
Chandan Rajendra3ce5fa32018-12-12 15:20:12 +05304 * Filesystems that implement per-file encryption must include this header
5 * file.
Jaegeuk Kime6b120d2017-07-10 12:55:09 -07006 *
7 * Copyright (C) 2015, Google, Inc.
8 *
9 * Written by Michael Halcrow, 2015.
10 * Modified by Jaegeuk Kim, 2015.
11 */
Dave Chinner16179292017-10-09 12:15:34 -070012#ifndef _LINUX_FSCRYPT_H
13#define _LINUX_FSCRYPT_H
Jaegeuk Kime6b120d2017-07-10 12:55:09 -070014
Jaegeuk Kime6b120d2017-07-10 12:55:09 -070015#include <linux/fs.h>
Chandan Rajendra3ce5fa32018-12-12 15:20:12 +053016#include <linux/mm.h>
17#include <linux/slab.h>
Jaegeuk Kime6b120d2017-07-10 12:55:09 -070018
19#define FS_CRYPTO_BLOCK_SIZE 16
20
Eric Biggersf0c472b2018-01-05 10:44:55 -080021struct fscrypt_ctx;
Jaegeuk Kime6b120d2017-07-10 12:55:09 -070022struct fscrypt_info;
23
Jaegeuk Kime6b120d2017-07-10 12:55:09 -070024struct fscrypt_str {
25 unsigned char *name;
26 u32 len;
27};
28
29struct fscrypt_name {
30 const struct qstr *usr_fname;
31 struct fscrypt_str disk_name;
32 u32 hash;
33 u32 minor_hash;
34 struct fscrypt_str crypto_buf;
35};
36
37#define FSTR_INIT(n, l) { .name = n, .len = l }
38#define FSTR_TO_QSTR(f) QSTR_INIT((f)->name, (f)->len)
39#define fname_name(p) ((p)->disk_name.name)
40#define fname_len(p) ((p)->disk_name.len)
41
Chandan Rajendra3ce5fa32018-12-12 15:20:12 +053042#ifdef CONFIG_FS_ENCRYPTION
43/*
44 * fscrypt superblock flags
45 */
46#define FS_CFLG_OWN_PAGES (1U << 1)
47
48/*
49 * crypto operations for filesystems
50 */
51struct fscrypt_operations {
52 unsigned int flags;
53 const char *key_prefix;
54 int (*get_context)(struct inode *, void *, size_t);
55 int (*set_context)(struct inode *, const void *, size_t, void *);
56 bool (*dummy_context)(struct inode *);
57 bool (*empty_dir)(struct inode *);
58 unsigned int max_namelen;
59};
60
61struct fscrypt_ctx {
62 union {
63 struct {
64 struct page *bounce_page; /* Ciphertext page */
65 struct page *control_page; /* Original page */
66 } w;
67 struct {
68 struct bio *bio;
69 struct work_struct work;
70 } r;
71 struct list_head free_list; /* Free list */
72 };
73 u8 flags; /* Flags */
74};
75
76static inline bool fscrypt_has_encryption_key(const struct inode *inode)
77{
78 return (inode->i_crypt_info != NULL);
79}
80
81static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
82{
83 return inode->i_sb->s_cop->dummy_context &&
84 inode->i_sb->s_cop->dummy_context(inode);
85}
86
87/* crypto.c */
88extern void fscrypt_enqueue_decrypt_work(struct work_struct *);
Eric Biggers0db29a12019-03-18 10:23:33 -070089extern struct fscrypt_ctx *fscrypt_get_ctx(gfp_t);
Chandan Rajendra3ce5fa32018-12-12 15:20:12 +053090extern void fscrypt_release_ctx(struct fscrypt_ctx *);
91extern struct page *fscrypt_encrypt_page(const struct inode *, struct page *,
92 unsigned int, unsigned int,
93 u64, gfp_t);
94extern int fscrypt_decrypt_page(const struct inode *, struct page *, unsigned int,
95 unsigned int, u64);
96
97static inline struct page *fscrypt_control_page(struct page *page)
98{
99 return ((struct fscrypt_ctx *)page_private(page))->w.control_page;
100}
101
102extern void fscrypt_restore_control_page(struct page *);
103
104/* policy.c */
105extern int fscrypt_ioctl_set_policy(struct file *, const void __user *);
106extern int fscrypt_ioctl_get_policy(struct file *, void __user *);
107extern int fscrypt_has_permitted_context(struct inode *, struct inode *);
108extern int fscrypt_inherit_context(struct inode *, struct inode *,
109 void *, bool);
110/* keyinfo.c */
111extern int fscrypt_get_encryption_info(struct inode *);
112extern void fscrypt_put_encryption_info(struct inode *);
113
114/* fname.c */
115extern int fscrypt_setup_filename(struct inode *, const struct qstr *,
116 int lookup, struct fscrypt_name *);
117
118static inline void fscrypt_free_filename(struct fscrypt_name *fname)
119{
120 kfree(fname->crypto_buf.name);
121}
122
123extern int fscrypt_fname_alloc_buffer(const struct inode *, u32,
124 struct fscrypt_str *);
125extern void fscrypt_fname_free_buffer(struct fscrypt_str *);
126extern int fscrypt_fname_disk_to_usr(struct inode *, u32, u32,
127 const struct fscrypt_str *, struct fscrypt_str *);
128
129#define FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE 32
130
131/* Extracts the second-to-last ciphertext block; see explanation below */
132#define FSCRYPT_FNAME_DIGEST(name, len) \
133 ((name) + round_down((len) - FS_CRYPTO_BLOCK_SIZE - 1, \
134 FS_CRYPTO_BLOCK_SIZE))
135
136#define FSCRYPT_FNAME_DIGEST_SIZE FS_CRYPTO_BLOCK_SIZE
137
138/**
139 * fscrypt_digested_name - alternate identifier for an on-disk filename
140 *
141 * When userspace lists an encrypted directory without access to the key,
142 * filenames whose ciphertext is longer than FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE
143 * bytes are shown in this abbreviated form (base64-encoded) rather than as the
144 * full ciphertext (base64-encoded). This is necessary to allow supporting
145 * filenames up to NAME_MAX bytes, since base64 encoding expands the length.
146 *
147 * To make it possible for filesystems to still find the correct directory entry
148 * despite not knowing the full on-disk name, we encode any filesystem-specific
149 * 'hash' and/or 'minor_hash' which the filesystem may need for its lookups,
150 * followed by the second-to-last ciphertext block of the filename. Due to the
151 * use of the CBC-CTS encryption mode, the second-to-last ciphertext block
152 * depends on the full plaintext. (Note that ciphertext stealing causes the
153 * last two blocks to appear "flipped".) This makes accidental collisions very
154 * unlikely: just a 1 in 2^128 chance for two filenames to collide even if they
155 * share the same filesystem-specific hashes.
156 *
157 * However, this scheme isn't immune to intentional collisions, which can be
158 * created by anyone able to create arbitrary plaintext filenames and view them
159 * without the key. Making the "digest" be a real cryptographic hash like
160 * SHA-256 over the full ciphertext would prevent this, although it would be
161 * less efficient and harder to implement, especially since the filesystem would
162 * need to calculate it for each directory entry examined during a search.
163 */
164struct fscrypt_digested_name {
165 u32 hash;
166 u32 minor_hash;
167 u8 digest[FSCRYPT_FNAME_DIGEST_SIZE];
168};
169
170/**
171 * fscrypt_match_name() - test whether the given name matches a directory entry
172 * @fname: the name being searched for
173 * @de_name: the name from the directory entry
174 * @de_name_len: the length of @de_name in bytes
175 *
176 * Normally @fname->disk_name will be set, and in that case we simply compare
177 * that to the name stored in the directory entry. The only exception is that
178 * if we don't have the key for an encrypted directory and a filename in it is
179 * very long, then we won't have the full disk_name and we'll instead need to
180 * match against the fscrypt_digested_name.
181 *
182 * Return: %true if the name matches, otherwise %false.
183 */
184static inline bool fscrypt_match_name(const struct fscrypt_name *fname,
185 const u8 *de_name, u32 de_name_len)
186{
187 if (unlikely(!fname->disk_name.name)) {
188 const struct fscrypt_digested_name *n =
189 (const void *)fname->crypto_buf.name;
190 if (WARN_ON_ONCE(fname->usr_fname->name[0] != '_'))
191 return false;
192 if (de_name_len <= FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE)
193 return false;
194 return !memcmp(FSCRYPT_FNAME_DIGEST(de_name, de_name_len),
195 n->digest, FSCRYPT_FNAME_DIGEST_SIZE);
196 }
197
198 if (de_name_len != fname->disk_name.len)
199 return false;
200 return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len);
201}
202
203/* bio.c */
204extern void fscrypt_decrypt_bio(struct bio *);
205extern void fscrypt_enqueue_decrypt_bio(struct fscrypt_ctx *ctx,
206 struct bio *bio);
207extern void fscrypt_pullback_bio_page(struct page **, bool);
208extern int fscrypt_zeroout_range(const struct inode *, pgoff_t, sector_t,
209 unsigned int);
210
211/* hooks.c */
212extern int fscrypt_file_open(struct inode *inode, struct file *filp);
213extern int __fscrypt_prepare_link(struct inode *inode, struct inode *dir);
214extern int __fscrypt_prepare_rename(struct inode *old_dir,
215 struct dentry *old_dentry,
216 struct inode *new_dir,
217 struct dentry *new_dentry,
218 unsigned int flags);
219extern int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry);
220extern int __fscrypt_prepare_symlink(struct inode *dir, unsigned int len,
221 unsigned int max_len,
222 struct fscrypt_str *disk_link);
223extern int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
224 unsigned int len,
225 struct fscrypt_str *disk_link);
226extern const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
227 unsigned int max_size,
228 struct delayed_call *done);
229#else /* !CONFIG_FS_ENCRYPTION */
230
231static inline bool fscrypt_has_encryption_key(const struct inode *inode)
232{
233 return false;
234}
235
236static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
237{
238 return false;
239}
240
241/* crypto.c */
242static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work)
243{
244}
245
Eric Biggers0db29a12019-03-18 10:23:33 -0700246static inline struct fscrypt_ctx *fscrypt_get_ctx(gfp_t gfp_flags)
Chandan Rajendra3ce5fa32018-12-12 15:20:12 +0530247{
248 return ERR_PTR(-EOPNOTSUPP);
249}
250
251static inline void fscrypt_release_ctx(struct fscrypt_ctx *ctx)
252{
253 return;
254}
255
256static inline struct page *fscrypt_encrypt_page(const struct inode *inode,
257 struct page *page,
258 unsigned int len,
259 unsigned int offs,
260 u64 lblk_num, gfp_t gfp_flags)
261{
262 return ERR_PTR(-EOPNOTSUPP);
263}
264
265static inline int fscrypt_decrypt_page(const struct inode *inode,
266 struct page *page,
267 unsigned int len, unsigned int offs,
268 u64 lblk_num)
269{
270 return -EOPNOTSUPP;
271}
272
273static inline struct page *fscrypt_control_page(struct page *page)
274{
275 WARN_ON_ONCE(1);
276 return ERR_PTR(-EINVAL);
277}
278
279static inline void fscrypt_restore_control_page(struct page *page)
280{
281 return;
282}
283
284/* policy.c */
285static inline int fscrypt_ioctl_set_policy(struct file *filp,
286 const void __user *arg)
287{
288 return -EOPNOTSUPP;
289}
290
291static inline int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg)
292{
293 return -EOPNOTSUPP;
294}
295
296static inline int fscrypt_has_permitted_context(struct inode *parent,
297 struct inode *child)
298{
299 return 0;
300}
301
302static inline int fscrypt_inherit_context(struct inode *parent,
303 struct inode *child,
304 void *fs_data, bool preload)
305{
306 return -EOPNOTSUPP;
307}
308
309/* keyinfo.c */
310static inline int fscrypt_get_encryption_info(struct inode *inode)
311{
312 return -EOPNOTSUPP;
313}
314
315static inline void fscrypt_put_encryption_info(struct inode *inode)
316{
317 return;
318}
319
320 /* fname.c */
321static inline int fscrypt_setup_filename(struct inode *dir,
322 const struct qstr *iname,
323 int lookup, struct fscrypt_name *fname)
324{
325 if (IS_ENCRYPTED(dir))
326 return -EOPNOTSUPP;
327
328 memset(fname, 0, sizeof(struct fscrypt_name));
329 fname->usr_fname = iname;
330 fname->disk_name.name = (unsigned char *)iname->name;
331 fname->disk_name.len = iname->len;
332 return 0;
333}
334
335static inline void fscrypt_free_filename(struct fscrypt_name *fname)
336{
337 return;
338}
339
340static inline int fscrypt_fname_alloc_buffer(const struct inode *inode,
341 u32 max_encrypted_len,
342 struct fscrypt_str *crypto_str)
343{
344 return -EOPNOTSUPP;
345}
346
347static inline void fscrypt_fname_free_buffer(struct fscrypt_str *crypto_str)
348{
349 return;
350}
351
352static inline int fscrypt_fname_disk_to_usr(struct inode *inode,
353 u32 hash, u32 minor_hash,
354 const struct fscrypt_str *iname,
355 struct fscrypt_str *oname)
356{
357 return -EOPNOTSUPP;
358}
359
360static inline bool fscrypt_match_name(const struct fscrypt_name *fname,
361 const u8 *de_name, u32 de_name_len)
362{
363 /* Encryption support disabled; use standard comparison */
364 if (de_name_len != fname->disk_name.len)
365 return false;
366 return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len);
367}
368
369/* bio.c */
370static inline void fscrypt_decrypt_bio(struct bio *bio)
371{
372}
373
374static inline void fscrypt_enqueue_decrypt_bio(struct fscrypt_ctx *ctx,
375 struct bio *bio)
376{
377}
378
379static inline void fscrypt_pullback_bio_page(struct page **page, bool restore)
380{
381 return;
382}
383
384static inline int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
385 sector_t pblk, unsigned int len)
386{
387 return -EOPNOTSUPP;
388}
389
390/* hooks.c */
391
392static inline int fscrypt_file_open(struct inode *inode, struct file *filp)
393{
394 if (IS_ENCRYPTED(inode))
395 return -EOPNOTSUPP;
396 return 0;
397}
398
399static inline int __fscrypt_prepare_link(struct inode *inode,
400 struct inode *dir)
401{
402 return -EOPNOTSUPP;
403}
404
405static inline int __fscrypt_prepare_rename(struct inode *old_dir,
406 struct dentry *old_dentry,
407 struct inode *new_dir,
408 struct dentry *new_dentry,
409 unsigned int flags)
410{
411 return -EOPNOTSUPP;
412}
413
414static inline int __fscrypt_prepare_lookup(struct inode *dir,
415 struct dentry *dentry)
416{
417 return -EOPNOTSUPP;
418}
419
420static inline int __fscrypt_prepare_symlink(struct inode *dir,
421 unsigned int len,
422 unsigned int max_len,
423 struct fscrypt_str *disk_link)
424{
425 return -EOPNOTSUPP;
426}
427
428
429static inline int __fscrypt_encrypt_symlink(struct inode *inode,
430 const char *target,
431 unsigned int len,
432 struct fscrypt_str *disk_link)
433{
434 return -EOPNOTSUPP;
435}
436
437static inline const char *fscrypt_get_symlink(struct inode *inode,
438 const void *caddr,
439 unsigned int max_size,
440 struct delayed_call *done)
441{
442 return ERR_PTR(-EOPNOTSUPP);
443}
444#endif /* !CONFIG_FS_ENCRYPTION */
Dave Chinner16179292017-10-09 12:15:34 -0700445
Eric Biggers5190ed02017-10-09 12:15:39 -0700446/**
447 * fscrypt_require_key - require an inode's encryption key
448 * @inode: the inode we need the key for
449 *
450 * If the inode is encrypted, set up its encryption key if not already done.
451 * Then require that the key be present and return -ENOKEY otherwise.
452 *
453 * No locks are needed, and the key will live as long as the struct inode --- so
454 * it won't go away from under you.
455 *
456 * Return: 0 on success, -ENOKEY if the key is missing, or another -errno code
457 * if a problem occurred while setting up the encryption key.
458 */
459static inline int fscrypt_require_key(struct inode *inode)
460{
461 if (IS_ENCRYPTED(inode)) {
462 int err = fscrypt_get_encryption_info(inode);
463
464 if (err)
465 return err;
466 if (!fscrypt_has_encryption_key(inode))
467 return -ENOKEY;
468 }
469 return 0;
470}
Dave Chinner16179292017-10-09 12:15:34 -0700471
Eric Biggersf5218702017-10-09 12:15:41 -0700472/**
473 * fscrypt_prepare_link - prepare to link an inode into a possibly-encrypted directory
474 * @old_dentry: an existing dentry for the inode being linked
475 * @dir: the target directory
476 * @dentry: negative dentry for the target filename
477 *
478 * A new link can only be added to an encrypted directory if the directory's
479 * encryption key is available --- since otherwise we'd have no way to encrypt
480 * the filename. Therefore, we first set up the directory's encryption key (if
481 * not already done) and return an error if it's unavailable.
482 *
483 * We also verify that the link will not violate the constraint that all files
484 * in an encrypted directory tree use the same encryption policy.
485 *
486 * Return: 0 on success, -ENOKEY if the directory's encryption key is missing,
Eric Biggers15e483d2019-01-22 16:20:21 -0800487 * -EXDEV if the link would result in an inconsistent encryption policy, or
Eric Biggersf5218702017-10-09 12:15:41 -0700488 * another -errno code.
489 */
490static inline int fscrypt_prepare_link(struct dentry *old_dentry,
491 struct inode *dir,
492 struct dentry *dentry)
493{
494 if (IS_ENCRYPTED(dir))
495 return __fscrypt_prepare_link(d_inode(old_dentry), dir);
496 return 0;
497}
498
Eric Biggers98fe83a2017-10-09 12:15:42 -0700499/**
500 * fscrypt_prepare_rename - prepare for a rename between possibly-encrypted directories
501 * @old_dir: source directory
502 * @old_dentry: dentry for source file
503 * @new_dir: target directory
504 * @new_dentry: dentry for target location (may be negative unless exchanging)
505 * @flags: rename flags (we care at least about %RENAME_EXCHANGE)
506 *
507 * Prepare for ->rename() where the source and/or target directories may be
508 * encrypted. A new link can only be added to an encrypted directory if the
509 * directory's encryption key is available --- since otherwise we'd have no way
510 * to encrypt the filename. A rename to an existing name, on the other hand,
511 * *is* cryptographically possible without the key. However, we take the more
512 * conservative approach and just forbid all no-key renames.
513 *
514 * We also verify that the rename will not violate the constraint that all files
515 * in an encrypted directory tree use the same encryption policy.
516 *
Eric Biggers15e483d2019-01-22 16:20:21 -0800517 * Return: 0 on success, -ENOKEY if an encryption key is missing, -EXDEV if the
Eric Biggers98fe83a2017-10-09 12:15:42 -0700518 * rename would cause inconsistent encryption policies, or another -errno code.
519 */
520static inline int fscrypt_prepare_rename(struct inode *old_dir,
521 struct dentry *old_dentry,
522 struct inode *new_dir,
523 struct dentry *new_dentry,
524 unsigned int flags)
525{
526 if (IS_ENCRYPTED(old_dir) || IS_ENCRYPTED(new_dir))
527 return __fscrypt_prepare_rename(old_dir, old_dentry,
528 new_dir, new_dentry, flags);
529 return 0;
530}
531
Eric Biggersec822ff2017-10-09 12:15:43 -0700532/**
533 * fscrypt_prepare_lookup - prepare to lookup a name in a possibly-encrypted directory
534 * @dir: directory being searched
535 * @dentry: filename being looked up
536 * @flags: lookup flags
537 *
538 * Prepare for ->lookup() in a directory which may be encrypted. Lookups can be
539 * done with or without the directory's encryption key; without the key,
540 * filenames are presented in encrypted form. Therefore, we'll try to set up
541 * the directory's encryption key, but even without it the lookup can continue.
542 *
543 * To allow invalidating stale dentries if the directory's encryption key is
544 * added later, we also install a custom ->d_revalidate() method and use the
545 * DCACHE_ENCRYPTED_WITH_KEY flag to indicate whether a given dentry is a
546 * plaintext name (flag set) or a ciphertext name (flag cleared).
547 *
548 * Return: 0 on success, -errno if a problem occurred while setting up the
549 * encryption key
550 */
551static inline int fscrypt_prepare_lookup(struct inode *dir,
552 struct dentry *dentry,
553 unsigned int flags)
554{
555 if (IS_ENCRYPTED(dir))
556 return __fscrypt_prepare_lookup(dir, dentry);
557 return 0;
558}
559
Eric Biggers9e48a9f2017-10-09 12:15:44 -0700560/**
561 * fscrypt_prepare_setattr - prepare to change a possibly-encrypted inode's attributes
562 * @dentry: dentry through which the inode is being changed
563 * @attr: attributes to change
564 *
565 * Prepare for ->setattr() on a possibly-encrypted inode. On an encrypted file,
566 * most attribute changes are allowed even without the encryption key. However,
567 * without the encryption key we do have to forbid truncates. This is needed
568 * because the size being truncated to may not be a multiple of the filesystem
569 * block size, and in that case we'd have to decrypt the final block, zero the
570 * portion past i_size, and re-encrypt it. (We *could* allow truncating to a
571 * filesystem block boundary, but it's simpler to just forbid all truncates ---
572 * and we already forbid all other contents modifications without the key.)
573 *
574 * Return: 0 on success, -ENOKEY if the key is missing, or another -errno code
575 * if a problem occurred while setting up the encryption key.
576 */
577static inline int fscrypt_prepare_setattr(struct dentry *dentry,
578 struct iattr *attr)
579{
580 if (attr->ia_valid & ATTR_SIZE)
581 return fscrypt_require_key(d_inode(dentry));
582 return 0;
583}
584
Eric Biggersa7e05c72018-01-05 10:45:01 -0800585/**
586 * fscrypt_prepare_symlink - prepare to create a possibly-encrypted symlink
587 * @dir: directory in which the symlink is being created
588 * @target: plaintext symlink target
589 * @len: length of @target excluding null terminator
590 * @max_len: space the filesystem has available to store the symlink target
591 * @disk_link: (out) the on-disk symlink target being prepared
592 *
593 * This function computes the size the symlink target will require on-disk,
594 * stores it in @disk_link->len, and validates it against @max_len. An
595 * encrypted symlink may be longer than the original.
596 *
597 * Additionally, @disk_link->name is set to @target if the symlink will be
598 * unencrypted, but left NULL if the symlink will be encrypted. For encrypted
599 * symlinks, the filesystem must call fscrypt_encrypt_symlink() to create the
600 * on-disk target later. (The reason for the two-step process is that some
601 * filesystems need to know the size of the symlink target before creating the
602 * inode, e.g. to determine whether it will be a "fast" or "slow" symlink.)
603 *
604 * Return: 0 on success, -ENAMETOOLONG if the symlink target is too long,
605 * -ENOKEY if the encryption key is missing, or another -errno code if a problem
606 * occurred while setting up the encryption key.
607 */
608static inline int fscrypt_prepare_symlink(struct inode *dir,
609 const char *target,
610 unsigned int len,
611 unsigned int max_len,
612 struct fscrypt_str *disk_link)
613{
614 if (IS_ENCRYPTED(dir) || fscrypt_dummy_context_enabled(dir))
615 return __fscrypt_prepare_symlink(dir, len, max_len, disk_link);
616
617 disk_link->name = (unsigned char *)target;
618 disk_link->len = len + 1;
619 if (disk_link->len > max_len)
620 return -ENAMETOOLONG;
621 return 0;
622}
623
624/**
625 * fscrypt_encrypt_symlink - encrypt the symlink target if needed
626 * @inode: symlink inode
627 * @target: plaintext symlink target
628 * @len: length of @target excluding null terminator
629 * @disk_link: (in/out) the on-disk symlink target being prepared
630 *
631 * If the symlink target needs to be encrypted, then this function encrypts it
632 * into @disk_link->name. fscrypt_prepare_symlink() must have been called
633 * previously to compute @disk_link->len. If the filesystem did not allocate a
634 * buffer for @disk_link->name after calling fscrypt_prepare_link(), then one
635 * will be kmalloc()'ed and the filesystem will be responsible for freeing it.
636 *
637 * Return: 0 on success, -errno on failure
638 */
639static inline int fscrypt_encrypt_symlink(struct inode *inode,
640 const char *target,
641 unsigned int len,
642 struct fscrypt_str *disk_link)
643{
644 if (IS_ENCRYPTED(inode))
645 return __fscrypt_encrypt_symlink(inode, target, len, disk_link);
646 return 0;
647}
648
Dave Chinner16179292017-10-09 12:15:34 -0700649#endif /* _LINUX_FSCRYPT_H */