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