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