diff options
author | Jaegeuk Kim <jaegeuk@kernel.org> | 2015-05-15 19:26:10 -0400 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2016-03-18 00:19:33 -0400 |
commit | 0b81d0779072696371822e5ed9e7c6292e547024 (patch) | |
tree | c75412a642ee596fd33a392f0f353c4c1185f7f5 /fs/f2fs/f2fs.h | |
parent | 59692b7c71e4271b62bddce5bfd50b9e805a4a02 (diff) |
fs crypto: move per-file encryption from f2fs tree to fs/crypto
This patch adds the renamed functions moved from the f2fs crypto files.
1. definitions for per-file encryption used by ext4 and f2fs.
2. crypto.c for encrypt/decrypt functions
a. IO preparation:
- fscrypt_get_ctx / fscrypt_release_ctx
b. before IOs:
- fscrypt_encrypt_page
- fscrypt_decrypt_page
- fscrypt_zeroout_range
c. after IOs:
- fscrypt_decrypt_bio_pages
- fscrypt_pullback_bio_page
- fscrypt_restore_control_page
3. policy.c supporting context management.
a. For ioctls:
- fscrypt_process_policy
- fscrypt_get_policy
b. For context permission
- fscrypt_has_permitted_context
- fscrypt_inherit_context
4. keyinfo.c to handle permissions
- fscrypt_get_encryption_info
- fscrypt_free_encryption_info
5. fname.c to support filename encryption
a. general wrapper functions
- fscrypt_fname_disk_to_usr
- fscrypt_fname_usr_to_disk
- fscrypt_setup_filename
- fscrypt_free_filename
b. specific filename handling functions
- fscrypt_fname_alloc_buffer
- fscrypt_fname_free_buffer
6. Makefile and Kconfig
Cc: Al Viro <viro@ftp.linux.org.uk>
Signed-off-by: Michael Halcrow <mhalcrow@google.com>
Signed-off-by: Ildar Muslukhov <ildarm@google.com>
Signed-off-by: Uday Savagaonkar <savagaon@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs/f2fs.h')
-rw-r--r-- | fs/f2fs/f2fs.h | 172 |
1 files changed, 33 insertions, 139 deletions
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index ffd03363989b..6447e9002807 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/vmalloc.h> | 22 | #include <linux/vmalloc.h> |
23 | #include <linux/bio.h> | 23 | #include <linux/bio.h> |
24 | #include <linux/blkdev.h> | 24 | #include <linux/blkdev.h> |
25 | #include <linux/fscrypto.h> | ||
25 | 26 | ||
26 | #ifdef CONFIG_F2FS_CHECK_FS | 27 | #ifdef CONFIG_F2FS_CHECK_FS |
27 | #define f2fs_bug_on(sbi, condition) BUG_ON(condition) | 28 | #define f2fs_bug_on(sbi, condition) BUG_ON(condition) |
@@ -231,12 +232,9 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal, | |||
231 | #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) | 232 | #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) |
232 | #define F2FS_IOC_DEFRAGMENT _IO(F2FS_IOCTL_MAGIC, 8) | 233 | #define F2FS_IOC_DEFRAGMENT _IO(F2FS_IOCTL_MAGIC, 8) |
233 | 234 | ||
234 | #define F2FS_IOC_SET_ENCRYPTION_POLICY \ | 235 | #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY |
235 | _IOR('f', 19, struct f2fs_encryption_policy) | 236 | #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY |
236 | #define F2FS_IOC_GET_ENCRYPTION_PWSALT \ | 237 | #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT |
237 | _IOW('f', 20, __u8[16]) | ||
238 | #define F2FS_IOC_GET_ENCRYPTION_POLICY \ | ||
239 | _IOW('f', 21, struct f2fs_encryption_policy) | ||
240 | 238 | ||
241 | /* | 239 | /* |
242 | * should be same as XFS_IOC_GOINGDOWN. | 240 | * should be same as XFS_IOC_GOINGDOWN. |
@@ -266,25 +264,6 @@ struct f2fs_defragment { | |||
266 | * For INODE and NODE manager | 264 | * For INODE and NODE manager |
267 | */ | 265 | */ |
268 | /* for directory operations */ | 266 | /* for directory operations */ |
269 | struct f2fs_str { | ||
270 | unsigned char *name; | ||
271 | u32 len; | ||
272 | }; | ||
273 | |||
274 | struct f2fs_filename { | ||
275 | const struct qstr *usr_fname; | ||
276 | struct f2fs_str disk_name; | ||
277 | f2fs_hash_t hash; | ||
278 | #ifdef CONFIG_F2FS_FS_ENCRYPTION | ||
279 | struct f2fs_str crypto_buf; | ||
280 | #endif | ||
281 | }; | ||
282 | |||
283 | #define FSTR_INIT(n, l) { .name = n, .len = l } | ||
284 | #define FSTR_TO_QSTR(f) QSTR_INIT((f)->name, (f)->len) | ||
285 | #define fname_name(p) ((p)->disk_name.name) | ||
286 | #define fname_len(p) ((p)->disk_name.len) | ||
287 | |||
288 | struct f2fs_dentry_ptr { | 267 | struct f2fs_dentry_ptr { |
289 | struct inode *inode; | 268 | struct inode *inode; |
290 | const void *bitmap; | 269 | const void *bitmap; |
@@ -412,15 +391,6 @@ struct f2fs_map_blocks { | |||
412 | #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) | 391 | #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) |
413 | #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) | 392 | #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) |
414 | 393 | ||
415 | /* Encryption algorithms */ | ||
416 | #define F2FS_ENCRYPTION_MODE_INVALID 0 | ||
417 | #define F2FS_ENCRYPTION_MODE_AES_256_XTS 1 | ||
418 | #define F2FS_ENCRYPTION_MODE_AES_256_GCM 2 | ||
419 | #define F2FS_ENCRYPTION_MODE_AES_256_CBC 3 | ||
420 | #define F2FS_ENCRYPTION_MODE_AES_256_CTS 4 | ||
421 | |||
422 | #include "f2fs_crypto.h" | ||
423 | |||
424 | #define DEF_DIR_LEVEL 0 | 394 | #define DEF_DIR_LEVEL 0 |
425 | 395 | ||
426 | struct f2fs_inode_info { | 396 | struct f2fs_inode_info { |
@@ -444,13 +414,7 @@ struct f2fs_inode_info { | |||
444 | struct list_head dirty_list; /* linked in global dirty list */ | 414 | struct list_head dirty_list; /* linked in global dirty list */ |
445 | struct list_head inmem_pages; /* inmemory pages managed by f2fs */ | 415 | struct list_head inmem_pages; /* inmemory pages managed by f2fs */ |
446 | struct mutex inmem_lock; /* lock for inmemory pages */ | 416 | struct mutex inmem_lock; /* lock for inmemory pages */ |
447 | |||
448 | struct extent_tree *extent_tree; /* cached extent_tree entry */ | 417 | struct extent_tree *extent_tree; /* cached extent_tree entry */ |
449 | |||
450 | #ifdef CONFIG_F2FS_FS_ENCRYPTION | ||
451 | /* Encryption params */ | ||
452 | struct f2fs_crypt_info *i_crypt_info; | ||
453 | #endif | ||
454 | }; | 418 | }; |
455 | 419 | ||
456 | static inline void get_extent_info(struct extent_info *ext, | 420 | static inline void get_extent_info(struct extent_info *ext, |
@@ -1741,10 +1705,10 @@ struct dentry *f2fs_get_parent(struct dentry *child); | |||
1741 | extern unsigned char f2fs_filetype_table[F2FS_FT_MAX]; | 1705 | extern unsigned char f2fs_filetype_table[F2FS_FT_MAX]; |
1742 | void set_de_type(struct f2fs_dir_entry *, umode_t); | 1706 | void set_de_type(struct f2fs_dir_entry *, umode_t); |
1743 | 1707 | ||
1744 | struct f2fs_dir_entry *find_target_dentry(struct f2fs_filename *, | 1708 | struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *, |
1745 | f2fs_hash_t, int *, struct f2fs_dentry_ptr *); | 1709 | f2fs_hash_t, int *, struct f2fs_dentry_ptr *); |
1746 | bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, | 1710 | bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, |
1747 | unsigned int, struct f2fs_str *); | 1711 | unsigned int, struct fscrypt_str *); |
1748 | void do_make_empty_dir(struct inode *, struct inode *, | 1712 | void do_make_empty_dir(struct inode *, struct inode *, |
1749 | struct f2fs_dentry_ptr *); | 1713 | struct f2fs_dentry_ptr *); |
1750 | struct page *init_inode_metadata(struct inode *, struct inode *, | 1714 | struct page *init_inode_metadata(struct inode *, struct inode *, |
@@ -2120,7 +2084,7 @@ int f2fs_convert_inline_inode(struct inode *); | |||
2120 | int f2fs_write_inline_data(struct inode *, struct page *); | 2084 | int f2fs_write_inline_data(struct inode *, struct page *); |
2121 | bool recover_inline_data(struct inode *, struct page *); | 2085 | bool recover_inline_data(struct inode *, struct page *); |
2122 | struct f2fs_dir_entry *find_in_inline_dir(struct inode *, | 2086 | struct f2fs_dir_entry *find_in_inline_dir(struct inode *, |
2123 | struct f2fs_filename *, struct page **); | 2087 | struct fscrypt_name *, struct page **); |
2124 | struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **); | 2088 | struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **); |
2125 | int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *); | 2089 | int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *); |
2126 | int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *, | 2090 | int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *, |
@@ -2129,7 +2093,7 @@ void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *, | |||
2129 | struct inode *, struct inode *); | 2093 | struct inode *, struct inode *); |
2130 | bool f2fs_empty_inline_dir(struct inode *); | 2094 | bool f2fs_empty_inline_dir(struct inode *); |
2131 | int f2fs_read_inline_dir(struct file *, struct dir_context *, | 2095 | int f2fs_read_inline_dir(struct file *, struct dir_context *, |
2132 | struct f2fs_str *); | 2096 | struct fscrypt_str *); |
2133 | int f2fs_inline_data_fiemap(struct inode *, | 2097 | int f2fs_inline_data_fiemap(struct inode *, |
2134 | struct fiemap_extent_info *, __u64, __u64); | 2098 | struct fiemap_extent_info *, __u64, __u64); |
2135 | 2099 | ||
@@ -2159,13 +2123,9 @@ void destroy_extent_cache(void); | |||
2159 | /* | 2123 | /* |
2160 | * crypto support | 2124 | * crypto support |
2161 | */ | 2125 | */ |
2162 | static inline int f2fs_encrypted_inode(struct inode *inode) | 2126 | static inline bool f2fs_encrypted_inode(struct inode *inode) |
2163 | { | 2127 | { |
2164 | #ifdef CONFIG_F2FS_FS_ENCRYPTION | ||
2165 | return file_is_encrypt(inode); | 2128 | return file_is_encrypt(inode); |
2166 | #else | ||
2167 | return 0; | ||
2168 | #endif | ||
2169 | } | 2129 | } |
2170 | 2130 | ||
2171 | static inline void f2fs_set_encrypted_inode(struct inode *inode) | 2131 | static inline void f2fs_set_encrypted_inode(struct inode *inode) |
@@ -2177,20 +2137,12 @@ static inline void f2fs_set_encrypted_inode(struct inode *inode) | |||
2177 | 2137 | ||
2178 | static inline bool f2fs_bio_encrypted(struct bio *bio) | 2138 | static inline bool f2fs_bio_encrypted(struct bio *bio) |
2179 | { | 2139 | { |
2180 | #ifdef CONFIG_F2FS_FS_ENCRYPTION | 2140 | return bio->bi_private != NULL; |
2181 | return unlikely(bio->bi_private != NULL); | ||
2182 | #else | ||
2183 | return false; | ||
2184 | #endif | ||
2185 | } | 2141 | } |
2186 | 2142 | ||
2187 | static inline int f2fs_sb_has_crypto(struct super_block *sb) | 2143 | static inline int f2fs_sb_has_crypto(struct super_block *sb) |
2188 | { | 2144 | { |
2189 | #ifdef CONFIG_F2FS_FS_ENCRYPTION | ||
2190 | return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); | 2145 | return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); |
2191 | #else | ||
2192 | return 0; | ||
2193 | #endif | ||
2194 | } | 2146 | } |
2195 | 2147 | ||
2196 | static inline bool f2fs_may_encrypt(struct inode *inode) | 2148 | static inline bool f2fs_may_encrypt(struct inode *inode) |
@@ -2204,86 +2156,28 @@ static inline bool f2fs_may_encrypt(struct inode *inode) | |||
2204 | #endif | 2156 | #endif |
2205 | } | 2157 | } |
2206 | 2158 | ||
2207 | /* crypto_policy.c */ | 2159 | #ifndef CONFIG_F2FS_FS_ENCRYPTION |
2208 | int f2fs_is_child_context_consistent_with_parent(struct inode *, | 2160 | #define fscrypt_set_d_op(i) |
2209 | struct inode *); | 2161 | #define fscrypt_get_ctx fscrypt_notsupp_get_ctx |
2210 | int f2fs_inherit_context(struct inode *, struct inode *, struct page *); | 2162 | #define fscrypt_release_ctx fscrypt_notsupp_release_ctx |
2211 | int f2fs_process_policy(const struct f2fs_encryption_policy *, struct inode *); | 2163 | #define fscrypt_encrypt_page fscrypt_notsupp_encrypt_page |
2212 | int f2fs_get_policy(struct inode *, struct f2fs_encryption_policy *); | 2164 | #define fscrypt_decrypt_page fscrypt_notsupp_decrypt_page |
2213 | 2165 | #define fscrypt_decrypt_bio_pages fscrypt_notsupp_decrypt_bio_pages | |
2214 | /* crypt.c */ | 2166 | #define fscrypt_pullback_bio_page fscrypt_notsupp_pullback_bio_page |
2215 | extern struct kmem_cache *f2fs_crypt_info_cachep; | 2167 | #define fscrypt_restore_control_page fscrypt_notsupp_restore_control_page |
2216 | bool f2fs_valid_contents_enc_mode(uint32_t); | 2168 | #define fscrypt_zeroout_range fscrypt_notsupp_zeroout_range |
2217 | uint32_t f2fs_validate_encryption_key_size(uint32_t, uint32_t); | 2169 | #define fscrypt_process_policy fscrypt_notsupp_process_policy |
2218 | struct f2fs_crypto_ctx *f2fs_get_crypto_ctx(struct inode *); | 2170 | #define fscrypt_get_policy fscrypt_notsupp_get_policy |
2219 | void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *); | 2171 | #define fscrypt_has_permitted_context fscrypt_notsupp_has_permitted_context |
2220 | struct page *f2fs_encrypt(struct inode *, struct page *); | 2172 | #define fscrypt_inherit_context fscrypt_notsupp_inherit_context |
2221 | int f2fs_decrypt(struct page *); | 2173 | #define fscrypt_get_encryption_info fscrypt_notsupp_get_encryption_info |
2222 | void f2fs_end_io_crypto_work(struct f2fs_crypto_ctx *, struct bio *); | 2174 | #define fscrypt_put_encryption_info fscrypt_notsupp_put_encryption_info |
2223 | 2175 | #define fscrypt_setup_filename fscrypt_notsupp_setup_filename | |
2224 | /* crypto_key.c */ | 2176 | #define fscrypt_free_filename fscrypt_notsupp_free_filename |
2225 | void f2fs_free_encryption_info(struct inode *, struct f2fs_crypt_info *); | 2177 | #define fscrypt_fname_encrypted_size fscrypt_notsupp_fname_encrypted_size |
2226 | int _f2fs_get_encryption_info(struct inode *inode); | 2178 | #define fscrypt_fname_alloc_buffer fscrypt_notsupp_fname_alloc_buffer |
2227 | 2179 | #define fscrypt_fname_free_buffer fscrypt_notsupp_fname_free_buffer | |
2228 | /* crypto_fname.c */ | 2180 | #define fscrypt_fname_disk_to_usr fscrypt_notsupp_fname_disk_to_usr |
2229 | bool f2fs_valid_filenames_enc_mode(uint32_t); | 2181 | #define fscrypt_fname_usr_to_disk fscrypt_notsupp_fname_usr_to_disk |
2230 | u32 f2fs_fname_crypto_round_up(u32, u32); | ||
2231 | unsigned f2fs_fname_encrypted_size(struct inode *, u32); | ||
2232 | int f2fs_fname_crypto_alloc_buffer(struct inode *, u32, struct f2fs_str *); | ||
2233 | int f2fs_fname_disk_to_usr(struct inode *, f2fs_hash_t *, | ||
2234 | const struct f2fs_str *, struct f2fs_str *); | ||
2235 | int f2fs_fname_usr_to_disk(struct inode *, const struct qstr *, | ||
2236 | struct f2fs_str *); | ||
2237 | |||
2238 | #ifdef CONFIG_F2FS_FS_ENCRYPTION | ||
2239 | void f2fs_restore_and_release_control_page(struct page **); | ||
2240 | void f2fs_restore_control_page(struct page *); | ||
2241 | |||
2242 | int __init f2fs_init_crypto(void); | ||
2243 | int f2fs_crypto_initialize(void); | ||
2244 | void f2fs_exit_crypto(void); | ||
2245 | |||
2246 | int f2fs_has_encryption_key(struct inode *); | ||
2247 | |||
2248 | static inline int f2fs_get_encryption_info(struct inode *inode) | ||
2249 | { | ||
2250 | struct f2fs_crypt_info *ci = F2FS_I(inode)->i_crypt_info; | ||
2251 | |||
2252 | if (!ci || | ||
2253 | (ci->ci_keyring_key && | ||
2254 | (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) | | ||
2255 | (1 << KEY_FLAG_REVOKED) | | ||
2256 | (1 << KEY_FLAG_DEAD))))) | ||
2257 | return _f2fs_get_encryption_info(inode); | ||
2258 | return 0; | ||
2259 | } | ||
2260 | |||
2261 | void f2fs_fname_crypto_free_buffer(struct f2fs_str *); | ||
2262 | int f2fs_fname_setup_filename(struct inode *, const struct qstr *, | ||
2263 | int lookup, struct f2fs_filename *); | ||
2264 | void f2fs_fname_free_filename(struct f2fs_filename *); | ||
2265 | #else | ||
2266 | static inline void f2fs_restore_and_release_control_page(struct page **p) { } | ||
2267 | static inline void f2fs_restore_control_page(struct page *p) { } | ||
2268 | |||
2269 | static inline int __init f2fs_init_crypto(void) { return 0; } | ||
2270 | static inline void f2fs_exit_crypto(void) { } | ||
2271 | |||
2272 | static inline int f2fs_has_encryption_key(struct inode *i) { return 0; } | ||
2273 | static inline int f2fs_get_encryption_info(struct inode *i) { return 0; } | ||
2274 | static inline void f2fs_fname_crypto_free_buffer(struct f2fs_str *p) { } | ||
2275 | |||
2276 | static inline int f2fs_fname_setup_filename(struct inode *dir, | ||
2277 | const struct qstr *iname, | ||
2278 | int lookup, struct f2fs_filename *fname) | ||
2279 | { | ||
2280 | memset(fname, 0, sizeof(struct f2fs_filename)); | ||
2281 | fname->usr_fname = iname; | ||
2282 | fname->disk_name.name = (unsigned char *)iname->name; | ||
2283 | fname->disk_name.len = iname->len; | ||
2284 | return 0; | ||
2285 | } | ||
2286 | |||
2287 | static inline void f2fs_fname_free_filename(struct f2fs_filename *fname) { } | ||
2288 | #endif | 2182 | #endif |
2289 | #endif | 2183 | #endif |