summaryrefslogtreecommitdiffstats
path: root/fs/f2fs/f2fs.h
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@kernel.org>2015-05-15 19:26:10 -0400
committerJaegeuk Kim <jaegeuk@kernel.org>2016-03-18 00:19:33 -0400
commit0b81d0779072696371822e5ed9e7c6292e547024 (patch)
treec75412a642ee596fd33a392f0f353c4c1185f7f5 /fs/f2fs/f2fs.h
parent59692b7c71e4271b62bddce5bfd50b9e805a4a02 (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.h172
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 */
269struct f2fs_str {
270 unsigned char *name;
271 u32 len;
272};
273
274struct 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
288struct f2fs_dentry_ptr { 267struct 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
426struct f2fs_inode_info { 396struct 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
456static inline void get_extent_info(struct extent_info *ext, 420static inline void get_extent_info(struct extent_info *ext,
@@ -1741,10 +1705,10 @@ struct dentry *f2fs_get_parent(struct dentry *child);
1741extern unsigned char f2fs_filetype_table[F2FS_FT_MAX]; 1705extern unsigned char f2fs_filetype_table[F2FS_FT_MAX];
1742void set_de_type(struct f2fs_dir_entry *, umode_t); 1706void set_de_type(struct f2fs_dir_entry *, umode_t);
1743 1707
1744struct f2fs_dir_entry *find_target_dentry(struct f2fs_filename *, 1708struct 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 *);
1746bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, 1710bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *,
1747 unsigned int, struct f2fs_str *); 1711 unsigned int, struct fscrypt_str *);
1748void do_make_empty_dir(struct inode *, struct inode *, 1712void do_make_empty_dir(struct inode *, struct inode *,
1749 struct f2fs_dentry_ptr *); 1713 struct f2fs_dentry_ptr *);
1750struct page *init_inode_metadata(struct inode *, struct inode *, 1714struct page *init_inode_metadata(struct inode *, struct inode *,
@@ -2120,7 +2084,7 @@ int f2fs_convert_inline_inode(struct inode *);
2120int f2fs_write_inline_data(struct inode *, struct page *); 2084int f2fs_write_inline_data(struct inode *, struct page *);
2121bool recover_inline_data(struct inode *, struct page *); 2085bool recover_inline_data(struct inode *, struct page *);
2122struct f2fs_dir_entry *find_in_inline_dir(struct inode *, 2086struct f2fs_dir_entry *find_in_inline_dir(struct inode *,
2123 struct f2fs_filename *, struct page **); 2087 struct fscrypt_name *, struct page **);
2124struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **); 2088struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **);
2125int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *); 2089int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *);
2126int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *, 2090int 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 *);
2130bool f2fs_empty_inline_dir(struct inode *); 2094bool f2fs_empty_inline_dir(struct inode *);
2131int f2fs_read_inline_dir(struct file *, struct dir_context *, 2095int f2fs_read_inline_dir(struct file *, struct dir_context *,
2132 struct f2fs_str *); 2096 struct fscrypt_str *);
2133int f2fs_inline_data_fiemap(struct inode *, 2097int 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 */
2162static inline int f2fs_encrypted_inode(struct inode *inode) 2126static 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
2171static inline void f2fs_set_encrypted_inode(struct inode *inode) 2131static 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
2178static inline bool f2fs_bio_encrypted(struct bio *bio) 2138static 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
2187static inline int f2fs_sb_has_crypto(struct super_block *sb) 2143static 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
2196static inline bool f2fs_may_encrypt(struct inode *inode) 2148static 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
2208int 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
2210int f2fs_inherit_context(struct inode *, struct inode *, struct page *); 2162#define fscrypt_release_ctx fscrypt_notsupp_release_ctx
2211int f2fs_process_policy(const struct f2fs_encryption_policy *, struct inode *); 2163#define fscrypt_encrypt_page fscrypt_notsupp_encrypt_page
2212int 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
2215extern struct kmem_cache *f2fs_crypt_info_cachep; 2167#define fscrypt_restore_control_page fscrypt_notsupp_restore_control_page
2216bool f2fs_valid_contents_enc_mode(uint32_t); 2168#define fscrypt_zeroout_range fscrypt_notsupp_zeroout_range
2217uint32_t f2fs_validate_encryption_key_size(uint32_t, uint32_t); 2169#define fscrypt_process_policy fscrypt_notsupp_process_policy
2218struct f2fs_crypto_ctx *f2fs_get_crypto_ctx(struct inode *); 2170#define fscrypt_get_policy fscrypt_notsupp_get_policy
2219void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *); 2171#define fscrypt_has_permitted_context fscrypt_notsupp_has_permitted_context
2220struct page *f2fs_encrypt(struct inode *, struct page *); 2172#define fscrypt_inherit_context fscrypt_notsupp_inherit_context
2221int f2fs_decrypt(struct page *); 2173#define fscrypt_get_encryption_info fscrypt_notsupp_get_encryption_info
2222void 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
2225void f2fs_free_encryption_info(struct inode *, struct f2fs_crypt_info *); 2177#define fscrypt_fname_encrypted_size fscrypt_notsupp_fname_encrypted_size
2226int _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
2229bool f2fs_valid_filenames_enc_mode(uint32_t); 2181#define fscrypt_fname_usr_to_disk fscrypt_notsupp_fname_usr_to_disk
2230u32 f2fs_fname_crypto_round_up(u32, u32);
2231unsigned f2fs_fname_encrypted_size(struct inode *, u32);
2232int f2fs_fname_crypto_alloc_buffer(struct inode *, u32, struct f2fs_str *);
2233int f2fs_fname_disk_to_usr(struct inode *, f2fs_hash_t *,
2234 const struct f2fs_str *, struct f2fs_str *);
2235int f2fs_fname_usr_to_disk(struct inode *, const struct qstr *,
2236 struct f2fs_str *);
2237
2238#ifdef CONFIG_F2FS_FS_ENCRYPTION
2239void f2fs_restore_and_release_control_page(struct page **);
2240void f2fs_restore_control_page(struct page *);
2241
2242int __init f2fs_init_crypto(void);
2243int f2fs_crypto_initialize(void);
2244void f2fs_exit_crypto(void);
2245
2246int f2fs_has_encryption_key(struct inode *);
2247
2248static 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
2261void f2fs_fname_crypto_free_buffer(struct f2fs_str *);
2262int f2fs_fname_setup_filename(struct inode *, const struct qstr *,
2263 int lookup, struct f2fs_filename *);
2264void f2fs_fname_free_filename(struct f2fs_filename *);
2265#else
2266static inline void f2fs_restore_and_release_control_page(struct page **p) { }
2267static inline void f2fs_restore_control_page(struct page *p) { }
2268
2269static inline int __init f2fs_init_crypto(void) { return 0; }
2270static inline void f2fs_exit_crypto(void) { }
2271
2272static inline int f2fs_has_encryption_key(struct inode *i) { return 0; }
2273static inline int f2fs_get_encryption_info(struct inode *i) { return 0; }
2274static inline void f2fs_fname_crypto_free_buffer(struct f2fs_str *p) { }
2275
2276static 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
2287static inline void f2fs_fname_free_filename(struct f2fs_filename *fname) { }
2288#endif 2182#endif
2289#endif 2183#endif