Linus Torvalds | 32190f0 | 2017-11-14 11:35:15 -0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Eric Biggers | 46f47e4 | 2017-01-24 10:58:06 -0800 | [diff] [blame] | 2 | /* |
Dave Chinner | 734f0d2 | 2017-10-09 12:15:34 -0700 | [diff] [blame] | 3 | * fscrypt.h: declarations for per-file encryption |
| 4 | * |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 5 | * Filesystems that implement per-file encryption must include this header |
| 6 | * file. |
Eric Biggers | 46f47e4 | 2017-01-24 10:58:06 -0800 | [diff] [blame] | 7 | * |
| 8 | * Copyright (C) 2015, Google, Inc. |
| 9 | * |
| 10 | * Written by Michael Halcrow, 2015. |
| 11 | * Modified by Jaegeuk Kim, 2015. |
| 12 | */ |
Dave Chinner | 734f0d2 | 2017-10-09 12:15:34 -0700 | [diff] [blame] | 13 | #ifndef _LINUX_FSCRYPT_H |
| 14 | #define _LINUX_FSCRYPT_H |
Eric Biggers | 46f47e4 | 2017-01-24 10:58:06 -0800 | [diff] [blame] | 15 | |
Eric Biggers | 46f47e4 | 2017-01-24 10:58:06 -0800 | [diff] [blame] | 16 | #include <linux/fs.h> |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 17 | #include <linux/mm.h> |
| 18 | #include <linux/slab.h> |
Eric Biggers | a48b7ad | 2019-08-04 19:35:43 -0700 | [diff] [blame] | 19 | #include <uapi/linux/fscrypt.h> |
Eric Biggers | 46f47e4 | 2017-01-24 10:58:06 -0800 | [diff] [blame] | 20 | |
| 21 | #define FS_CRYPTO_BLOCK_SIZE 16 |
| 22 | |
| 23 | struct fscrypt_info; |
| 24 | |
Eric Biggers | 46f47e4 | 2017-01-24 10:58:06 -0800 | [diff] [blame] | 25 | struct fscrypt_str { |
| 26 | unsigned char *name; |
| 27 | u32 len; |
| 28 | }; |
| 29 | |
| 30 | struct fscrypt_name { |
| 31 | const struct qstr *usr_fname; |
| 32 | struct fscrypt_str disk_name; |
| 33 | u32 hash; |
| 34 | u32 minor_hash; |
| 35 | struct fscrypt_str crypto_buf; |
Eric Biggers | 716c370 | 2019-03-20 11:39:13 -0700 | [diff] [blame] | 36 | bool is_ciphertext_name; |
Eric Biggers | 46f47e4 | 2017-01-24 10:58:06 -0800 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | #define FSTR_INIT(n, l) { .name = n, .len = l } |
| 40 | #define FSTR_TO_QSTR(f) QSTR_INIT((f)->name, (f)->len) |
| 41 | #define fname_name(p) ((p)->disk_name.name) |
| 42 | #define fname_len(p) ((p)->disk_name.len) |
| 43 | |
Tahsin Erdogan | af65207 | 2017-07-06 00:01:59 -0400 | [diff] [blame] | 44 | /* Maximum value for the third parameter of fscrypt_operations.set_context(). */ |
Eric Biggers | 73ce50d | 2019-08-04 19:35:47 -0700 | [diff] [blame] | 45 | #define FSCRYPT_SET_CONTEXT_MAX_SIZE 40 |
Tahsin Erdogan | af65207 | 2017-07-06 00:01:59 -0400 | [diff] [blame] | 46 | |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 47 | #ifdef CONFIG_FS_ENCRYPTION |
| 48 | /* |
| 49 | * fscrypt superblock flags |
| 50 | */ |
| 51 | #define FS_CFLG_OWN_PAGES (1U << 1) |
| 52 | |
| 53 | /* |
| 54 | * crypto operations for filesystems |
| 55 | */ |
| 56 | struct fscrypt_operations { |
| 57 | unsigned int flags; |
| 58 | const char *key_prefix; |
| 59 | int (*get_context)(struct inode *, void *, size_t); |
| 60 | int (*set_context)(struct inode *, const void *, size_t, void *); |
| 61 | bool (*dummy_context)(struct inode *); |
| 62 | bool (*empty_dir)(struct inode *); |
| 63 | unsigned int max_namelen; |
Eric Biggers | 9423171 | 2019-10-24 14:43:36 -0700 | [diff] [blame] | 64 | bool (*has_stable_inodes)(struct super_block *sb); |
| 65 | void (*get_ino_and_lblk_bits)(struct super_block *sb, |
| 66 | int *ino_bits_ret, int *lblk_bits_ret); |
Satya Tangirala | 0797369 | 2019-10-24 14:44:29 -0700 | [diff] [blame] | 67 | bool (*inline_crypt_enabled)(struct super_block *sb); |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 68 | }; |
| 69 | |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 70 | static inline bool fscrypt_has_encryption_key(const struct inode *inode) |
| 71 | { |
Eric Biggers | 7a8861d | 2019-04-11 14:32:15 -0700 | [diff] [blame] | 72 | /* pairs with cmpxchg_release() in fscrypt_get_encryption_info() */ |
| 73 | return READ_ONCE(inode->i_crypt_info) != NULL; |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static inline bool fscrypt_dummy_context_enabled(struct inode *inode) |
| 77 | { |
| 78 | return inode->i_sb->s_cop->dummy_context && |
| 79 | inode->i_sb->s_cop->dummy_context(inode); |
| 80 | } |
| 81 | |
Eric Biggers | dd038b3 | 2019-03-20 11:39:11 -0700 | [diff] [blame] | 82 | /* |
| 83 | * When d_splice_alias() moves a directory's encrypted alias to its decrypted |
| 84 | * alias as a result of the encryption key being added, DCACHE_ENCRYPTED_NAME |
| 85 | * must be cleared. Note that we don't have to support arbitrary moves of this |
| 86 | * flag because fscrypt doesn't allow encrypted aliases to be the source or |
| 87 | * target of a rename(). |
| 88 | */ |
| 89 | static inline void fscrypt_handle_d_move(struct dentry *dentry) |
| 90 | { |
| 91 | dentry->d_flags &= ~DCACHE_ENCRYPTED_NAME; |
| 92 | } |
| 93 | |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 94 | /* crypto.c */ |
| 95 | extern void fscrypt_enqueue_decrypt_work(struct work_struct *); |
Eric Biggers | fd0e18f | 2019-05-20 09:29:44 -0700 | [diff] [blame] | 96 | |
| 97 | extern struct page *fscrypt_encrypt_pagecache_blocks(struct page *page, |
| 98 | unsigned int len, |
| 99 | unsigned int offs, |
| 100 | gfp_t gfp_flags); |
Eric Biggers | ce7b7a2 | 2019-05-20 09:29:43 -0700 | [diff] [blame] | 101 | extern int fscrypt_encrypt_block_inplace(const struct inode *inode, |
| 102 | struct page *page, unsigned int len, |
| 103 | unsigned int offs, u64 lblk_num, |
| 104 | gfp_t gfp_flags); |
Eric Biggers | 8780629 | 2019-05-20 09:29:47 -0700 | [diff] [blame] | 105 | |
| 106 | extern int fscrypt_decrypt_pagecache_blocks(struct page *page, unsigned int len, |
| 107 | unsigned int offs); |
Eric Biggers | 4582236 | 2019-05-20 09:29:46 -0700 | [diff] [blame] | 108 | extern int fscrypt_decrypt_block_inplace(const struct inode *inode, |
| 109 | struct page *page, unsigned int len, |
| 110 | unsigned int offs, u64 lblk_num); |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 111 | |
Eric Biggers | 2edab9e | 2019-05-20 09:29:39 -0700 | [diff] [blame] | 112 | static inline bool fscrypt_is_bounce_page(struct page *page) |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 113 | { |
Eric Biggers | 2edab9e | 2019-05-20 09:29:39 -0700 | [diff] [blame] | 114 | return page->mapping == NULL; |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 115 | } |
| 116 | |
Eric Biggers | 2edab9e | 2019-05-20 09:29:39 -0700 | [diff] [blame] | 117 | static inline struct page *fscrypt_pagecache_page(struct page *bounce_page) |
| 118 | { |
| 119 | return (struct page *)page_private(bounce_page); |
| 120 | } |
| 121 | |
| 122 | extern void fscrypt_free_bounce_page(struct page *bounce_page); |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 123 | |
| 124 | /* policy.c */ |
| 125 | extern int fscrypt_ioctl_set_policy(struct file *, const void __user *); |
| 126 | extern int fscrypt_ioctl_get_policy(struct file *, void __user *); |
Eric Biggers | 73ce50d | 2019-08-04 19:35:47 -0700 | [diff] [blame] | 127 | extern int fscrypt_ioctl_get_policy_ex(struct file *, void __user *); |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 128 | extern int fscrypt_has_permitted_context(struct inode *, struct inode *); |
| 129 | extern int fscrypt_inherit_context(struct inode *, struct inode *, |
| 130 | void *, bool); |
Eric Biggers | 9846255 | 2019-08-04 19:35:46 -0700 | [diff] [blame] | 131 | /* keyring.c */ |
| 132 | extern void fscrypt_sb_free(struct super_block *sb); |
| 133 | extern int fscrypt_ioctl_add_key(struct file *filp, void __user *arg); |
Eric Biggers | cacc84e | 2019-08-04 19:35:46 -0700 | [diff] [blame] | 134 | extern int fscrypt_ioctl_remove_key(struct file *filp, void __user *arg); |
Eric Biggers | 080389c | 2019-08-04 19:35:47 -0700 | [diff] [blame] | 135 | extern int fscrypt_ioctl_remove_key_all_users(struct file *filp, |
| 136 | void __user *arg); |
Eric Biggers | dbfc658 | 2019-08-04 19:35:46 -0700 | [diff] [blame] | 137 | extern int fscrypt_ioctl_get_key_status(struct file *filp, void __user *arg); |
Eric Biggers | 4932f53 | 2019-10-09 14:35:48 -0700 | [diff] [blame] | 138 | extern int fscrypt_register_key_removal_notifier(struct notifier_block *nb); |
| 139 | extern int fscrypt_unregister_key_removal_notifier(struct notifier_block *nb); |
Eric Biggers | 9846255 | 2019-08-04 19:35:46 -0700 | [diff] [blame] | 140 | |
Eric Biggers | c677e57 | 2019-08-04 19:35:45 -0700 | [diff] [blame] | 141 | /* keysetup.c */ |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 142 | extern int fscrypt_get_encryption_info(struct inode *); |
| 143 | extern void fscrypt_put_encryption_info(struct inode *); |
Eric Biggers | 1f1be4a | 2019-04-10 13:21:15 -0700 | [diff] [blame] | 144 | extern void fscrypt_free_inode(struct inode *); |
Eric Biggers | cacc84e | 2019-08-04 19:35:46 -0700 | [diff] [blame] | 145 | extern int fscrypt_drop_inode(struct inode *inode); |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 146 | |
| 147 | /* fname.c */ |
| 148 | extern int fscrypt_setup_filename(struct inode *, const struct qstr *, |
| 149 | int lookup, struct fscrypt_name *); |
| 150 | |
| 151 | static inline void fscrypt_free_filename(struct fscrypt_name *fname) |
| 152 | { |
| 153 | kfree(fname->crypto_buf.name); |
| 154 | } |
| 155 | |
| 156 | extern int fscrypt_fname_alloc_buffer(const struct inode *, u32, |
| 157 | struct fscrypt_str *); |
| 158 | extern void fscrypt_fname_free_buffer(struct fscrypt_str *); |
| 159 | extern int fscrypt_fname_disk_to_usr(struct inode *, u32, u32, |
| 160 | const struct fscrypt_str *, struct fscrypt_str *); |
| 161 | |
| 162 | #define FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE 32 |
| 163 | |
| 164 | /* Extracts the second-to-last ciphertext block; see explanation below */ |
| 165 | #define FSCRYPT_FNAME_DIGEST(name, len) \ |
| 166 | ((name) + round_down((len) - FS_CRYPTO_BLOCK_SIZE - 1, \ |
| 167 | FS_CRYPTO_BLOCK_SIZE)) |
| 168 | |
| 169 | #define FSCRYPT_FNAME_DIGEST_SIZE FS_CRYPTO_BLOCK_SIZE |
| 170 | |
| 171 | /** |
| 172 | * fscrypt_digested_name - alternate identifier for an on-disk filename |
| 173 | * |
| 174 | * When userspace lists an encrypted directory without access to the key, |
| 175 | * filenames whose ciphertext is longer than FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE |
| 176 | * bytes are shown in this abbreviated form (base64-encoded) rather than as the |
| 177 | * full ciphertext (base64-encoded). This is necessary to allow supporting |
| 178 | * filenames up to NAME_MAX bytes, since base64 encoding expands the length. |
| 179 | * |
| 180 | * To make it possible for filesystems to still find the correct directory entry |
| 181 | * despite not knowing the full on-disk name, we encode any filesystem-specific |
| 182 | * 'hash' and/or 'minor_hash' which the filesystem may need for its lookups, |
| 183 | * followed by the second-to-last ciphertext block of the filename. Due to the |
| 184 | * use of the CBC-CTS encryption mode, the second-to-last ciphertext block |
| 185 | * depends on the full plaintext. (Note that ciphertext stealing causes the |
| 186 | * last two blocks to appear "flipped".) This makes accidental collisions very |
| 187 | * unlikely: just a 1 in 2^128 chance for two filenames to collide even if they |
| 188 | * share the same filesystem-specific hashes. |
| 189 | * |
| 190 | * However, this scheme isn't immune to intentional collisions, which can be |
| 191 | * created by anyone able to create arbitrary plaintext filenames and view them |
| 192 | * without the key. Making the "digest" be a real cryptographic hash like |
| 193 | * SHA-256 over the full ciphertext would prevent this, although it would be |
| 194 | * less efficient and harder to implement, especially since the filesystem would |
| 195 | * need to calculate it for each directory entry examined during a search. |
| 196 | */ |
| 197 | struct fscrypt_digested_name { |
| 198 | u32 hash; |
| 199 | u32 minor_hash; |
| 200 | u8 digest[FSCRYPT_FNAME_DIGEST_SIZE]; |
| 201 | }; |
| 202 | |
| 203 | /** |
| 204 | * fscrypt_match_name() - test whether the given name matches a directory entry |
| 205 | * @fname: the name being searched for |
| 206 | * @de_name: the name from the directory entry |
| 207 | * @de_name_len: the length of @de_name in bytes |
| 208 | * |
| 209 | * Normally @fname->disk_name will be set, and in that case we simply compare |
| 210 | * that to the name stored in the directory entry. The only exception is that |
| 211 | * if we don't have the key for an encrypted directory and a filename in it is |
| 212 | * very long, then we won't have the full disk_name and we'll instead need to |
| 213 | * match against the fscrypt_digested_name. |
| 214 | * |
| 215 | * Return: %true if the name matches, otherwise %false. |
| 216 | */ |
| 217 | static inline bool fscrypt_match_name(const struct fscrypt_name *fname, |
| 218 | const u8 *de_name, u32 de_name_len) |
| 219 | { |
| 220 | if (unlikely(!fname->disk_name.name)) { |
| 221 | const struct fscrypt_digested_name *n = |
| 222 | (const void *)fname->crypto_buf.name; |
| 223 | if (WARN_ON_ONCE(fname->usr_fname->name[0] != '_')) |
| 224 | return false; |
| 225 | if (de_name_len <= FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE) |
| 226 | return false; |
| 227 | return !memcmp(FSCRYPT_FNAME_DIGEST(de_name, de_name_len), |
| 228 | n->digest, FSCRYPT_FNAME_DIGEST_SIZE); |
| 229 | } |
| 230 | |
| 231 | if (de_name_len != fname->disk_name.len) |
| 232 | return false; |
| 233 | return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len); |
| 234 | } |
| 235 | |
| 236 | /* bio.c */ |
| 237 | extern void fscrypt_decrypt_bio(struct bio *); |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 238 | extern int fscrypt_zeroout_range(const struct inode *, pgoff_t, sector_t, |
| 239 | unsigned int); |
| 240 | |
| 241 | /* hooks.c */ |
| 242 | extern int fscrypt_file_open(struct inode *inode, struct file *filp); |
Eric Biggers | 081985b | 2019-03-20 11:39:10 -0700 | [diff] [blame] | 243 | extern int __fscrypt_prepare_link(struct inode *inode, struct inode *dir, |
| 244 | struct dentry *dentry); |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 245 | extern int __fscrypt_prepare_rename(struct inode *old_dir, |
| 246 | struct dentry *old_dentry, |
| 247 | struct inode *new_dir, |
| 248 | struct dentry *new_dentry, |
| 249 | unsigned int flags); |
Eric Biggers | 716c370 | 2019-03-20 11:39:13 -0700 | [diff] [blame] | 250 | extern int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry, |
| 251 | struct fscrypt_name *fname); |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 252 | extern int __fscrypt_prepare_symlink(struct inode *dir, unsigned int len, |
| 253 | unsigned int max_len, |
| 254 | struct fscrypt_str *disk_link); |
| 255 | extern int __fscrypt_encrypt_symlink(struct inode *inode, const char *target, |
| 256 | unsigned int len, |
| 257 | struct fscrypt_str *disk_link); |
| 258 | extern const char *fscrypt_get_symlink(struct inode *inode, const void *caddr, |
| 259 | unsigned int max_size, |
| 260 | struct delayed_call *done); |
| 261 | #else /* !CONFIG_FS_ENCRYPTION */ |
| 262 | |
| 263 | static inline bool fscrypt_has_encryption_key(const struct inode *inode) |
| 264 | { |
| 265 | return false; |
| 266 | } |
| 267 | |
| 268 | static inline bool fscrypt_dummy_context_enabled(struct inode *inode) |
| 269 | { |
| 270 | return false; |
| 271 | } |
| 272 | |
Eric Biggers | dd038b3 | 2019-03-20 11:39:11 -0700 | [diff] [blame] | 273 | static inline void fscrypt_handle_d_move(struct dentry *dentry) |
| 274 | { |
| 275 | } |
| 276 | |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 277 | /* crypto.c */ |
| 278 | static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work) |
| 279 | { |
| 280 | } |
| 281 | |
Eric Biggers | fd0e18f | 2019-05-20 09:29:44 -0700 | [diff] [blame] | 282 | static inline struct page *fscrypt_encrypt_pagecache_blocks(struct page *page, |
| 283 | unsigned int len, |
| 284 | unsigned int offs, |
| 285 | gfp_t gfp_flags) |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 286 | { |
| 287 | return ERR_PTR(-EOPNOTSUPP); |
| 288 | } |
| 289 | |
Eric Biggers | ce7b7a2 | 2019-05-20 09:29:43 -0700 | [diff] [blame] | 290 | static inline int fscrypt_encrypt_block_inplace(const struct inode *inode, |
| 291 | struct page *page, |
| 292 | unsigned int len, |
| 293 | unsigned int offs, u64 lblk_num, |
| 294 | gfp_t gfp_flags) |
| 295 | { |
| 296 | return -EOPNOTSUPP; |
| 297 | } |
| 298 | |
Eric Biggers | 8780629 | 2019-05-20 09:29:47 -0700 | [diff] [blame] | 299 | static inline int fscrypt_decrypt_pagecache_blocks(struct page *page, |
| 300 | unsigned int len, |
| 301 | unsigned int offs) |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 302 | { |
| 303 | return -EOPNOTSUPP; |
| 304 | } |
| 305 | |
Eric Biggers | 4582236 | 2019-05-20 09:29:46 -0700 | [diff] [blame] | 306 | static inline int fscrypt_decrypt_block_inplace(const struct inode *inode, |
| 307 | struct page *page, |
| 308 | unsigned int len, |
| 309 | unsigned int offs, u64 lblk_num) |
| 310 | { |
| 311 | return -EOPNOTSUPP; |
| 312 | } |
| 313 | |
Eric Biggers | 2edab9e | 2019-05-20 09:29:39 -0700 | [diff] [blame] | 314 | static inline bool fscrypt_is_bounce_page(struct page *page) |
| 315 | { |
| 316 | return false; |
| 317 | } |
| 318 | |
| 319 | static inline struct page *fscrypt_pagecache_page(struct page *bounce_page) |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 320 | { |
| 321 | WARN_ON_ONCE(1); |
| 322 | return ERR_PTR(-EINVAL); |
| 323 | } |
| 324 | |
Eric Biggers | 2edab9e | 2019-05-20 09:29:39 -0700 | [diff] [blame] | 325 | static inline void fscrypt_free_bounce_page(struct page *bounce_page) |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 326 | { |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /* policy.c */ |
| 330 | static inline int fscrypt_ioctl_set_policy(struct file *filp, |
| 331 | const void __user *arg) |
| 332 | { |
| 333 | return -EOPNOTSUPP; |
| 334 | } |
| 335 | |
| 336 | static inline int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg) |
| 337 | { |
| 338 | return -EOPNOTSUPP; |
| 339 | } |
| 340 | |
Eric Biggers | 73ce50d | 2019-08-04 19:35:47 -0700 | [diff] [blame] | 341 | static inline int fscrypt_ioctl_get_policy_ex(struct file *filp, |
| 342 | void __user *arg) |
| 343 | { |
| 344 | return -EOPNOTSUPP; |
| 345 | } |
| 346 | |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 347 | static inline int fscrypt_has_permitted_context(struct inode *parent, |
| 348 | struct inode *child) |
| 349 | { |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | static inline int fscrypt_inherit_context(struct inode *parent, |
| 354 | struct inode *child, |
| 355 | void *fs_data, bool preload) |
| 356 | { |
| 357 | return -EOPNOTSUPP; |
| 358 | } |
| 359 | |
Eric Biggers | 9846255 | 2019-08-04 19:35:46 -0700 | [diff] [blame] | 360 | /* keyring.c */ |
| 361 | static inline void fscrypt_sb_free(struct super_block *sb) |
| 362 | { |
| 363 | } |
| 364 | |
| 365 | static inline int fscrypt_ioctl_add_key(struct file *filp, void __user *arg) |
| 366 | { |
| 367 | return -EOPNOTSUPP; |
| 368 | } |
| 369 | |
Eric Biggers | cacc84e | 2019-08-04 19:35:46 -0700 | [diff] [blame] | 370 | static inline int fscrypt_ioctl_remove_key(struct file *filp, void __user *arg) |
| 371 | { |
| 372 | return -EOPNOTSUPP; |
| 373 | } |
| 374 | |
Eric Biggers | 080389c | 2019-08-04 19:35:47 -0700 | [diff] [blame] | 375 | static inline int fscrypt_ioctl_remove_key_all_users(struct file *filp, |
| 376 | void __user *arg) |
| 377 | { |
| 378 | return -EOPNOTSUPP; |
| 379 | } |
| 380 | |
Eric Biggers | dbfc658 | 2019-08-04 19:35:46 -0700 | [diff] [blame] | 381 | static inline int fscrypt_ioctl_get_key_status(struct file *filp, |
| 382 | void __user *arg) |
| 383 | { |
| 384 | return -EOPNOTSUPP; |
| 385 | } |
| 386 | |
Eric Biggers | 4932f53 | 2019-10-09 14:35:48 -0700 | [diff] [blame] | 387 | static inline int fscrypt_register_key_removal_notifier( |
| 388 | struct notifier_block *nb) |
| 389 | { |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | static inline int fscrypt_unregister_key_removal_notifier( |
| 394 | struct notifier_block *nb) |
| 395 | { |
| 396 | return 0; |
| 397 | } |
| 398 | |
Eric Biggers | c677e57 | 2019-08-04 19:35:45 -0700 | [diff] [blame] | 399 | /* keysetup.c */ |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 400 | static inline int fscrypt_get_encryption_info(struct inode *inode) |
| 401 | { |
| 402 | return -EOPNOTSUPP; |
| 403 | } |
| 404 | |
| 405 | static inline void fscrypt_put_encryption_info(struct inode *inode) |
| 406 | { |
| 407 | return; |
| 408 | } |
| 409 | |
Eric Biggers | 1f1be4a | 2019-04-10 13:21:15 -0700 | [diff] [blame] | 410 | static inline void fscrypt_free_inode(struct inode *inode) |
| 411 | { |
| 412 | } |
| 413 | |
Eric Biggers | cacc84e | 2019-08-04 19:35:46 -0700 | [diff] [blame] | 414 | static inline int fscrypt_drop_inode(struct inode *inode) |
| 415 | { |
| 416 | return 0; |
| 417 | } |
| 418 | |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 419 | /* fname.c */ |
| 420 | static inline int fscrypt_setup_filename(struct inode *dir, |
| 421 | const struct qstr *iname, |
| 422 | int lookup, struct fscrypt_name *fname) |
| 423 | { |
| 424 | if (IS_ENCRYPTED(dir)) |
| 425 | return -EOPNOTSUPP; |
| 426 | |
Eric Biggers | 716c370 | 2019-03-20 11:39:13 -0700 | [diff] [blame] | 427 | memset(fname, 0, sizeof(*fname)); |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 428 | fname->usr_fname = iname; |
| 429 | fname->disk_name.name = (unsigned char *)iname->name; |
| 430 | fname->disk_name.len = iname->len; |
| 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | static inline void fscrypt_free_filename(struct fscrypt_name *fname) |
| 435 | { |
| 436 | return; |
| 437 | } |
| 438 | |
| 439 | static inline int fscrypt_fname_alloc_buffer(const struct inode *inode, |
| 440 | u32 max_encrypted_len, |
| 441 | struct fscrypt_str *crypto_str) |
| 442 | { |
| 443 | return -EOPNOTSUPP; |
| 444 | } |
| 445 | |
| 446 | static inline void fscrypt_fname_free_buffer(struct fscrypt_str *crypto_str) |
| 447 | { |
| 448 | return; |
| 449 | } |
| 450 | |
| 451 | static inline int fscrypt_fname_disk_to_usr(struct inode *inode, |
| 452 | u32 hash, u32 minor_hash, |
| 453 | const struct fscrypt_str *iname, |
| 454 | struct fscrypt_str *oname) |
| 455 | { |
| 456 | return -EOPNOTSUPP; |
| 457 | } |
| 458 | |
| 459 | static inline bool fscrypt_match_name(const struct fscrypt_name *fname, |
| 460 | const u8 *de_name, u32 de_name_len) |
| 461 | { |
| 462 | /* Encryption support disabled; use standard comparison */ |
| 463 | if (de_name_len != fname->disk_name.len) |
| 464 | return false; |
| 465 | return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len); |
| 466 | } |
| 467 | |
| 468 | /* bio.c */ |
| 469 | static inline void fscrypt_decrypt_bio(struct bio *bio) |
| 470 | { |
| 471 | } |
| 472 | |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 473 | static inline int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk, |
| 474 | sector_t pblk, unsigned int len) |
| 475 | { |
| 476 | return -EOPNOTSUPP; |
| 477 | } |
| 478 | |
| 479 | /* hooks.c */ |
| 480 | |
| 481 | static inline int fscrypt_file_open(struct inode *inode, struct file *filp) |
| 482 | { |
| 483 | if (IS_ENCRYPTED(inode)) |
| 484 | return -EOPNOTSUPP; |
| 485 | return 0; |
| 486 | } |
| 487 | |
Eric Biggers | 081985b | 2019-03-20 11:39:10 -0700 | [diff] [blame] | 488 | static inline int __fscrypt_prepare_link(struct inode *inode, struct inode *dir, |
| 489 | struct dentry *dentry) |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 490 | { |
| 491 | return -EOPNOTSUPP; |
| 492 | } |
| 493 | |
| 494 | static inline int __fscrypt_prepare_rename(struct inode *old_dir, |
| 495 | struct dentry *old_dentry, |
| 496 | struct inode *new_dir, |
| 497 | struct dentry *new_dentry, |
| 498 | unsigned int flags) |
| 499 | { |
| 500 | return -EOPNOTSUPP; |
| 501 | } |
| 502 | |
| 503 | static inline int __fscrypt_prepare_lookup(struct inode *dir, |
Eric Biggers | 716c370 | 2019-03-20 11:39:13 -0700 | [diff] [blame] | 504 | struct dentry *dentry, |
| 505 | struct fscrypt_name *fname) |
Chandan Rajendra | ad8ceb0 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 506 | { |
| 507 | return -EOPNOTSUPP; |
| 508 | } |
| 509 | |
| 510 | static inline int __fscrypt_prepare_symlink(struct inode *dir, |
| 511 | unsigned int len, |
| 512 | unsigned int max_len, |
| 513 | struct fscrypt_str *disk_link) |
| 514 | { |
| 515 | return -EOPNOTSUPP; |
| 516 | } |
| 517 | |
| 518 | |
| 519 | static inline int __fscrypt_encrypt_symlink(struct inode *inode, |
| 520 | const char *target, |
| 521 | unsigned int len, |
| 522 | struct fscrypt_str *disk_link) |
| 523 | { |
| 524 | return -EOPNOTSUPP; |
| 525 | } |
| 526 | |
| 527 | static inline const char *fscrypt_get_symlink(struct inode *inode, |
| 528 | const void *caddr, |
| 529 | unsigned int max_size, |
| 530 | struct delayed_call *done) |
| 531 | { |
| 532 | return ERR_PTR(-EOPNOTSUPP); |
| 533 | } |
| 534 | #endif /* !CONFIG_FS_ENCRYPTION */ |
Dave Chinner | 734f0d2 | 2017-10-09 12:15:34 -0700 | [diff] [blame] | 535 | |
Satya Tangirala | 0797369 | 2019-10-24 14:44:29 -0700 | [diff] [blame] | 536 | /* inline_crypt.c */ |
| 537 | #ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT |
| 538 | extern bool fscrypt_inode_uses_inline_crypto(const struct inode *inode); |
| 539 | |
| 540 | extern bool fscrypt_inode_uses_fs_layer_crypto(const struct inode *inode); |
| 541 | |
| 542 | extern int fscrypt_set_bio_crypt_ctx(struct bio *bio, const struct inode *inode, |
| 543 | u64 first_lblk, gfp_t gfp_mask); |
| 544 | |
| 545 | extern int fscrypt_set_bio_crypt_ctx_bh(struct bio *bio, |
| 546 | const struct buffer_head *first_bh, |
| 547 | gfp_t gfp_mask); |
| 548 | |
| 549 | extern bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode, |
| 550 | u64 next_lblk); |
| 551 | |
| 552 | extern bool fscrypt_mergeable_bio_bh(struct bio *bio, |
| 553 | const struct buffer_head *next_bh); |
| 554 | |
| 555 | #else /* CONFIG_FS_ENCRYPTION_INLINE_CRYPT */ |
| 556 | static inline bool fscrypt_inode_uses_inline_crypto(const struct inode *inode) |
| 557 | { |
| 558 | return false; |
| 559 | } |
| 560 | |
| 561 | static inline bool fscrypt_inode_uses_fs_layer_crypto(const struct inode *inode) |
| 562 | { |
| 563 | return IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode); |
| 564 | } |
| 565 | |
| 566 | static inline int fscrypt_set_bio_crypt_ctx(struct bio *bio, |
| 567 | const struct inode *inode, |
| 568 | u64 first_lblk, gfp_t gfp_mask) |
| 569 | { |
| 570 | return 0; |
| 571 | } |
| 572 | |
| 573 | static inline int fscrypt_set_bio_crypt_ctx_bh( |
| 574 | struct bio *bio, |
| 575 | const struct buffer_head *first_bh, |
| 576 | gfp_t gfp_mask) |
| 577 | { |
| 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | static inline bool fscrypt_mergeable_bio(struct bio *bio, |
| 582 | const struct inode *inode, |
| 583 | u64 next_lblk) |
| 584 | { |
| 585 | return true; |
| 586 | } |
| 587 | |
| 588 | static inline bool fscrypt_mergeable_bio_bh(struct bio *bio, |
| 589 | const struct buffer_head *next_bh) |
| 590 | { |
| 591 | return true; |
| 592 | } |
| 593 | #endif /* !CONFIG_FS_ENCRYPTION_INLINE_CRYPT */ |
| 594 | |
Eric Biggers | d293c3e | 2017-10-09 12:15:39 -0700 | [diff] [blame] | 595 | /** |
| 596 | * fscrypt_require_key - require an inode's encryption key |
| 597 | * @inode: the inode we need the key for |
| 598 | * |
| 599 | * If the inode is encrypted, set up its encryption key if not already done. |
| 600 | * Then require that the key be present and return -ENOKEY otherwise. |
| 601 | * |
| 602 | * No locks are needed, and the key will live as long as the struct inode --- so |
| 603 | * it won't go away from under you. |
| 604 | * |
| 605 | * Return: 0 on success, -ENOKEY if the key is missing, or another -errno code |
| 606 | * if a problem occurred while setting up the encryption key. |
| 607 | */ |
| 608 | static inline int fscrypt_require_key(struct inode *inode) |
| 609 | { |
| 610 | if (IS_ENCRYPTED(inode)) { |
| 611 | int err = fscrypt_get_encryption_info(inode); |
| 612 | |
| 613 | if (err) |
| 614 | return err; |
| 615 | if (!fscrypt_has_encryption_key(inode)) |
| 616 | return -ENOKEY; |
| 617 | } |
| 618 | return 0; |
| 619 | } |
Dave Chinner | 734f0d2 | 2017-10-09 12:15:34 -0700 | [diff] [blame] | 620 | |
Eric Biggers | 0ea87a9 | 2017-10-09 12:15:41 -0700 | [diff] [blame] | 621 | /** |
| 622 | * fscrypt_prepare_link - prepare to link an inode into a possibly-encrypted directory |
| 623 | * @old_dentry: an existing dentry for the inode being linked |
| 624 | * @dir: the target directory |
| 625 | * @dentry: negative dentry for the target filename |
| 626 | * |
| 627 | * A new link can only be added to an encrypted directory if the directory's |
| 628 | * encryption key is available --- since otherwise we'd have no way to encrypt |
| 629 | * the filename. Therefore, we first set up the directory's encryption key (if |
| 630 | * not already done) and return an error if it's unavailable. |
| 631 | * |
| 632 | * We also verify that the link will not violate the constraint that all files |
| 633 | * in an encrypted directory tree use the same encryption policy. |
| 634 | * |
| 635 | * Return: 0 on success, -ENOKEY if the directory's encryption key is missing, |
Eric Biggers | 94e1068 | 2019-01-22 16:20:21 -0800 | [diff] [blame] | 636 | * -EXDEV if the link would result in an inconsistent encryption policy, or |
Eric Biggers | 0ea87a9 | 2017-10-09 12:15:41 -0700 | [diff] [blame] | 637 | * another -errno code. |
| 638 | */ |
| 639 | static inline int fscrypt_prepare_link(struct dentry *old_dentry, |
| 640 | struct inode *dir, |
| 641 | struct dentry *dentry) |
| 642 | { |
| 643 | if (IS_ENCRYPTED(dir)) |
Eric Biggers | 081985b | 2019-03-20 11:39:10 -0700 | [diff] [blame] | 644 | return __fscrypt_prepare_link(d_inode(old_dentry), dir, dentry); |
Eric Biggers | 0ea87a9 | 2017-10-09 12:15:41 -0700 | [diff] [blame] | 645 | return 0; |
| 646 | } |
| 647 | |
Eric Biggers | 94b26f3 | 2017-10-09 12:15:42 -0700 | [diff] [blame] | 648 | /** |
| 649 | * fscrypt_prepare_rename - prepare for a rename between possibly-encrypted directories |
| 650 | * @old_dir: source directory |
| 651 | * @old_dentry: dentry for source file |
| 652 | * @new_dir: target directory |
| 653 | * @new_dentry: dentry for target location (may be negative unless exchanging) |
| 654 | * @flags: rename flags (we care at least about %RENAME_EXCHANGE) |
| 655 | * |
| 656 | * Prepare for ->rename() where the source and/or target directories may be |
| 657 | * encrypted. A new link can only be added to an encrypted directory if the |
| 658 | * directory's encryption key is available --- since otherwise we'd have no way |
| 659 | * to encrypt the filename. A rename to an existing name, on the other hand, |
| 660 | * *is* cryptographically possible without the key. However, we take the more |
| 661 | * conservative approach and just forbid all no-key renames. |
| 662 | * |
| 663 | * We also verify that the rename will not violate the constraint that all files |
| 664 | * in an encrypted directory tree use the same encryption policy. |
| 665 | * |
Eric Biggers | 94e1068 | 2019-01-22 16:20:21 -0800 | [diff] [blame] | 666 | * Return: 0 on success, -ENOKEY if an encryption key is missing, -EXDEV if the |
Eric Biggers | 94b26f3 | 2017-10-09 12:15:42 -0700 | [diff] [blame] | 667 | * rename would cause inconsistent encryption policies, or another -errno code. |
| 668 | */ |
| 669 | static inline int fscrypt_prepare_rename(struct inode *old_dir, |
| 670 | struct dentry *old_dentry, |
| 671 | struct inode *new_dir, |
| 672 | struct dentry *new_dentry, |
| 673 | unsigned int flags) |
| 674 | { |
| 675 | if (IS_ENCRYPTED(old_dir) || IS_ENCRYPTED(new_dir)) |
| 676 | return __fscrypt_prepare_rename(old_dir, old_dentry, |
| 677 | new_dir, new_dentry, flags); |
| 678 | return 0; |
| 679 | } |
| 680 | |
Eric Biggers | 32c3cf0 | 2017-10-09 12:15:43 -0700 | [diff] [blame] | 681 | /** |
| 682 | * fscrypt_prepare_lookup - prepare to lookup a name in a possibly-encrypted directory |
| 683 | * @dir: directory being searched |
| 684 | * @dentry: filename being looked up |
Eric Biggers | 716c370 | 2019-03-20 11:39:13 -0700 | [diff] [blame] | 685 | * @fname: (output) the name to use to search the on-disk directory |
Eric Biggers | 32c3cf0 | 2017-10-09 12:15:43 -0700 | [diff] [blame] | 686 | * |
Eric Biggers | 716c370 | 2019-03-20 11:39:13 -0700 | [diff] [blame] | 687 | * Prepare for ->lookup() in a directory which may be encrypted by determining |
| 688 | * the name that will actually be used to search the directory on-disk. Lookups |
| 689 | * can be done with or without the directory's encryption key; without the key, |
Eric Biggers | 32c3cf0 | 2017-10-09 12:15:43 -0700 | [diff] [blame] | 690 | * filenames are presented in encrypted form. Therefore, we'll try to set up |
| 691 | * the directory's encryption key, but even without it the lookup can continue. |
| 692 | * |
Eric Biggers | 37b434e | 2019-03-20 11:39:09 -0700 | [diff] [blame] | 693 | * This also installs a custom ->d_revalidate() method which will invalidate the |
| 694 | * dentry if it was created without the key and the key is later added. |
Eric Biggers | 32c3cf0 | 2017-10-09 12:15:43 -0700 | [diff] [blame] | 695 | * |
Eric Biggers | 716c370 | 2019-03-20 11:39:13 -0700 | [diff] [blame] | 696 | * Return: 0 on success; -ENOENT if key is unavailable but the filename isn't a |
| 697 | * correctly formed encoded ciphertext name, so a negative dentry should be |
| 698 | * created; or another -errno code. |
Eric Biggers | 32c3cf0 | 2017-10-09 12:15:43 -0700 | [diff] [blame] | 699 | */ |
| 700 | static inline int fscrypt_prepare_lookup(struct inode *dir, |
| 701 | struct dentry *dentry, |
Eric Biggers | 716c370 | 2019-03-20 11:39:13 -0700 | [diff] [blame] | 702 | struct fscrypt_name *fname) |
Eric Biggers | 32c3cf0 | 2017-10-09 12:15:43 -0700 | [diff] [blame] | 703 | { |
| 704 | if (IS_ENCRYPTED(dir)) |
Eric Biggers | 716c370 | 2019-03-20 11:39:13 -0700 | [diff] [blame] | 705 | return __fscrypt_prepare_lookup(dir, dentry, fname); |
| 706 | |
| 707 | memset(fname, 0, sizeof(*fname)); |
| 708 | fname->usr_fname = &dentry->d_name; |
| 709 | fname->disk_name.name = (unsigned char *)dentry->d_name.name; |
| 710 | fname->disk_name.len = dentry->d_name.len; |
Eric Biggers | 32c3cf0 | 2017-10-09 12:15:43 -0700 | [diff] [blame] | 711 | return 0; |
| 712 | } |
| 713 | |
Eric Biggers | 815dac3 | 2017-10-09 12:15:44 -0700 | [diff] [blame] | 714 | /** |
| 715 | * fscrypt_prepare_setattr - prepare to change a possibly-encrypted inode's attributes |
| 716 | * @dentry: dentry through which the inode is being changed |
| 717 | * @attr: attributes to change |
| 718 | * |
| 719 | * Prepare for ->setattr() on a possibly-encrypted inode. On an encrypted file, |
| 720 | * most attribute changes are allowed even without the encryption key. However, |
| 721 | * without the encryption key we do have to forbid truncates. This is needed |
| 722 | * because the size being truncated to may not be a multiple of the filesystem |
| 723 | * block size, and in that case we'd have to decrypt the final block, zero the |
| 724 | * portion past i_size, and re-encrypt it. (We *could* allow truncating to a |
| 725 | * filesystem block boundary, but it's simpler to just forbid all truncates --- |
| 726 | * and we already forbid all other contents modifications without the key.) |
| 727 | * |
| 728 | * Return: 0 on success, -ENOKEY if the key is missing, or another -errno code |
| 729 | * if a problem occurred while setting up the encryption key. |
| 730 | */ |
| 731 | static inline int fscrypt_prepare_setattr(struct dentry *dentry, |
| 732 | struct iattr *attr) |
| 733 | { |
| 734 | if (attr->ia_valid & ATTR_SIZE) |
| 735 | return fscrypt_require_key(d_inode(dentry)); |
| 736 | return 0; |
| 737 | } |
| 738 | |
Eric Biggers | 76e81d6 | 2018-01-05 10:45:01 -0800 | [diff] [blame] | 739 | /** |
| 740 | * fscrypt_prepare_symlink - prepare to create a possibly-encrypted symlink |
| 741 | * @dir: directory in which the symlink is being created |
| 742 | * @target: plaintext symlink target |
| 743 | * @len: length of @target excluding null terminator |
| 744 | * @max_len: space the filesystem has available to store the symlink target |
| 745 | * @disk_link: (out) the on-disk symlink target being prepared |
| 746 | * |
| 747 | * This function computes the size the symlink target will require on-disk, |
| 748 | * stores it in @disk_link->len, and validates it against @max_len. An |
| 749 | * encrypted symlink may be longer than the original. |
| 750 | * |
| 751 | * Additionally, @disk_link->name is set to @target if the symlink will be |
| 752 | * unencrypted, but left NULL if the symlink will be encrypted. For encrypted |
| 753 | * symlinks, the filesystem must call fscrypt_encrypt_symlink() to create the |
| 754 | * on-disk target later. (The reason for the two-step process is that some |
| 755 | * filesystems need to know the size of the symlink target before creating the |
| 756 | * inode, e.g. to determine whether it will be a "fast" or "slow" symlink.) |
| 757 | * |
| 758 | * Return: 0 on success, -ENAMETOOLONG if the symlink target is too long, |
| 759 | * -ENOKEY if the encryption key is missing, or another -errno code if a problem |
| 760 | * occurred while setting up the encryption key. |
| 761 | */ |
| 762 | static inline int fscrypt_prepare_symlink(struct inode *dir, |
| 763 | const char *target, |
| 764 | unsigned int len, |
| 765 | unsigned int max_len, |
| 766 | struct fscrypt_str *disk_link) |
| 767 | { |
| 768 | if (IS_ENCRYPTED(dir) || fscrypt_dummy_context_enabled(dir)) |
| 769 | return __fscrypt_prepare_symlink(dir, len, max_len, disk_link); |
| 770 | |
| 771 | disk_link->name = (unsigned char *)target; |
| 772 | disk_link->len = len + 1; |
| 773 | if (disk_link->len > max_len) |
| 774 | return -ENAMETOOLONG; |
| 775 | return 0; |
| 776 | } |
| 777 | |
| 778 | /** |
| 779 | * fscrypt_encrypt_symlink - encrypt the symlink target if needed |
| 780 | * @inode: symlink inode |
| 781 | * @target: plaintext symlink target |
| 782 | * @len: length of @target excluding null terminator |
| 783 | * @disk_link: (in/out) the on-disk symlink target being prepared |
| 784 | * |
| 785 | * If the symlink target needs to be encrypted, then this function encrypts it |
| 786 | * into @disk_link->name. fscrypt_prepare_symlink() must have been called |
| 787 | * previously to compute @disk_link->len. If the filesystem did not allocate a |
| 788 | * buffer for @disk_link->name after calling fscrypt_prepare_link(), then one |
| 789 | * will be kmalloc()'ed and the filesystem will be responsible for freeing it. |
| 790 | * |
| 791 | * Return: 0 on success, -errno on failure |
| 792 | */ |
| 793 | static inline int fscrypt_encrypt_symlink(struct inode *inode, |
| 794 | const char *target, |
| 795 | unsigned int len, |
| 796 | struct fscrypt_str *disk_link) |
| 797 | { |
| 798 | if (IS_ENCRYPTED(inode)) |
| 799 | return __fscrypt_encrypt_symlink(inode, target, len, disk_link); |
| 800 | return 0; |
| 801 | } |
| 802 | |
Eric Biggers | 2edab9e | 2019-05-20 09:29:39 -0700 | [diff] [blame] | 803 | /* If *pagep is a bounce page, free it and set *pagep to the pagecache page */ |
| 804 | static inline void fscrypt_finalize_bounce_page(struct page **pagep) |
| 805 | { |
| 806 | struct page *page = *pagep; |
| 807 | |
| 808 | if (fscrypt_is_bounce_page(page)) { |
| 809 | *pagep = fscrypt_pagecache_page(page); |
| 810 | fscrypt_free_bounce_page(page); |
| 811 | } |
| 812 | } |
| 813 | |
Dave Chinner | 734f0d2 | 2017-10-09 12:15:34 -0700 | [diff] [blame] | 814 | #endif /* _LINUX_FSCRYPT_H */ |