Inline Encryption Support for fscrypt
Subsystems (5)
v4 cover Inline Encryption Support for fscrypt
This patch series adds support for Inline Encryption to fscrypt, f2fs and ext4. It builds on the inline encryption support now present in the block layer, and has been rebased on v5.8-rc3. Note that Patches 1 and 2 can be applied independently of Patches 3 and 4 (and Patches 3 and 4 can be applied independently of each other).
This patch series previously went though a number of iterations as part of the "Inline Encryption Support" patchset (last version was v13:
https://lkml.kernel.org/r/[email protected]).
Patch 1 introduces the SB_INLINECRYPT sb options, which filesystems should set if they want to use blk-crypto for file content en/decryption.
Patch 2 adds inline encryption support to fscrypt. To use inline encryption with fscrypt, the filesystem must set the above mentioned SB_INLINECRYPT sb option. When this option is set, the contents of encrypted files will be en/decrypted using blk-crypto.
Patches 3 and 4 wire up f2fs and ext4 respectively to fscrypt support for inline encryption, and e.g ensure that bios are submitted with blocks that not only are contiguous, but also have continuous DUNs.
This patchset was tested by running xfstests with the "inlinecrypt" mount option on ext4 and f2fs with test dummy encryption (the actual en/decryption of file contents was handled by the blk-crypto-fallback). It was also tested along with the UFS patches from the original series on some Qualcomm and Mediatek chipsets with hardware inline encryption support (refer to
https://lkml.kernel.org/linux-scsi/[email protected]/
and
https://lkml.kernel.org/linux-scsi/[email protected]/
for more details on those tests).
Changes v3 => v4
- change the page_is_mergeable() check in add_ipu_page() to an f2fs_bug_on since the only caller of add_ipu_page() already checks page_is_mergeable
- add reviewed by
Changes v2 => v3
- Fix issue with inline encryption + IV_INO_LBLK_32 policy found by Eric
- minor cleanup
Changes v1 => v2
- SB_INLINECRYPT mount option is shown by individual filesystems instead of by the common VFS code since the option is parsed by filesystem specific code, and is not a mount option applicable generically to all filesystems.
- Make fscrypt_select_encryption_impl() return error code when it fails to allocate memory.
- cleanups
Changes v13 in original patchset => v1
- rename struct fscrypt_info::ci_key to ci_enc_key
- set dun bytes more precisely in fscrypt
- cleanups
Eric Biggers (1):
ext4: add inline encryption support
Satya Tangirala (3):
fs: introduce SB_INLINECRYPT
fscrypt: add inline encryption support
f2fs: add inline encryption support
Documentation/admin-guide/ext4.rst | 7 + Documentation/filesystems/f2fs.rst | 7 + Documentation/filesystems/fscrypt.rst | 3 + fs/buffer.c | 7 +- fs/crypto/Kconfig | 6 + fs/crypto/Makefile | 1 + fs/crypto/bio.c | 51 ++++ fs/crypto/crypto.c | 2 +- fs/crypto/fname.c | 4 +- fs/crypto/fscrypt_private.h | 115 +++++++- fs/crypto/inline_crypt.c | 364 ++++++++++++++++++++++++++ fs/crypto/keyring.c | 6 +- fs/crypto/keysetup.c | 70 +++-- fs/crypto/keysetup_v1.c | 16 +- fs/ext4/inode.c | 4 +- fs/ext4/page-io.c | 6 +- fs/ext4/readpage.c | 11 +- fs/ext4/super.c | 12 + fs/f2fs/compress.c | 2 +- fs/f2fs/data.c | 79 +++++- fs/f2fs/super.c | 35 +++ include/linux/fs.h | 1 + include/linux/fscrypt.h | 82 ++++++ 23 files changed, 820 insertions(+), 71 deletions(-) create mode 100644 fs/crypto/inline_crypt.c
Signature · 1 line
2.27.0.212.ge8ba1cc988-goog
PATCH v4 1/4 fs: introduce SB_INLINECRYPT
Introduce SB_INLINECRYPT, which is set by filesystems that wish to use blk-crypto for file content en/decryption. This flag maps to the '-o inlinecrypt' mount option which multiple filesystems will implement, and code in fs/crypto/ needs to be able to check for this mount option in a filesystem-independent way.
--- include/linux/fs.h | 1 + 1 file changed, 1 insertion(+)
include/linux/fs.h +1 -0
@@ -1380,6 +1380,7 @@ extern int send_sigurg(struct fown_struct *fown);#define SB_NODIRATIME 2048/* Do not update directory access times */ #define SB_SILENT 32768#define SB_POSIXACL (1<<16)/* VFS does not apply the umask */ +#define SB_INLINECRYPT (1<<17)/* Use blk-crypto for encrypted files */ #define SB_KERNMOUNT (1<<22)/* this is a kern_mount call */ #define SB_I_VERSION (1<<23)/* Update inode I_version field */ #define SB_LAZYTIME (1<<25)/* Update the on-disk [acm]times lazily */
Signature · 1 line
2.27.0.212.ge8ba1cc988-goog
Re: [PATCH v4 1/4] fs: introduce SB_INLINECRYPT
Quoted 8 lines · Satya Tangirala
Introduce
SB_INLINECRYPT, which is set by filesystems that wish to use blk-crypto for file content en/decryption. This flag maps to the '-o inlinecrypt' mount option which multiple filesystems will implement, and code infs/crypto/needs to be able to check for this mount option in a filesystem-independent way.Signed-off-by Satya Tangirala <[email protected]>Reviewed-by Eric Biggers <[email protected]>
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH v4 2/4 fscrypt: add inline encryption support
In reply to Satya TangiralaAdd support for inline encryption to fs/crypto/. With "inline encryption", the block layer handles the decryption/encryption as part of the bio, instead of the filesystem doing the crypto itself via Linux's crypto API. This model is needed in order to take advantage of the inline encryption hardware present on most modern mobile SoCs.
To use inline encryption, the filesystem needs to be mounted with '-o inlinecrypt'. Blk-crypto will then be used instead of the traditional filesystem-layer crypto whenever possible to encrypt the contents of any encrypted files in that filesystem. Fscrypt still provides the key and IV to use, and the actual ciphertext on-disk is still the same; therefore it's testable using the existing fscrypt ciphertext verification tests.
Note that since blk-crypto has a fallback to Linux's crypto API, and also supports all the encryption modes currently supported by fscrypt, this feature is usable and testable even without actual inline encryption hardware.
Per-filesystem changes will be needed to set encryption contexts when submitting bios and to implement the 'inlinecrypt' mount option. This patch just adds the common code.
--- Documentation/filesystems/fscrypt.rst | 3 + fs/crypto/Kconfig | 6 + fs/crypto/Makefile | 1 + fs/crypto/bio.c | 51 ++++ fs/crypto/crypto.c | 2 +- fs/crypto/fname.c | 4 +- fs/crypto/fscrypt_private.h | 115 +++++++- fs/crypto/inline_crypt.c | 364 ++++++++++++++++++++++++++ fs/crypto/keyring.c | 6 +- fs/crypto/keysetup.c | 70 +++-- fs/crypto/keysetup_v1.c | 16 +- include/linux/fscrypt.h | 82 ++++++ 12 files changed, 673 insertions(+), 47 deletions(-) create mode 100644 fs/crypto/inline_crypt.c
Documentation/filesystems/fscrypt.rst +3 -0
@@ -1255,6 +1255,7 @@ f2fs encryption using `kvm-xfstests <https://github.com/tytso/xfstests-bld/blob/master/Documentation/kvm-quickstart.md>`_:: kvm-xfstests -c ext4,f2fs -g encrypt + kvm-xfstests -c ext4,f2fs -g encrypt -m inlinecrypt UBIFS encryption can also be tested this way, but it should be done in a separate command, and it takes some time for kvm-xfstests to set up
@@ -1276,6 +1277,7 @@ This tests the encrypted I/O paths more thoroughly. To do this with kvm-xfstests, use the "encrypt" filesystem configuration:: kvm-xfstests -c ext4/encrypt,f2fs/encrypt -g auto + kvm-xfstests -c ext4/encrypt,f2fs/encrypt -g auto -m inlinecrypt Because this runs many more tests than "-g encrypt" does, it takes much longer to run; so also consider using `gce-xfstests
@@ -1283,3 +1285,4 @@ much longer to run; so also consider using `gce-xfstests instead of kvm-xfstests:: gce-xfstests -c ext4/encrypt,f2fs/encrypt -g auto + gce-xfstests -c ext4/encrypt,f2fs/encrypt -g auto -m inlinecrypt
fs/crypto/Kconfig +6 -0
@@ -24,3 +24,9 @@ config FS_ENCRYPTION_ALGS select CRYPTO_SHA256 select CRYPTO_SHA512 select CRYPTO_XTS + +config FS_ENCRYPTION_INLINE_CRYPT + bool "Enable fscrypt to use inline crypto" + depends on FS_ENCRYPTION && BLK_INLINE_ENCRYPTION + help + Enable fscrypt to use inline encryption hardware if available.
fs/crypto/Makefile +1 -0
@@ -11,3 +11,4 @@ fscrypto-y := crypto.o \ policy.o fscrypto-$(CONFIG_BLOCK) += bio.o +fscrypto-$(CONFIG_FS_ENCRYPTION_INLINE_CRYPT) += inline_crypt.o
fs/crypto/bio.c +51 -0
63 lines not on this page · raw message
fs/crypto/crypto.c +1 -1
@@ -100,7 +100,7 @@ int fscrypt_crypt_block(const struct inode *inode, fscrypt_direction_t rw,DECLARE_CRYPTO_WAIT (wait);struct scatterlist dst, src;struct fscrypt_info *ci = inode->i_crypt_info; -struct crypto_skcipher *tfm = ci->ci_ctfm; +struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;int res =0 ;if (WARN_ON_ONCE (len <=0 ))
fs/crypto/fname.c +2 -2
@@ -115,7 +115,7 @@ int fscrypt_fname_encrypt(const struct inode *inode, const struct qstr *iname,struct skcipher_request *req =NULL ;DECLARE_CRYPTO_WAIT (wait);const struct fscrypt_info *ci = inode->i_crypt_info; -struct crypto_skcipher *tfm = ci->ci_ctfm; +struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;union fscrypt_iv iv;struct scatterlist sg;int res;
@@ -171,7 +171,7 @@ static int fname_decrypt(const struct inode *inode,DECLARE_CRYPTO_WAIT (wait);struct scatterlist src_sg, dst_sg;const struct fscrypt_info *ci = inode->i_crypt_info; -struct crypto_skcipher *tfm = ci->ci_ctfm; +struct crypto_skcipher *tfm = ci->ci_enc_key.tfm;union fscrypt_iv iv;int res;
fs/crypto/fscrypt_private.h +105 -10
170 lines not on this page · raw message
fs/crypto/inline_crypt.c new file +364 -0
364 lines not on this page · raw message
fs/crypto/keyring.c +3 -3
@@ -45,9 +45,9 @@ static void free_master_key(struct fscrypt_master_key *mk)wipe_master_key_secret (&mk->mk_secret);for (i =0 ; i <= __FSCRYPT_MODE_MAX; i++) { -crypto_free_skcipher (mk->mk_direct_keys[i]); -crypto_free_skcipher (mk->mk_iv_ino_lblk_64_keys[i]); -crypto_free_skcipher (mk->mk_iv_ino_lblk_32_keys[i]); +fscrypt_destroy_prepared_key (&mk->mk_direct_keys[i]); +fscrypt_destroy_prepared_key (&mk->mk_iv_ino_lblk_64_keys[i]); +fscrypt_destroy_prepared_key (&mk->mk_iv_ino_lblk_32_keys[i]); }key_put (mk->mk_users);
fs/crypto/keysetup.c +48 -22
150 lines not on this page · raw message
fs/crypto/keysetup_v1.c +7 -9
@@ -146,7 +146,7 @@ struct fscrypt_direct_key {struct hlist_node dk_node;refcount_t dk_refcount;const struct fscrypt_mode *dk_mode; -struct crypto_skcipher *dk_ctfm; +struct fscrypt_prepared_key dk_key;u8 dk_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE ];u8 dk_raw[FSCRYPT_MAX_KEY_SIZE ]; };
@@ -154,7 +154,7 @@ struct fscrypt_direct_key {static void free_direct_key (struct fscrypt_direct_key *dk) {if (dk) { -crypto_free_skcipher (dk->dk_ctfm); +fscrypt_destroy_prepared_key (&dk->dk_key);kzfree (dk); } }
@@ -199,6 +199,8 @@ find_or_insert_direct_key(struct fscrypt_direct_key *to_insert,continue ;if (ci->ci_mode != dk->dk_mode)continue ; +if (!fscrypt_is_key_prepared (&dk->dk_key, ci)) +continue ;if (crypto_memneq (raw_key, dk->dk_raw, ci->ci_mode->keysize))continue ;/* using existing tfm with same (descriptor, mode, raw_key) */
@@ -231,13 +233,9 @@ fscrypt_get_direct_key(const struct fscrypt_info *ci, const u8 *raw_key)return ERR_PTR (-ENOMEM );refcount_set (&dk->dk_refcount,1 ); dk->dk_mode = ci->ci_mode; - dk->dk_ctfm =fscrypt_allocate_skcipher (ci->ci_mode, raw_key, - ci->ci_inode); -if (IS_ERR (dk->dk_ctfm)) { - err =PTR_ERR (dk->dk_ctfm); - dk->dk_ctfm =NULL ; + err =fscrypt_prepare_key (&dk->dk_key, raw_key, ci); +if (err) goto err_free_dk; - }memcpy (dk->dk_descriptor, ci->ci_policy.v1.master_key_descriptor,FSCRYPT_KEY_DESCRIPTOR_SIZE );memcpy (dk->dk_raw, raw_key, ci->ci_mode->keysize);
@@ -259,7 +257,7 @@ static int setup_v1_file_key_direct(struct fscrypt_info *ci,if (IS_ERR (dk))return PTR_ERR (dk); ci->ci_direct_key = dk; - ci->ci_ctfm = dk->dk_ctfm; + ci->ci_enc_key = dk->dk_key;return 0 ; }
include/linux/fscrypt.h +82 -0
94 lines not on this page · raw message
Signature · 1 line
2.27.0.212.ge8ba1cc988-goog
Re: [PATCH v4 2/4] fscrypt: add inline encryption support
Quoted 23 lines · Satya Tangirala
Add support for inline encryption to
fs/crypto/. With "inline encryption", the block layer handles the decryption/encryption as part of the bio, instead of the filesystem doing the crypto itself via Linux's crypto API. This model is needed in order to take advantage of the inline encryption hardware present on most modern mobile SoCs.To use inline encryption, the filesystem needs to be mounted with '-o inlinecrypt'. Blk-crypto will then be used instead of the traditional filesystem-layer crypto whenever possible to encrypt the contents of any encrypted files in that filesystem. Fscrypt still provides the key and IV to use, and the actual ciphertext on-disk is still the same; therefore it's testable using the existing fscrypt ciphertext verification tests.
Note that since blk-crypto has a fallback to Linux's crypto API, and also supports all the encryption modes currently supported by fscrypt, this feature is usable and testable even without actual inline encryption hardware.
Per-filesystem changes will be needed to set encryption contexts when submitting bios and to implement the 'inlinecrypt' mount option. This patch just adds the common code.
Quoted 5 lines
Co-developed-by Eric Biggers <[email protected]>Signed-off-by Eric Biggers <[email protected]>Signed-off-by Satya Tangirala <[email protected]>Reviewed-by Jaegeuk Kim <[email protected]>Reviewed-by Eric Biggers <[email protected]>
PATCH v4 3/4 f2fs: add inline encryption support
In reply to Satya TangiralaWire up f2fs to support inline encryption via the helper functions which fs/crypto/ now provides. This includes:
- Adding a mount option 'inlinecrypt' which enables inline encryption on encrypted files where it can be used.
- Setting the bio_crypt_ctx on bios that will be submitted to an inline-encrypted file.
- Not adding logically discontiguous data to bios that will be submitted to an inline-encrypted file.
- Not doing filesystem-layer crypto on inline-encrypted files.
This patch includes a fix for a race during IPU by Sahitya Tummala <[email protected]>
--- Documentation/filesystems/f2fs.rst | 7 +++ fs/f2fs/compress.c | 2 +- fs/f2fs/data.c | 79 +++++++++++++++++++++++++----- fs/f2fs/super.c | 35 +++++++++++++ 4 files changed, 109 insertions(+), 14 deletions(-)
Documentation/filesystems/f2fs.rst +7 -0
@@ -258,6 +258,13 @@ compress_extension=%s Support adding specified extension, so that f2fs can enab on compression extension list and enable compression on these file by default rather than to enable it via ioctl. For other files, we can still enable compression via ioctl. +inlinecrypt + When possible, encrypt/decrypt the contents of encrypted + files using the blk-crypto framework rather than + filesystem-layer encryption. This allows the use of + inline encryption hardware. The on-disk format is + unaffected. For more details, see + Documentation/block/inline-encryption.rst. ====================== ============================================================ Debugfs Entries
fs/f2fs/compress.c +1 -1
@@ -1086,7 +1086,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc, .submitted = false, .io_type = io_type, .io_wbc = wbc, - .encrypted = f2fs_encrypted_file(cc->inode), + .encrypted = fscrypt_inode_uses_fs_layer_crypto(cc->inode), };struct dnode_of_data dn;struct node_info ni;
fs/f2fs/data.c +66 -13
171 lines not on this page · raw message
fs/f2fs/super.c +35 -0
@@ -138,6 +138,7 @@ enum { Opt_alloc, Opt_fsync, Opt_test_dummy_encryption, + Opt_inlinecrypt, Opt_checkpoint_disable, Opt_checkpoint_disable_cap, Opt_checkpoint_disable_cap_perc,
@@ -204,6 +205,7 @@ static match_table_t f2fs_tokens = { {Opt_fsync, "fsync_mode=%s"}, {Opt_test_dummy_encryption, "test_dummy_encryption=%s"}, {Opt_test_dummy_encryption, "test_dummy_encryption"}, + {Opt_inlinecrypt, "inlinecrypt"}, {Opt_checkpoint_disable, "checkpoint=disable"}, {Opt_checkpoint_disable_cap, "checkpoint=disable:%u"}, {Opt_checkpoint_disable_cap_perc, "checkpoint=disable:%u%%"},
@@ -833,6 +835,13 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)if (ret)return ret;break ; +case Opt_inlinecrypt: +#ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT + sb->s_flags |=SB_INLINECRYPT ; +#else +f2fs_info (sbi,"inline encryption not supported" ); +#endif +break ;case Opt_checkpoint_disable_cap_perc:if (args->from &&match_int (args, &arg))return -EINVAL ;
@@ -1590,6 +1599,9 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)fscrypt_show_test_dummy_encryption (seq,',' , sbi->sb); +if (sbi->sb->s_flags &SB_INLINECRYPT ) +seq_puts (seq,",inlinecrypt" ); +if (F2FS_OPTION (sbi).alloc_mode ==ALLOC_MODE_DEFAULT )seq_printf (seq,",alloc_mode=%s" ,"default" );else if (F2FS_OPTION (sbi).alloc_mode ==ALLOC_MODE_REUSE )
@@ -1624,6 +1636,8 @@ static void default_options(struct f2fs_sb_info *sbi)F2FS_OPTION (sbi).compress_ext_cnt =0 ;F2FS_OPTION (sbi).bggc_mode =BGGC_MODE_ON ; + sbi->sb->s_flags &= ~SB_INLINECRYPT ; +set_opt (sbi,INLINE_XATTR );set_opt (sbi,INLINE_DATA );set_opt (sbi,INLINE_DENTRY );
@@ -2470,6 +2484,25 @@ static void f2fs_get_ino_and_lblk_bits(struct super_block *sb, *lblk_bits_ret =8 *sizeof (block_t); } +static int f2fs_get_num_devices (struct super_block *sb) +{ +struct f2fs_sb_info *sbi =F2FS_SB (sb); + +if (f2fs_is_multi_device (sbi)) +return sbi->s_ndevs; +return 1 ; +} + +static void f2fs_get_devices (struct super_block *sb, +struct request_queue **devs) +{ +struct f2fs_sb_info *sbi =F2FS_SB (sb); +int i; + +for (i =0 ; i < sbi->s_ndevs; i++) + devs[i] =bdev_get_queue (FDEV (i).bdev); +} +static const struct fscrypt_operations f2fs_cryptops = { .key_prefix ="f2fs:" , .get_context = f2fs_get_context,
@@ -2479,6 +2512,8 @@ static const struct fscrypt_operations f2fs_cryptops = { .max_namelen = F2FS_NAME_LEN, .has_stable_inodes = f2fs_has_stable_inodes, .get_ino_and_lblk_bits = f2fs_get_ino_and_lblk_bits, + .get_num_devices = f2fs_get_num_devices, + .get_devices = f2fs_get_devices, };#endif
Signature · 1 line
2.27.0.212.ge8ba1cc988-goog
PATCH v4 4/4 ext4: add inline encryption support
In reply to Satya TangiralaFrom: Eric Biggers <[email protected]>
Wire up ext4 to support inline encryption via the helper functions which fs/crypto/ now provides. This includes:
- Adding a mount option 'inlinecrypt' which enables inline encryption on encrypted files where it can be used.
- Setting the bio_crypt_ctx on bios that will be submitted to an inline-encrypted file.
Note: submit_bh_wbc() in fs/buffer.c also needed to be patched for this part, since ext4 sometimes uses ll_rw_block() on file data.
- Not adding logically discontiguous data to bios that will be submitted to an inline-encrypted file.
- Not doing filesystem-layer crypto on inline-encrypted files.
--- Documentation/admin-guide/ext4.rst | 7 +++++++ fs/buffer.c | 7 ++++--- fs/ext4/inode.c | 4 ++-- fs/ext4/page-io.c | 6 ++++-- fs/ext4/readpage.c | 11 ++++++++--- fs/ext4/super.c | 12 ++++++++++++ 6 files changed, 37 insertions(+), 10 deletions(-)
Documentation/admin-guide/ext4.rst +7 -0
@@ -395,6 +395,13 @@ When mounting an ext4 filesystem, the following option are accepted: Documentation/filesystems/dax.txt. Note that this option is incompatible with data=journal. + inlinecrypt + When possible, encrypt/decrypt the contents of encrypted files using the + blk-crypto framework rather than filesystem-layer encryption. This + allows the use of inline encryption hardware. The on-disk format is + unaffected. For more details, see + Documentation/block/inline-encryption.rst. + Data Mode ========= There are 3 different data modes:
fs/buffer.c +4 -3
@@ -320,9 +320,8 @@ static void decrypt_bh(struct work_struct *work)static void end_buffer_async_read_io (struct buffer_head *bh,int uptodate) {/* Decrypt if needed */ -if (uptodate &&IS_ENABLED (CONFIG_FS_ENCRYPTION ) && -IS_ENCRYPTED (bh->b_page->mapping->host) && -S_ISREG (bh->b_page->mapping->host->i_mode)) { +if (uptodate && +fscrypt_inode_uses_fs_layer_crypto (bh->b_page->mapping->host)) {struct decrypt_bh_ctx *ctx =kmalloc (sizeof (*ctx),GFP_ATOMIC );if (ctx) {
@@ -3046,6 +3045,8 @@ static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,*/ bio =bio_alloc (GFP_NOIO ,1 ); +fscrypt_set_bio_crypt_ctx_bh (bio, bh,GFP_NOIO ); + bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >>9 );bio_set_dev (bio, bh->b_bdev); bio->bi_write_hint = write_hint;
fs/ext4/inode.c +2 -2
@@ -1096,7 +1096,7 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len, }if (unlikely (err)) {page_zero_new_buffers (page, from, to); - }else if (IS_ENCRYPTED (inode) &&S_ISREG (inode->i_mode)) { + }else if (fscrypt_inode_uses_fs_layer_crypto (inode)) {for (i =0 ; i < nr_wait; i++) {int err2;
@@ -3737,7 +3737,7 @@ static int __ext4_block_zero_page_range(handle_t *handle,/* Uhhuh. Read error. Complain and punt. */ if (!buffer_uptodate (bh)) goto unlock; -if (S_ISREG (inode->i_mode) &&IS_ENCRYPTED (inode)) { +if (fscrypt_inode_uses_fs_layer_crypto (inode)) {/* We expect the key to be set. */ BUG_ON (!fscrypt_has_encryption_key (inode)); err = fscrypt_decrypt_pagecache_blocks(page, blocksize,
fs/ext4/page-io.c +4 -2
@@ -402,6 +402,7 @@ static void io_submit_init_bio(struct ext4_io_submit *io,* __GFP_DIRECT_RECLAIM is set, see comments for bio_alloc_bioset(). */ bio =bio_alloc (GFP_NOIO ,BIO_MAX_PAGES ); +fscrypt_set_bio_crypt_ctx_bh (bio, bh,GFP_NOIO ); bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >>9 );bio_set_dev (bio, bh->b_bdev); bio->bi_end_io = ext4_end_bio;
@@ -418,7 +419,8 @@ static void io_submit_add_bh(struct ext4_io_submit *io, {int ret; -if (io->io_bio && bh->b_blocknr != io->io_next_block) { +if (io->io_bio && (bh->b_blocknr != io->io_next_block || + !fscrypt_mergeable_bio_bh (io->io_bio, bh))) { submit_and_retry:ext4_io_submit (io); }
@@ -506,7 +508,7 @@ int ext4_bio_write_page(struct ext4_io_submit *io,* (e.g. holes) to be unnecessarily encrypted, but this is rare and * can't happen in the common case of blocksize == PAGE_SIZE. */ -if (IS_ENCRYPTED (inode) &&S_ISREG (inode->i_mode) && nr_to_submit) { +if (fscrypt_inode_uses_fs_layer_crypto (inode) && nr_to_submit) {gfp_t gfp_flags =GFP_NOFS ;unsigned int enc_bytes =round_up (len,i_blocksize (inode));
fs/ext4/readpage.c +8 -3
@@ -195,7 +195,7 @@ static void ext4_set_bio_post_read_ctx(struct bio *bio, {unsigned int post_read_steps =0 ; -if (IS_ENCRYPTED (inode) &&S_ISREG (inode->i_mode)) +if (fscrypt_inode_uses_fs_layer_crypto (inode)) post_read_steps |=1 <<STEP_DECRYPT ;if (ext4_need_verity (inode, first_idx))
@@ -230,6 +230,7 @@ int ext4_mpage_readpages(struct inode *inode,const unsigned blkbits = inode->i_blkbits;const unsigned blocks_per_page =PAGE_SIZE >> blkbits;const unsigned blocksize =1 << blkbits; +sector_t next_block;sector_t block_in_file;sector_t last_block;sector_t last_block_in_file;
@@ -258,7 +259,8 @@ int ext4_mpage_readpages(struct inode *inode,if (page_has_buffers (page)) goto confused; - block_in_file = (sector_t )page->index << (PAGE_SHIFT - blkbits); + block_in_file = next_block = + (sector_t )page->index << (PAGE_SHIFT - blkbits); last_block = block_in_file + nr_pages * blocks_per_page; last_block_in_file = (ext4_readpage_limit (inode) + blocksize -1 ) >> blkbits;
@@ -358,7 +360,8 @@ int ext4_mpage_readpages(struct inode *inode,* This page will go to BIO. Do we need to send this * BIO off first? */ -if (bio && (last_block_in_bio != blocks[0 ] -1 )) { +if (bio && (last_block_in_bio != blocks[0 ] -1 || + !fscrypt_mergeable_bio (bio, inode, next_block))) { submit_and_realloc:submit_bio (bio); bio =NULL ;
@@ -370,6 +373,8 @@ int ext4_mpage_readpages(struct inode *inode,*/ bio =bio_alloc (GFP_KERNEL ,min_t (int, nr_pages,BIO_MAX_PAGES )); +fscrypt_set_bio_crypt_ctx (bio, inode, next_block, +GFP_KERNEL );ext4_set_bio_post_read_ctx (bio, inode, page->index);bio_set_dev (bio, bdev); bio->bi_iter.bi_sector = blocks[0 ] << (blkbits -9 );
fs/ext4/super.c +12 -0
@@ -1508,6 +1508,7 @@ enum { Opt_journal_path, Opt_journal_checksum, Opt_journal_async_commit, Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback, Opt_data_err_abort, Opt_data_err_ignore, Opt_test_dummy_encryption, + Opt_inlinecrypt, Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota, Opt_noquota, Opt_barrier, Opt_nobarrier, Opt_err,
@@ -1610,6 +1611,7 @@ static const match_table_t tokens = { {Opt_max_dir_size_kb, "max_dir_size_kb=%u"}, {Opt_test_dummy_encryption, "test_dummy_encryption=%s"}, {Opt_test_dummy_encryption, "test_dummy_encryption"}, + {Opt_inlinecrypt, "inlinecrypt"}, {Opt_nombcache, "nombcache"}, {Opt_nombcache, "no_mbcache"}, /* for backward compatibility */ {Opt_removed, "check=none"}, /* mount option from ext2/3 */
@@ -1946,6 +1948,13 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,case Opt_nolazytime: sb->s_flags &= ~SB_LAZYTIME ;return 1 ; +case Opt_inlinecrypt: +#ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT + sb->s_flags |=SB_INLINECRYPT ; +#else +ext4_msg (sb,KERN_ERR ,"inline encryption not supported" ); +#endif +return 1 ; }for (m = ext4_mount_opts; m->token != Opt_err; m++)
@@ -2404,6 +2413,9 @@ static int _ext4_show_options(struct seq_file *seq, struct super_block *sb,fscrypt_show_test_dummy_encryption (seq, sep, sb); +if (sb->s_flags &SB_INLINECRYPT ) +SEQ_OPTS_PUTS ("inlinecrypt" ); +if (test_opt (sb,DAX_ALWAYS )) {if (IS_EXT2_SB (sb))SEQ_OPTS_PUTS ("dax" );
Signature · 1 line
2.27.0.212.ge8ba1cc988-goog
Re: [PATCH v4 4/4] ext4: add inline encryption support
Quoted 14 lines · Satya Tangirala
From: Eric Biggers <[email protected]>
Wire up ext4 to support inline encryption via the helper functions which
fs/crypto/now provides. This includes:- Adding a mount option 'inlinecrypt' which enables inline encryption on encrypted files where it can be used.
- Setting the
bio_crypt_ctxon bios that will be submitted to an inline-encrypted file.Note:
submit_bh_wbc()infs/buffer.calso needed to be patched for this part, since ext4 sometimes usesll_rw_block()on file data.
Quoted 8 lines
- Not adding logically discontiguous data to bios that will be submitted to an inline-encrypted file.
- Not doing filesystem-layer crypto on inline-encrypted files.
Signed-off-by Eric Biggers <[email protected]>Co-developed-by Satya Tangirala <[email protected]>Signed-off-by Satya Tangirala <[email protected]>
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Eric Biggers
maintainerRe: [PATCH v4 4/4] ext4: add inline encryption support
Quoted 18 lines · On Wed, Jul 08, 2020 at 01:18:12PM -0400, [email protected] wrote:
Quoted 17 lines · Satya Tangirala
From: Eric Biggers <[email protected]>
Wire up ext4 to support inline encryption via the helper functions which
fs/crypto/now provides. This includes:- Adding a mount option 'inlinecrypt' which enables inline encryption on encrypted files where it can be used.
- Setting the
bio_crypt_ctxon bios that will be submitted to an inline-encrypted file.Note:
submit_bh_wbc()infs/buffer.calso needed to be patched for this part, since ext4 sometimes usesll_rw_block()on file data.- Not adding logically discontiguous data to bios that will be submitted to an inline-encrypted file.
Quoted 8 lines
Quoted 5 lines
- Not doing filesystem-layer crypto on inline-encrypted files.
Signed-off-by Eric Biggers <[email protected]>Co-developed-by Satya Tangirala <[email protected]>Signed-off-by Satya Tangirala <[email protected]>Reviewed-by Theodore Ts'o <[email protected]>
Thanks Ted. I've applied this patch to fscrypt.git#master for 5.9.
- Eric
Quoted 13 lines · Satya Tangirala
This patch series adds support for Inline Encryption to fscrypt, f2fs and ext4. It builds on the inline encryption support now present in the block layer, and has been rebased on v5.8-rc3. Note that Patches 1 and 2 can be applied independently of Patches 3 and 4 (and Patches 3 and 4 can be applied independently of each other).
This patch series previously went though a number of iterations as part of the "Inline Encryption Support" patchset (last version was v13:
https://lkml.kernel.org/r/[email protected]).Patch 1 introduces the
SB_INLINECRYPTsb options, which filesystems should set if they want to use blk-crypto for file content en/decryption.
Quoted 8 lines
Patch 2 adds inline encryption support to fscrypt. To use inline encryption with fscrypt, the filesystem must set the above mentioned
SB_INLINECRYPTsb option. When this option is set, the contents of encrypted files will be en/decrypted using blk-crypto.Patches 3 and 4 wire up f2fs and ext4 respectively to fscrypt support for inline encryption, and e.g ensure that bios are submitted with blocks that not only are contiguous, but also have continuous DUNs.
I've applied patches 1-3 to fscrypt.git#master for 5.9. Any additional reviews are still appreciated though.
Ted and Andreas, can I get your Acked-by on patch 4?
- Eric