* [PATCH 2/3] ext4 crypto: initialize crypto memory in early stage @ 2015-05-12 21:21 Jaegeuk Kim 2015-05-12 21:21 ` [PATCH 3/3] ext4 crypto: use inode number for xts_tweak Jaegeuk Kim 0 siblings, 1 reply; 3+ messages in thread From: Jaegeuk Kim @ 2015-05-12 21:21 UTC (permalink / raw) To: linux-ext4, Theodore Ts'o; +Cc: Jaegeuk Kim Previously, crypto initialization was done at the first readpage time. It'd need to avoid large memory allocation at run time. Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> --- fs/ext4/crypto.c | 2 +- fs/ext4/crypto_key.c | 6 ------ fs/ext4/ext4.h | 4 ++-- fs/ext4/super.c | 8 ++++++++ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c index 04c620f..f265c08 100644 --- a/fs/ext4/crypto.c +++ b/fs/ext4/crypto.c @@ -256,7 +256,7 @@ void ext4_exit_crypto(void) * * Return: Zero on success, non-zero otherwise. */ -int ext4_init_crypto(void) +int __init ext4_init_crypto(void) { int i, res = -ENOMEM; diff --git a/fs/ext4/crypto_key.c b/fs/ext4/crypto_key.c index 858d7d6..fb957ab 100644 --- a/fs/ext4/crypto_key.c +++ b/fs/ext4/crypto_key.c @@ -113,12 +113,6 @@ int _ext4_get_encryption_info(struct inode *inode) struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); int res; - if (!ext4_read_workqueue) { - res = ext4_init_crypto(); - if (res) - return res; - } - if (ei->i_crypt_info) { if (!ei->i_crypt_info->ci_keyring_key || key_validate(ei->i_crypt_info->ci_keyring_key) == 0) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 505bc66..3b5dd12 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2073,14 +2073,14 @@ int ext4_decrypt_one(struct inode *inode, struct page *page); int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex); #ifdef CONFIG_EXT4_FS_ENCRYPTION -int ext4_init_crypto(void); +int __init ext4_init_crypto(void); void ext4_exit_crypto(void); static inline int ext4_sb_has_crypto(struct super_block *sb) { return EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_ENCRYPT); } #else -static inline int ext4_init_crypto(void) { return 0; } +static inline int __init ext4_init_crypto(void) { return 0; } static inline void ext4_exit_crypto(void) { } static inline int ext4_sb_has_crypto(struct super_block *sb) { diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 79311e0..411a8a3 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5611,6 +5611,11 @@ static int __init ext4_init_fs(void) err = init_inodecache(); if (err) goto out1; + + err = ext4_init_crypto(); + if (err) + goto out0; + register_as_ext3(); register_as_ext2(); err = register_filesystem(&ext4_fs_type); @@ -5621,6 +5626,8 @@ static int __init ext4_init_fs(void) out: unregister_as_ext2(); unregister_as_ext3(); + ext4_exit_crypto(); +out0: destroy_inodecache(); out1: ext4_mballoc_ready = 0; @@ -5646,6 +5653,7 @@ static void __exit ext4_exit_fs(void) ext4_destroy_lazyinit_thread(); unregister_as_ext2(); unregister_as_ext3(); + ext4_exit_crypto(); unregister_filesystem(&ext4_fs_type); destroy_inodecache(); ext4_exit_mballoc(); -- 2.1.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 3/3] ext4 crypto: use inode number for xts_tweak 2015-05-12 21:21 [PATCH 2/3] ext4 crypto: initialize crypto memory in early stage Jaegeuk Kim @ 2015-05-12 21:21 ` Jaegeuk Kim 2015-05-12 21:31 ` [PATCH 3/3 v2] " Jaegeuk Kim 0 siblings, 1 reply; 3+ messages in thread From: Jaegeuk Kim @ 2015-05-12 21:21 UTC (permalink / raw) To: linux-ext4, Theodore Ts'o; +Cc: Jaegeuk Kim This patch was from: "f2fs crypto: use inode number for xts_tweak Previoulsy when making xts_tweak, page->index was used. But, when it supports fcollapse, the block address was moved, so that we can lose the original page->index, which causes decryption failure. In order to avoid that, let's use the inode->i_ino for xfs_tweak hint." Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> --- fs/ext4/crypto.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c index f265c08..5653646 100644 --- a/fs/ext4/crypto.c +++ b/fs/ext4/crypto.c @@ -337,7 +337,6 @@ typedef enum { static int ext4_page_crypto(struct ext4_crypto_ctx *ctx, struct inode *inode, ext4_direction_t rw, - pgoff_t index, struct page *src_page, struct page *dest_page) @@ -382,10 +381,10 @@ static int ext4_page_crypto(struct ext4_crypto_ctx *ctx, req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, ext4_crypt_complete, &ecr); - BUILD_BUG_ON(EXT4_XTS_TWEAK_SIZE < sizeof(index)); - memcpy(xts_tweak, &index, sizeof(index)); - memset(&xts_tweak[sizeof(index)], 0, - EXT4_XTS_TWEAK_SIZE - sizeof(index)); + BUILD_BUG_ON(EXT4_XTS_TWEAK_SIZE < sizeof(inode->i_ino)); + memcpy(xts_tweak, &inode->i_ino, sizeof(inode->i_ino)); + memset(&xts_tweak[sizeof(inode->i_ino)], 0, + EXT4_XTS_TWEAK_SIZE - sizeof(inode->i_ino)); sg_init_table(&dst, 1); sg_set_page(&dst, dest_page, PAGE_CACHE_SIZE, 0); @@ -459,7 +458,7 @@ struct page *ext4_encrypt(struct inode *inode, ctx->flags |= EXT4_WRITE_PATH_FL; ctx->w.bounce_page = ciphertext_page; ctx->w.control_page = plaintext_page; - err = ext4_page_crypto(ctx, inode, EXT4_ENCRYPT, plaintext_page->index, + err = ext4_page_crypto(ctx, inode, EXT4_ENCRYPT, plaintext_page, ciphertext_page); if (err) { ext4_release_crypto_ctx(ctx); @@ -487,7 +486,7 @@ int ext4_decrypt(struct ext4_crypto_ctx *ctx, struct page *page) BUG_ON(!PageLocked(page)); return ext4_page_crypto(ctx, page->mapping->host, - EXT4_DECRYPT, page->index, page, page); + EXT4_DECRYPT, page, page); } /* @@ -541,7 +540,7 @@ int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex) while (len--) { err = ext4_page_crypto(ctx, inode, EXT4_ENCRYPT, lblk, - ZERO_PAGE(0), ciphertext_page); + ciphertext_page); if (err) goto errout; -- 2.1.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 3/3 v2] ext4 crypto: use inode number for xts_tweak 2015-05-12 21:21 ` [PATCH 3/3] ext4 crypto: use inode number for xts_tweak Jaegeuk Kim @ 2015-05-12 21:31 ` Jaegeuk Kim 0 siblings, 0 replies; 3+ messages in thread From: Jaegeuk Kim @ 2015-05-12 21:31 UTC (permalink / raw) To: linux-ext4, Theodore Ts'o Sorry for the noise. Chnage log from v1: - fix wrong code changes. -- >8 -- >From 2c5474450be7811d9553b3920fb0ed0681f9fddd Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim <jaegeuk@kernel.org> Date: Tue, 12 May 2015 14:14:49 -0700 Subject: [PATCH] ext4 crypto: use inode number for xts_tweak This patch was from: "f2fs crypto: use inode number for xts_tweak Previoulsy when making xts_tweak, page->index was used. But, when it supports fcollapse, the block address was moved, so that we can lose the original page->index, which causes decryption failure. In order to avoid that, let's use the inode->i_ino for xfs_tweak hint." Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> --- fs/ext4/crypto.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c index f265c08..7ae6c3d 100644 --- a/fs/ext4/crypto.c +++ b/fs/ext4/crypto.c @@ -337,7 +337,6 @@ typedef enum { static int ext4_page_crypto(struct ext4_crypto_ctx *ctx, struct inode *inode, ext4_direction_t rw, - pgoff_t index, struct page *src_page, struct page *dest_page) @@ -382,10 +381,10 @@ static int ext4_page_crypto(struct ext4_crypto_ctx *ctx, req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, ext4_crypt_complete, &ecr); - BUILD_BUG_ON(EXT4_XTS_TWEAK_SIZE < sizeof(index)); - memcpy(xts_tweak, &index, sizeof(index)); - memset(&xts_tweak[sizeof(index)], 0, - EXT4_XTS_TWEAK_SIZE - sizeof(index)); + BUILD_BUG_ON(EXT4_XTS_TWEAK_SIZE < sizeof(inode->i_ino)); + memcpy(xts_tweak, &inode->i_ino, sizeof(inode->i_ino)); + memset(&xts_tweak[sizeof(inode->i_ino)], 0, + EXT4_XTS_TWEAK_SIZE - sizeof(inode->i_ino)); sg_init_table(&dst, 1); sg_set_page(&dst, dest_page, PAGE_CACHE_SIZE, 0); @@ -459,7 +458,7 @@ struct page *ext4_encrypt(struct inode *inode, ctx->flags |= EXT4_WRITE_PATH_FL; ctx->w.bounce_page = ciphertext_page; ctx->w.control_page = plaintext_page; - err = ext4_page_crypto(ctx, inode, EXT4_ENCRYPT, plaintext_page->index, + err = ext4_page_crypto(ctx, inode, EXT4_ENCRYPT, plaintext_page, ciphertext_page); if (err) { ext4_release_crypto_ctx(ctx); @@ -487,7 +486,7 @@ int ext4_decrypt(struct ext4_crypto_ctx *ctx, struct page *page) BUG_ON(!PageLocked(page)); return ext4_page_crypto(ctx, page->mapping->host, - EXT4_DECRYPT, page->index, page, page); + EXT4_DECRYPT, page, page); } /* @@ -512,7 +511,6 @@ int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex) struct ext4_crypto_ctx *ctx; struct page *ciphertext_page = NULL; struct bio *bio; - ext4_lblk_t lblk = ex->ee_block; ext4_fsblk_t pblk = ext4_ext_pblock(ex); unsigned int len = ext4_ext_get_actual_len(ex); int err = 0; @@ -540,7 +538,7 @@ int ext4_encrypted_zeroout(struct inode *inode, struct ext4_extent *ex) ctx->w.bounce_page = ciphertext_page; while (len--) { - err = ext4_page_crypto(ctx, inode, EXT4_ENCRYPT, lblk, + err = ext4_page_crypto(ctx, inode, EXT4_ENCRYPT, ZERO_PAGE(0), ciphertext_page); if (err) goto errout; -- 2.1.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-05-12 21:31 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-05-12 21:21 [PATCH 2/3] ext4 crypto: initialize crypto memory in early stage Jaegeuk Kim 2015-05-12 21:21 ` [PATCH 3/3] ext4 crypto: use inode number for xts_tweak Jaegeuk Kim 2015-05-12 21:31 ` [PATCH 3/3 v2] " Jaegeuk Kim
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).