diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-11-14 14:35:15 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-11-14 14:35:15 -0500 |
| commit | 32190f0afbf4f1c0a9142e5a886a078ee0b794fd (patch) | |
| tree | 865f5cd7effacf40c02e7cda5c31fef8a0624c89 /include/linux | |
| parent | 37dc79565c4b7e735f190eaa6ed5bb6eb3d3968a (diff) | |
| parent | a0b3bc855374c50b5ea85273553485af48caf2f7 (diff) | |
Merge tag 'fscrypt-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/fscrypt
Pull fscrypt updates from Ted Ts'o:
"Lots of cleanups, mostly courtesy by Eric Biggers"
* tag 'fscrypt-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/fscrypt:
fscrypt: lock mutex before checking for bounce page pool
fscrypt: add a documentation file for filesystem-level encryption
ext4: switch to fscrypt_prepare_setattr()
ext4: switch to fscrypt_prepare_lookup()
ext4: switch to fscrypt_prepare_rename()
ext4: switch to fscrypt_prepare_link()
ext4: switch to fscrypt_file_open()
fscrypt: new helper function - fscrypt_prepare_setattr()
fscrypt: new helper function - fscrypt_prepare_lookup()
fscrypt: new helper function - fscrypt_prepare_rename()
fscrypt: new helper function - fscrypt_prepare_link()
fscrypt: new helper function - fscrypt_file_open()
fscrypt: new helper function - fscrypt_require_key()
fscrypt: remove unneeded empty fscrypt_operations structs
fscrypt: remove ->is_encrypted()
fscrypt: switch from ->is_encrypted() to IS_ENCRYPTED()
fs, fscrypt: add an S_ENCRYPTED inode flag
fscrypt: clean up include file mess
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/fs.h | 2 | ||||
| -rw-r--r-- | include/linux/fscrypt.h | 294 | ||||
| -rw-r--r-- | include/linux/fscrypt_common.h | 142 | ||||
| -rw-r--r-- | include/linux/fscrypt_notsupp.h | 39 | ||||
| -rw-r--r-- | include/linux/fscrypt_supp.h | 17 |
5 files changed, 346 insertions, 148 deletions
diff --git a/include/linux/fs.h b/include/linux/fs.h index e1f75a3b4af5..269086440071 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
| @@ -1854,6 +1854,7 @@ struct super_operations { | |||
| 1854 | #else | 1854 | #else |
| 1855 | #define S_DAX 0 /* Make all the DAX code disappear */ | 1855 | #define S_DAX 0 /* Make all the DAX code disappear */ |
| 1856 | #endif | 1856 | #endif |
| 1857 | #define S_ENCRYPTED 16384 /* Encrypted file (using fs/crypto/) */ | ||
| 1857 | 1858 | ||
| 1858 | /* | 1859 | /* |
| 1859 | * Note that nosuid etc flags are inode-specific: setting some file-system | 1860 | * Note that nosuid etc flags are inode-specific: setting some file-system |
| @@ -1893,6 +1894,7 @@ static inline bool sb_rdonly(const struct super_block *sb) { return sb->s_flags | |||
| 1893 | #define IS_AUTOMOUNT(inode) ((inode)->i_flags & S_AUTOMOUNT) | 1894 | #define IS_AUTOMOUNT(inode) ((inode)->i_flags & S_AUTOMOUNT) |
| 1894 | #define IS_NOSEC(inode) ((inode)->i_flags & S_NOSEC) | 1895 | #define IS_NOSEC(inode) ((inode)->i_flags & S_NOSEC) |
| 1895 | #define IS_DAX(inode) ((inode)->i_flags & S_DAX) | 1896 | #define IS_DAX(inode) ((inode)->i_flags & S_DAX) |
| 1897 | #define IS_ENCRYPTED(inode) ((inode)->i_flags & S_ENCRYPTED) | ||
| 1896 | 1898 | ||
| 1897 | #define IS_WHITEOUT(inode) (S_ISCHR(inode->i_mode) && \ | 1899 | #define IS_WHITEOUT(inode) (S_ISCHR(inode->i_mode) && \ |
| 1898 | (inode)->i_rdev == WHITEOUT_DEV) | 1900 | (inode)->i_rdev == WHITEOUT_DEV) |
diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h new file mode 100644 index 000000000000..08b4b40c5aa8 --- /dev/null +++ b/include/linux/fscrypt.h | |||
| @@ -0,0 +1,294 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * fscrypt.h: declarations for per-file encryption | ||
| 4 | * | ||
| 5 | * Filesystems that implement per-file encryption include this header | ||
| 6 | * file with the __FS_HAS_ENCRYPTION set according to whether that filesystem | ||
| 7 | * is being built with encryption support or not. | ||
| 8 | * | ||
| 9 | * Copyright (C) 2015, Google, Inc. | ||
| 10 | * | ||
| 11 | * Written by Michael Halcrow, 2015. | ||
| 12 | * Modified by Jaegeuk Kim, 2015. | ||
| 13 | */ | ||
| 14 | #ifndef _LINUX_FSCRYPT_H | ||
| 15 | #define _LINUX_FSCRYPT_H | ||
| 16 | |||
| 17 | #include <linux/key.h> | ||
| 18 | #include <linux/fs.h> | ||
| 19 | #include <linux/mm.h> | ||
| 20 | #include <linux/bio.h> | ||
| 21 | #include <linux/dcache.h> | ||
| 22 | #include <crypto/skcipher.h> | ||
| 23 | #include <uapi/linux/fs.h> | ||
| 24 | |||
| 25 | #define FS_CRYPTO_BLOCK_SIZE 16 | ||
| 26 | |||
| 27 | struct fscrypt_info; | ||
| 28 | |||
| 29 | struct fscrypt_ctx { | ||
| 30 | union { | ||
| 31 | struct { | ||
| 32 | struct page *bounce_page; /* Ciphertext page */ | ||
| 33 | struct page *control_page; /* Original page */ | ||
| 34 | } w; | ||
| 35 | struct { | ||
| 36 | struct bio *bio; | ||
| 37 | struct work_struct work; | ||
| 38 | } r; | ||
| 39 | struct list_head free_list; /* Free list */ | ||
| 40 | }; | ||
| 41 | u8 flags; /* Flags */ | ||
| 42 | }; | ||
| 43 | |||
| 44 | /** | ||
| 45 | * For encrypted symlinks, the ciphertext length is stored at the beginning | ||
| 46 | * of the string in little-endian format. | ||
| 47 | */ | ||
| 48 | struct fscrypt_symlink_data { | ||
| 49 | __le16 len; | ||
| 50 | char encrypted_path[1]; | ||
| 51 | } __packed; | ||
| 52 | |||
| 53 | struct fscrypt_str { | ||
| 54 | unsigned char *name; | ||
| 55 | u32 len; | ||
| 56 | }; | ||
| 57 | |||
| 58 | struct fscrypt_name { | ||
| 59 | const struct qstr *usr_fname; | ||
| 60 | struct fscrypt_str disk_name; | ||
| 61 | u32 hash; | ||
| 62 | u32 minor_hash; | ||
| 63 | struct fscrypt_str crypto_buf; | ||
| 64 | }; | ||
| 65 | |||
| 66 | #define FSTR_INIT(n, l) { .name = n, .len = l } | ||
| 67 | #define FSTR_TO_QSTR(f) QSTR_INIT((f)->name, (f)->len) | ||
| 68 | #define fname_name(p) ((p)->disk_name.name) | ||
| 69 | #define fname_len(p) ((p)->disk_name.len) | ||
| 70 | |||
| 71 | /* | ||
| 72 | * fscrypt superblock flags | ||
| 73 | */ | ||
| 74 | #define FS_CFLG_OWN_PAGES (1U << 1) | ||
| 75 | |||
| 76 | /* | ||
| 77 | * crypto opertions for filesystems | ||
| 78 | */ | ||
| 79 | struct fscrypt_operations { | ||
| 80 | unsigned int flags; | ||
| 81 | const char *key_prefix; | ||
| 82 | int (*get_context)(struct inode *, void *, size_t); | ||
| 83 | int (*set_context)(struct inode *, const void *, size_t, void *); | ||
| 84 | bool (*dummy_context)(struct inode *); | ||
| 85 | bool (*empty_dir)(struct inode *); | ||
| 86 | unsigned (*max_namelen)(struct inode *); | ||
| 87 | }; | ||
| 88 | |||
| 89 | /* Maximum value for the third parameter of fscrypt_operations.set_context(). */ | ||
| 90 | #define FSCRYPT_SET_CONTEXT_MAX_SIZE 28 | ||
| 91 | |||
| 92 | static inline bool fscrypt_dummy_context_enabled(struct inode *inode) | ||
| 93 | { | ||
| 94 | if (inode->i_sb->s_cop->dummy_context && | ||
| 95 | inode->i_sb->s_cop->dummy_context(inode)) | ||
| 96 | return true; | ||
| 97 | return false; | ||
| 98 | } | ||
| 99 | |||
| 100 | static inline bool fscrypt_valid_enc_modes(u32 contents_mode, | ||
| 101 | u32 filenames_mode) | ||
| 102 | { | ||
| 103 | if (contents_mode == FS_ENCRYPTION_MODE_AES_128_CBC && | ||
| 104 | filenames_mode == FS_ENCRYPTION_MODE_AES_128_CTS) | ||
| 105 | return true; | ||
| 106 | |||
| 107 | if (contents_mode == FS_ENCRYPTION_MODE_AES_256_XTS && | ||
| 108 | filenames_mode == FS_ENCRYPTION_MODE_AES_256_CTS) | ||
| 109 | return true; | ||
| 110 | |||
| 111 | return false; | ||
| 112 | } | ||
| 113 | |||
| 114 | static inline bool fscrypt_is_dot_dotdot(const struct qstr *str) | ||
| 115 | { | ||
| 116 | if (str->len == 1 && str->name[0] == '.') | ||
| 117 | return true; | ||
| 118 | |||
| 119 | if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') | ||
| 120 | return true; | ||
| 121 | |||
| 122 | return false; | ||
| 123 | } | ||
| 124 | |||
| 125 | #if __FS_HAS_ENCRYPTION | ||
| 126 | |||
| 127 | static inline struct page *fscrypt_control_page(struct page *page) | ||
| 128 | { | ||
| 129 | return ((struct fscrypt_ctx *)page_private(page))->w.control_page; | ||
| 130 | } | ||
| 131 | |||
| 132 | static inline bool fscrypt_has_encryption_key(const struct inode *inode) | ||
| 133 | { | ||
| 134 | return (inode->i_crypt_info != NULL); | ||
| 135 | } | ||
| 136 | |||
| 137 | #include <linux/fscrypt_supp.h> | ||
| 138 | |||
| 139 | #else /* !__FS_HAS_ENCRYPTION */ | ||
| 140 | |||
| 141 | static inline struct page *fscrypt_control_page(struct page *page) | ||
| 142 | { | ||
| 143 | WARN_ON_ONCE(1); | ||
| 144 | return ERR_PTR(-EINVAL); | ||
| 145 | } | ||
| 146 | |||
| 147 | static inline bool fscrypt_has_encryption_key(const struct inode *inode) | ||
| 148 | { | ||
| 149 | return 0; | ||
| 150 | } | ||
| 151 | |||
| 152 | #include <linux/fscrypt_notsupp.h> | ||
| 153 | #endif /* __FS_HAS_ENCRYPTION */ | ||
| 154 | |||
| 155 | /** | ||
| 156 | * fscrypt_require_key - require an inode's encryption key | ||
| 157 | * @inode: the inode we need the key for | ||
| 158 | * | ||
| 159 | * If the inode is encrypted, set up its encryption key if not already done. | ||
| 160 | * Then require that the key be present and return -ENOKEY otherwise. | ||
| 161 | * | ||
| 162 | * No locks are needed, and the key will live as long as the struct inode --- so | ||
| 163 | * it won't go away from under you. | ||
| 164 | * | ||
| 165 | * Return: 0 on success, -ENOKEY if the key is missing, or another -errno code | ||
| 166 | * if a problem occurred while setting up the encryption key. | ||
| 167 | */ | ||
| 168 | static inline int fscrypt_require_key(struct inode *inode) | ||
| 169 | { | ||
| 170 | if (IS_ENCRYPTED(inode)) { | ||
| 171 | int err = fscrypt_get_encryption_info(inode); | ||
| 172 | |||
| 173 | if (err) | ||
| 174 | return err; | ||
| 175 | if (!fscrypt_has_encryption_key(inode)) | ||
| 176 | return -ENOKEY; | ||
| 177 | } | ||
| 178 | return 0; | ||
| 179 | } | ||
| 180 | |||
| 181 | /** | ||
| 182 | * fscrypt_prepare_link - prepare to link an inode into a possibly-encrypted directory | ||
| 183 | * @old_dentry: an existing dentry for the inode being linked | ||
| 184 | * @dir: the target directory | ||
| 185 | * @dentry: negative dentry for the target filename | ||
| 186 | * | ||
| 187 | * A new link can only be added to an encrypted directory if the directory's | ||
| 188 | * encryption key is available --- since otherwise we'd have no way to encrypt | ||
| 189 | * the filename. Therefore, we first set up the directory's encryption key (if | ||
| 190 | * not already done) and return an error if it's unavailable. | ||
| 191 | * | ||
| 192 | * We also verify that the link will not violate the constraint that all files | ||
| 193 | * in an encrypted directory tree use the same encryption policy. | ||
| 194 | * | ||
| 195 | * Return: 0 on success, -ENOKEY if the directory's encryption key is missing, | ||
| 196 | * -EPERM if the link would result in an inconsistent encryption policy, or | ||
| 197 | * another -errno code. | ||
| 198 | */ | ||
| 199 | static inline int fscrypt_prepare_link(struct dentry *old_dentry, | ||
| 200 | struct inode *dir, | ||
| 201 | struct dentry *dentry) | ||
| 202 | { | ||
| 203 | if (IS_ENCRYPTED(dir)) | ||
| 204 | return __fscrypt_prepare_link(d_inode(old_dentry), dir); | ||
| 205 | return 0; | ||
| 206 | } | ||
| 207 | |||
| 208 | /** | ||
| 209 | * fscrypt_prepare_rename - prepare for a rename between possibly-encrypted directories | ||
| 210 | * @old_dir: source directory | ||
| 211 | * @old_dentry: dentry for source file | ||
| 212 | * @new_dir: target directory | ||
| 213 | * @new_dentry: dentry for target location (may be negative unless exchanging) | ||
| 214 | * @flags: rename flags (we care at least about %RENAME_EXCHANGE) | ||
| 215 | * | ||
| 216 | * Prepare for ->rename() where the source and/or target directories may be | ||
| 217 | * encrypted. A new link can only be added to an encrypted directory if the | ||
| 218 | * directory's encryption key is available --- since otherwise we'd have no way | ||
| 219 | * to encrypt the filename. A rename to an existing name, on the other hand, | ||
| 220 | * *is* cryptographically possible without the key. However, we take the more | ||
| 221 | * conservative approach and just forbid all no-key renames. | ||
| 222 | * | ||
| 223 | * We also verify that the rename will not violate the constraint that all files | ||
| 224 | * in an encrypted directory tree use the same encryption policy. | ||
| 225 | * | ||
| 226 | * Return: 0 on success, -ENOKEY if an encryption key is missing, -EPERM if the | ||
| 227 | * rename would cause inconsistent encryption policies, or another -errno code. | ||
| 228 | */ | ||
| 229 | static inline int fscrypt_prepare_rename(struct inode *old_dir, | ||
| 230 | struct dentry *old_dentry, | ||
| 231 | struct inode *new_dir, | ||
| 232 | struct dentry *new_dentry, | ||
| 233 | unsigned int flags) | ||
| 234 | { | ||
| 235 | if (IS_ENCRYPTED(old_dir) || IS_ENCRYPTED(new_dir)) | ||
| 236 | return __fscrypt_prepare_rename(old_dir, old_dentry, | ||
| 237 | new_dir, new_dentry, flags); | ||
| 238 | return 0; | ||
| 239 | } | ||
| 240 | |||
| 241 | /** | ||
| 242 | * fscrypt_prepare_lookup - prepare to lookup a name in a possibly-encrypted directory | ||
| 243 | * @dir: directory being searched | ||
| 244 | * @dentry: filename being looked up | ||
| 245 | * @flags: lookup flags | ||
| 246 | * | ||
| 247 | * Prepare for ->lookup() in a directory which may be encrypted. Lookups can be | ||
| 248 | * done with or without the directory's encryption key; without the key, | ||
| 249 | * filenames are presented in encrypted form. Therefore, we'll try to set up | ||
| 250 | * the directory's encryption key, but even without it the lookup can continue. | ||
| 251 | * | ||
| 252 | * To allow invalidating stale dentries if the directory's encryption key is | ||
| 253 | * added later, we also install a custom ->d_revalidate() method and use the | ||
| 254 | * DCACHE_ENCRYPTED_WITH_KEY flag to indicate whether a given dentry is a | ||
| 255 | * plaintext name (flag set) or a ciphertext name (flag cleared). | ||
| 256 | * | ||
| 257 | * Return: 0 on success, -errno if a problem occurred while setting up the | ||
| 258 | * encryption key | ||
| 259 | */ | ||
| 260 | static inline int fscrypt_prepare_lookup(struct inode *dir, | ||
| 261 | struct dentry *dentry, | ||
| 262 | unsigned int flags) | ||
| 263 | { | ||
| 264 | if (IS_ENCRYPTED(dir)) | ||
| 265 | return __fscrypt_prepare_lookup(dir, dentry); | ||
| 266 | return 0; | ||
| 267 | } | ||
| 268 | |||
| 269 | /** | ||
| 270 | * fscrypt_prepare_setattr - prepare to change a possibly-encrypted inode's attributes | ||
| 271 | * @dentry: dentry through which the inode is being changed | ||
| 272 | * @attr: attributes to change | ||
| 273 | * | ||
| 274 | * Prepare for ->setattr() on a possibly-encrypted inode. On an encrypted file, | ||
| 275 | * most attribute changes are allowed even without the encryption key. However, | ||
| 276 | * without the encryption key we do have to forbid truncates. This is needed | ||
| 277 | * because the size being truncated to may not be a multiple of the filesystem | ||
| 278 | * block size, and in that case we'd have to decrypt the final block, zero the | ||
| 279 | * portion past i_size, and re-encrypt it. (We *could* allow truncating to a | ||
| 280 | * filesystem block boundary, but it's simpler to just forbid all truncates --- | ||
| 281 | * and we already forbid all other contents modifications without the key.) | ||
| 282 | * | ||
| 283 | * Return: 0 on success, -ENOKEY if the key is missing, or another -errno code | ||
| 284 | * if a problem occurred while setting up the encryption key. | ||
| 285 | */ | ||
| 286 | static inline int fscrypt_prepare_setattr(struct dentry *dentry, | ||
| 287 | struct iattr *attr) | ||
| 288 | { | ||
| 289 | if (attr->ia_valid & ATTR_SIZE) | ||
| 290 | return fscrypt_require_key(d_inode(dentry)); | ||
| 291 | return 0; | ||
| 292 | } | ||
| 293 | |||
| 294 | #endif /* _LINUX_FSCRYPT_H */ | ||
diff --git a/include/linux/fscrypt_common.h b/include/linux/fscrypt_common.h deleted file mode 100644 index 854d724978fa..000000000000 --- a/include/linux/fscrypt_common.h +++ /dev/null | |||
| @@ -1,142 +0,0 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * fscrypt_common.h: common declarations for per-file encryption | ||
| 4 | * | ||
| 5 | * Copyright (C) 2015, Google, Inc. | ||
| 6 | * | ||
| 7 | * Written by Michael Halcrow, 2015. | ||
| 8 | * Modified by Jaegeuk Kim, 2015. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #ifndef _LINUX_FSCRYPT_COMMON_H | ||
| 12 | #define _LINUX_FSCRYPT_COMMON_H | ||
| 13 | |||
| 14 | #include <linux/key.h> | ||
| 15 | #include <linux/fs.h> | ||
| 16 | #include <linux/mm.h> | ||
| 17 | #include <linux/bio.h> | ||
| 18 | #include <linux/dcache.h> | ||
| 19 | #include <crypto/skcipher.h> | ||
| 20 | #include <uapi/linux/fs.h> | ||
| 21 | |||
| 22 | #define FS_CRYPTO_BLOCK_SIZE 16 | ||
| 23 | |||
| 24 | struct fscrypt_info; | ||
| 25 | |||
| 26 | struct fscrypt_ctx { | ||
| 27 | union { | ||
| 28 | struct { | ||
| 29 | struct page *bounce_page; /* Ciphertext page */ | ||
| 30 | struct page *control_page; /* Original page */ | ||
| 31 | } w; | ||
| 32 | struct { | ||
| 33 | struct bio *bio; | ||
| 34 | struct work_struct work; | ||
| 35 | } r; | ||
| 36 | struct list_head free_list; /* Free list */ | ||
| 37 | }; | ||
| 38 | u8 flags; /* Flags */ | ||
| 39 | }; | ||
| 40 | |||
| 41 | /** | ||
| 42 | * For encrypted symlinks, the ciphertext length is stored at the beginning | ||
| 43 | * of the string in little-endian format. | ||
| 44 | */ | ||
| 45 | struct fscrypt_symlink_data { | ||
| 46 | __le16 len; | ||
| 47 | char encrypted_path[1]; | ||
| 48 | } __packed; | ||
| 49 | |||
| 50 | struct fscrypt_str { | ||
| 51 | unsigned char *name; | ||
| 52 | u32 len; | ||
| 53 | }; | ||
| 54 | |||
| 55 | struct fscrypt_name { | ||
| 56 | const struct qstr *usr_fname; | ||
| 57 | struct fscrypt_str disk_name; | ||
| 58 | u32 hash; | ||
| 59 | u32 minor_hash; | ||
| 60 | struct fscrypt_str crypto_buf; | ||
| 61 | }; | ||
| 62 | |||
| 63 | #define FSTR_INIT(n, l) { .name = n, .len = l } | ||
| 64 | #define FSTR_TO_QSTR(f) QSTR_INIT((f)->name, (f)->len) | ||
| 65 | #define fname_name(p) ((p)->disk_name.name) | ||
| 66 | #define fname_len(p) ((p)->disk_name.len) | ||
| 67 | |||
| 68 | /* | ||
| 69 | * fscrypt superblock flags | ||
| 70 | */ | ||
| 71 | #define FS_CFLG_OWN_PAGES (1U << 1) | ||
| 72 | |||
| 73 | /* | ||
| 74 | * crypto opertions for filesystems | ||
| 75 | */ | ||
| 76 | struct fscrypt_operations { | ||
| 77 | unsigned int flags; | ||
| 78 | const char *key_prefix; | ||
| 79 | int (*get_context)(struct inode *, void *, size_t); | ||
| 80 | int (*set_context)(struct inode *, const void *, size_t, void *); | ||
| 81 | bool (*dummy_context)(struct inode *); | ||
| 82 | bool (*is_encrypted)(struct inode *); | ||
| 83 | bool (*empty_dir)(struct inode *); | ||
| 84 | unsigned (*max_namelen)(struct inode *); | ||
| 85 | }; | ||
| 86 | |||
| 87 | /* Maximum value for the third parameter of fscrypt_operations.set_context(). */ | ||
| 88 | #define FSCRYPT_SET_CONTEXT_MAX_SIZE 28 | ||
| 89 | |||
| 90 | static inline bool fscrypt_dummy_context_enabled(struct inode *inode) | ||
| 91 | { | ||
| 92 | if (inode->i_sb->s_cop->dummy_context && | ||
| 93 | inode->i_sb->s_cop->dummy_context(inode)) | ||
| 94 | return true; | ||
| 95 | return false; | ||
| 96 | } | ||
| 97 | |||
| 98 | static inline bool fscrypt_valid_enc_modes(u32 contents_mode, | ||
| 99 | u32 filenames_mode) | ||
| 100 | { | ||
| 101 | if (contents_mode == FS_ENCRYPTION_MODE_AES_128_CBC && | ||
| 102 | filenames_mode == FS_ENCRYPTION_MODE_AES_128_CTS) | ||
| 103 | return true; | ||
| 104 | |||
| 105 | if (contents_mode == FS_ENCRYPTION_MODE_AES_256_XTS && | ||
| 106 | filenames_mode == FS_ENCRYPTION_MODE_AES_256_CTS) | ||
| 107 | return true; | ||
| 108 | |||
| 109 | return false; | ||
| 110 | } | ||
| 111 | |||
| 112 | static inline bool fscrypt_is_dot_dotdot(const struct qstr *str) | ||
| 113 | { | ||
| 114 | if (str->len == 1 && str->name[0] == '.') | ||
| 115 | return true; | ||
| 116 | |||
| 117 | if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') | ||
| 118 | return true; | ||
| 119 | |||
| 120 | return false; | ||
| 121 | } | ||
| 122 | |||
| 123 | static inline struct page *fscrypt_control_page(struct page *page) | ||
| 124 | { | ||
| 125 | #if IS_ENABLED(CONFIG_FS_ENCRYPTION) | ||
| 126 | return ((struct fscrypt_ctx *)page_private(page))->w.control_page; | ||
| 127 | #else | ||
| 128 | WARN_ON_ONCE(1); | ||
| 129 | return ERR_PTR(-EINVAL); | ||
| 130 | #endif | ||
| 131 | } | ||
| 132 | |||
| 133 | static inline int fscrypt_has_encryption_key(const struct inode *inode) | ||
| 134 | { | ||
| 135 | #if IS_ENABLED(CONFIG_FS_ENCRYPTION) | ||
| 136 | return (inode->i_crypt_info != NULL); | ||
| 137 | #else | ||
| 138 | return 0; | ||
| 139 | #endif | ||
| 140 | } | ||
| 141 | |||
| 142 | #endif /* _LINUX_FSCRYPT_COMMON_H */ | ||
diff --git a/include/linux/fscrypt_notsupp.h b/include/linux/fscrypt_notsupp.h index 19609ceea350..63e58808519a 100644 --- a/include/linux/fscrypt_notsupp.h +++ b/include/linux/fscrypt_notsupp.h | |||
| @@ -4,13 +4,16 @@ | |||
| 4 | * | 4 | * |
| 5 | * This stubs out the fscrypt functions for filesystems configured without | 5 | * This stubs out the fscrypt functions for filesystems configured without |
| 6 | * encryption support. | 6 | * encryption support. |
| 7 | * | ||
| 8 | * Do not include this file directly. Use fscrypt.h instead! | ||
| 7 | */ | 9 | */ |
| 10 | #ifndef _LINUX_FSCRYPT_H | ||
| 11 | #error "Incorrect include of linux/fscrypt_notsupp.h!" | ||
| 12 | #endif | ||
| 8 | 13 | ||
| 9 | #ifndef _LINUX_FSCRYPT_NOTSUPP_H | 14 | #ifndef _LINUX_FSCRYPT_NOTSUPP_H |
| 10 | #define _LINUX_FSCRYPT_NOTSUPP_H | 15 | #define _LINUX_FSCRYPT_NOTSUPP_H |
| 11 | 16 | ||
| 12 | #include <linux/fscrypt_common.h> | ||
| 13 | |||
| 14 | /* crypto.c */ | 17 | /* crypto.c */ |
| 15 | static inline struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *inode, | 18 | static inline struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *inode, |
| 16 | gfp_t gfp_flags) | 19 | gfp_t gfp_flags) |
| @@ -98,7 +101,7 @@ static inline int fscrypt_setup_filename(struct inode *dir, | |||
| 98 | const struct qstr *iname, | 101 | const struct qstr *iname, |
| 99 | int lookup, struct fscrypt_name *fname) | 102 | int lookup, struct fscrypt_name *fname) |
| 100 | { | 103 | { |
| 101 | if (dir->i_sb->s_cop->is_encrypted(dir)) | 104 | if (IS_ENCRYPTED(dir)) |
| 102 | return -EOPNOTSUPP; | 105 | return -EOPNOTSUPP; |
| 103 | 106 | ||
| 104 | memset(fname, 0, sizeof(struct fscrypt_name)); | 107 | memset(fname, 0, sizeof(struct fscrypt_name)); |
| @@ -175,4 +178,34 @@ static inline int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk, | |||
| 175 | return -EOPNOTSUPP; | 178 | return -EOPNOTSUPP; |
| 176 | } | 179 | } |
| 177 | 180 | ||
| 181 | /* hooks.c */ | ||
| 182 | |||
| 183 | static inline int fscrypt_file_open(struct inode *inode, struct file *filp) | ||
| 184 | { | ||
| 185 | if (IS_ENCRYPTED(inode)) | ||
| 186 | return -EOPNOTSUPP; | ||
| 187 | return 0; | ||
| 188 | } | ||
| 189 | |||
| 190 | static inline int __fscrypt_prepare_link(struct inode *inode, | ||
| 191 | struct inode *dir) | ||
| 192 | { | ||
| 193 | return -EOPNOTSUPP; | ||
| 194 | } | ||
| 195 | |||
| 196 | static inline 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) | ||
| 201 | { | ||
| 202 | return -EOPNOTSUPP; | ||
| 203 | } | ||
| 204 | |||
| 205 | static inline int __fscrypt_prepare_lookup(struct inode *dir, | ||
| 206 | struct dentry *dentry) | ||
| 207 | { | ||
| 208 | return -EOPNOTSUPP; | ||
| 209 | } | ||
| 210 | |||
| 178 | #endif /* _LINUX_FSCRYPT_NOTSUPP_H */ | 211 | #endif /* _LINUX_FSCRYPT_NOTSUPP_H */ |
diff --git a/include/linux/fscrypt_supp.h b/include/linux/fscrypt_supp.h index 5153dce22f09..cf9e9fc02f0a 100644 --- a/include/linux/fscrypt_supp.h +++ b/include/linux/fscrypt_supp.h | |||
| @@ -2,14 +2,15 @@ | |||
| 2 | /* | 2 | /* |
| 3 | * fscrypt_supp.h | 3 | * fscrypt_supp.h |
| 4 | * | 4 | * |
| 5 | * This is included by filesystems configured with encryption support. | 5 | * Do not include this file directly. Use fscrypt.h instead! |
| 6 | */ | 6 | */ |
| 7 | #ifndef _LINUX_FSCRYPT_H | ||
| 8 | #error "Incorrect include of linux/fscrypt_supp.h!" | ||
| 9 | #endif | ||
| 7 | 10 | ||
| 8 | #ifndef _LINUX_FSCRYPT_SUPP_H | 11 | #ifndef _LINUX_FSCRYPT_SUPP_H |
| 9 | #define _LINUX_FSCRYPT_SUPP_H | 12 | #define _LINUX_FSCRYPT_SUPP_H |
| 10 | 13 | ||
| 11 | #include <linux/fscrypt_common.h> | ||
| 12 | |||
| 13 | /* crypto.c */ | 14 | /* crypto.c */ |
| 14 | extern struct kmem_cache *fscrypt_info_cachep; | 15 | extern struct kmem_cache *fscrypt_info_cachep; |
| 15 | extern struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *, gfp_t); | 16 | extern struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *, gfp_t); |
| @@ -143,4 +144,14 @@ extern void fscrypt_pullback_bio_page(struct page **, bool); | |||
| 143 | extern int fscrypt_zeroout_range(const struct inode *, pgoff_t, sector_t, | 144 | extern int fscrypt_zeroout_range(const struct inode *, pgoff_t, sector_t, |
| 144 | unsigned int); | 145 | unsigned int); |
| 145 | 146 | ||
| 147 | /* hooks.c */ | ||
| 148 | extern int fscrypt_file_open(struct inode *inode, struct file *filp); | ||
| 149 | extern int __fscrypt_prepare_link(struct inode *inode, struct inode *dir); | ||
| 150 | extern int __fscrypt_prepare_rename(struct inode *old_dir, | ||
| 151 | struct dentry *old_dentry, | ||
| 152 | struct inode *new_dir, | ||
| 153 | struct dentry *new_dentry, | ||
| 154 | unsigned int flags); | ||
| 155 | extern int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry); | ||
| 156 | |||
| 146 | #endif /* _LINUX_FSCRYPT_SUPP_H */ | 157 | #endif /* _LINUX_FSCRYPT_SUPP_H */ |
