History

fscrypt: remove filesystem specific build config option

In order to have a common code base for fscrypt "post read" processing for all filesystems which support encryption, this commit removes filesystem specific build config option (e.g. CONFIG_EXT4_FS_ENCRYPTION) and replaces it with a build option (i.e. CONFIG_FS_ENCRYPTION) whose value affects all the filesystems making use of fscrypt.

Chandan Rajendra committed 7 years ago

Commit 643fa961 parent 62230e031 files · +460 −535Browse files

Unified · Split

31 files
  1. Documentation/filesystems/fscrypt.rst +2 −2
  2. arch/mips/configs/generic_defconfig +1 −1
  3. arch/nds32/configs/defconfig +1 −1
  4. arch/s390/configs/debug_defconfig +1 −1
  5. arch/s390/configs/performance_defconfig +1 −1
  6. fs/crypto/Kconfig +3 −2
  7. fs/crypto/fscrypt_private.h +0 −1
  8. fs/ext4/Kconfig +0 −15
  9. fs/ext4/dir.c +0 −2
  10. fs/ext4/ext4.h +3 −4
  11. fs/ext4/inode.c +4 −4
  12. fs/ext4/ioctl.c +2 −2
  13. fs/ext4/namei.c +5 −5
  14. fs/ext4/page-io.c +3 −3
  15. fs/ext4/readpage.c +1 −1
  16. fs/ext4/super.c +3 −3
  17. fs/ext4/sysfs.c +2 −2
  18. fs/f2fs/Kconfig +1 −11
  19. fs/f2fs/f2fs.h +3 −4
  20. fs/f2fs/super.c +4 −4
  21. fs/f2fs/sysfs.c +2 −2
  22. fs/ubifs/Kconfig +1 −11
  23. fs/ubifs/Makefile +1 −1
  24. fs/ubifs/ioctl.c +2 −2
  25. fs/ubifs/sb.c +1 −1
  26. fs/ubifs/super.c +1 −1
  27. fs/ubifs/ubifs.h +2 −3
  28. include/linux/fs.h +2 −2
  29. include/linux/fscrypt.h +408 −8
  30. include/linux/fscrypt_notsupp.h +0 −231
  31. include/linux/fscrypt_supp.h +0 −204
Documentation/filesystems/fscrypt.rst+2−2
@@ -343,9 +343,9 @@ FS_IOC_SET_ENCRYPTION_POLICY can fail with the following errors: · 342 unmodified lines
343343 - ``ENOTEMPTY``: the file is unencrypted and is a nonempty directory
344344 - ``ENOTTY``: this type of filesystem does not implement encryption
345345 - ``EOPNOTSUPP``: the kernel was not configured with encryption
346− support for this filesystem, or the filesystem superblock has not
346+ support for filesystems, or the filesystem superblock has not
347347 had encryption enabled on it. (For example, to use encryption on an
348− ext4 filesystem, CONFIG_EXT4_ENCRYPTION must be enabled in the
348+ ext4 filesystem, CONFIG_FS_ENCRYPTION must be enabled in the
349349 kernel config, and the superblock must have had the "encrypt"
350350 feature flag enabled using ``tune2fs -O encrypt`` or ``mkfs.ext4 -O
351351 encrypt``.)
arch/mips/configs/generic_defconfig+1−1
@@ -59,7 +59,7 @@ CONFIG_HID_MONTEREY=y · 58 unmodified lines
5959 CONFIG_EXT4_FS=y
6060 CONFIG_EXT4_FS_POSIX_ACL=y
6161 CONFIG_EXT4_FS_SECURITY=y
62−CONFIG_EXT4_ENCRYPTION=y
62+CONFIG_FS_ENCRYPTION=y
6363 CONFIG_FANOTIFY=y
6464 CONFIG_FUSE_FS=y
6565 CONFIG_CUSE=y
arch/nds32/configs/defconfig+1−1
@@ -74,7 +74,7 @@ CONFIG_GENERIC_PHY=y · 73 unmodified lines
7474 CONFIG_EXT4_FS=y
7575 CONFIG_EXT4_FS_POSIX_ACL=y
7676 CONFIG_EXT4_FS_SECURITY=y
77−CONFIG_EXT4_ENCRYPTION=y
77+CONFIG_FS_ENCRYPTION=y
7878 CONFIG_FUSE_FS=y
7979 CONFIG_MSDOS_FS=y
8080 CONFIG_VFAT_FS=y
arch/s390/configs/debug_defconfig+1−1
@@ -500,7 +500,6 @@ CONFIG_S390_AP_IOMMU=y · 499 unmodified lines
500500 CONFIG_EXT4_FS=y
501501 CONFIG_EXT4_FS_POSIX_ACL=y
502502 CONFIG_EXT4_FS_SECURITY=y
503−CONFIG_EXT4_ENCRYPTION=y
504503 CONFIG_JBD2_DEBUG=y
505504 CONFIG_JFS_FS=m
506505 CONFIG_JFS_POSIX_ACL=y
@@ -520,6 +519,7 @@ CONFIG_BTRFS_DEBUG=y · 13 unmodified lines
520519 CONFIG_NILFS2_FS=m
521520 CONFIG_FS_DAX=y
522521 CONFIG_EXPORTFS_BLOCK_OPS=y
522+CONFIG_FS_ENCRYPTION=y
523523 CONFIG_FANOTIFY=y
524524 CONFIG_FANOTIFY_ACCESS_PERMISSIONS=y
525525 CONFIG_QUOTA_NETLINK_INTERFACE=y
arch/s390/configs/performance_defconfig+1−1
@@ -497,7 +497,6 @@ CONFIG_S390_AP_IOMMU=y · 496 unmodified lines
497497 CONFIG_EXT4_FS=y
498498 CONFIG_EXT4_FS_POSIX_ACL=y
499499 CONFIG_EXT4_FS_SECURITY=y
500−CONFIG_EXT4_ENCRYPTION=y
501500 CONFIG_JBD2_DEBUG=y
502501 CONFIG_JFS_FS=m
503502 CONFIG_JFS_POSIX_ACL=y
@@ -515,6 +514,7 @@ CONFIG_BTRFS_FS_POSIX_ACL=y · 11 unmodified lines
515514 CONFIG_NILFS2_FS=m
516515 CONFIG_FS_DAX=y
517516 CONFIG_EXPORTFS_BLOCK_OPS=y
517+CONFIG_FS_ENCRYPTION=y
518518 CONFIG_FANOTIFY=y
519519 CONFIG_FANOTIFY_ACCESS_PERMISSIONS=y
520520 CONFIG_QUOTA_NETLINK_INTERFACE=y
fs/crypto/Kconfig+3−2
@@ -1,5 +1,5 @@
11 config FS_ENCRYPTION
2− tristate "FS Encryption (Per-file encryption)"
2+ bool "FS Encryption (Per-file encryption)"
33 select CRYPTO
44 select CRYPTO_AES
55 select CRYPTO_CBC
@@ -12,4 +12,5 @@ config FS_ENCRYPTION · 6 unmodified lines
1212 Enable encryption of files and directories. This
1313 feature is similar to ecryptfs, but it is more memory
1414 efficient since it avoids caching the encrypted and
15− decrypted pages in the page cache.
15+ decrypted pages in the page cache. Currently Ext4,
16+ F2FS and UBIFS make use of this feature.
fs/crypto/fscrypt_private.h+0−1
@@ -12,7 +12,6 @@ · 11 unmodified lines
1212 #ifndef _FSCRYPT_PRIVATE_H
1313 #define _FSCRYPT_PRIVATE_H
1414
15−#define __FS_HAS_ENCRYPTION 1
1615 #include <linux/fscrypt.h>
1716 #include <crypto/hash.h>
1817
fs/ext4/Kconfig+0−15
@@ -96,21 +96,6 @@ config EXT4_FS_SECURITY · 95 unmodified lines
9696 If you are not using a security module that requires using
9797 extended attributes for file security labels, say N.
9898
99−config EXT4_ENCRYPTION
100− bool "Ext4 Encryption"
101− depends on EXT4_FS
102− select FS_ENCRYPTION
103− help
104− Enable encryption of ext4 files and directories. This
105− feature is similar to ecryptfs, but it is more memory
106− efficient since it avoids caching the encrypted and
107− decrypted pages in the page cache.
108−
109−config EXT4_FS_ENCRYPTION
110− bool
111− default y
112− depends on EXT4_ENCRYPTION
113−
11499 config EXT4_DEBUG
115100 bool "EXT4 debugging support"
116101 depends on EXT4_FS
fs/ext4/dir.c+0−2
@@ -283,9 +283,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx) · 282 unmodified lines
283283 done:
284284 err = 0;
285285 errout:
286−#ifdef CONFIG_EXT4_FS_ENCRYPTION
287286 fscrypt_fname_free_buffer(&fstr);
288−#endif
289287 brelse(bh);
290288 return err;
291289 }
fs/ext4/ext4.h+3−4
@@ -40,7 +40,6 @@ · 39 unmodified lines
4040 #include <linux/compat.h>
4141 #endif
4242
43−#define __FS_HAS_ENCRYPTION IS_ENABLED(CONFIG_EXT4_FS_ENCRYPTION)
4443 #include <linux/fscrypt.h>
4544
4645 #include <linux/compiler.h>
@@ -1326,7 +1325,7 @@ struct ext4_super_block { · 1279 unmodified lines
13261325 #define EXT4_MF_FS_ABORTED 0x0002 /* Fatal error detected */
13271326 #define EXT4_MF_TEST_DUMMY_ENCRYPTION 0x0004
13281327
1329−#ifdef CONFIG_EXT4_FS_ENCRYPTION
1328+#ifdef CONFIG_FS_ENCRYPTION
13301329 #define DUMMY_ENCRYPTION_ENABLED(sbi) (unlikely((sbi)->s_mount_flags & \
13311330 EXT4_MF_TEST_DUMMY_ENCRYPTION))
13321331 #else
@@ -2051,7 +2050,7 @@ struct ext4_filename { · 718 unmodified lines
20512050 const struct qstr *usr_fname;
20522051 struct fscrypt_str disk_name;
20532052 struct dx_hash_info hinfo;
2054−#ifdef CONFIG_EXT4_FS_ENCRYPTION
2053+#ifdef CONFIG_FS_ENCRYPTION
20552054 struct fscrypt_str crypto_buf;
20562055 #endif
20572056 };
@@ -2279,7 +2278,7 @@ extern unsigned ext4_free_clusters_after_init(struct super_block *sb, · 221 unmodified lines
22792278 struct ext4_group_desc *gdp);
22802279 ext4_fsblk_t ext4_inode_to_goal_block(struct inode *);
22812280
2282−#ifdef CONFIG_EXT4_FS_ENCRYPTION
2281+#ifdef CONFIG_FS_ENCRYPTION
22832282 static inline int ext4_fname_setup_filename(struct inode *dir,
22842283 const struct qstr *iname,
22852284 int lookup, struct ext4_filename *fname)
fs/ext4/inode.c+4−4
@@ -1150,7 +1150,7 @@ int do_journal_get_write_access(handle_t *handle, · 1149 unmodified lines
11501150 return ret;
11511151 }
11521152
1153−#ifdef CONFIG_EXT4_FS_ENCRYPTION
1153+#ifdef CONFIG_FS_ENCRYPTION
11541154 static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len,
11551155 get_block_t *get_block)
11561156 {
@@ -1302,7 +1302,7 @@ retry_journal: · 145 unmodified lines
13021302 /* In case writeback began while the page was unlocked */
13031303 wait_for_stable_page(page);
13041304
1305−#ifdef CONFIG_EXT4_FS_ENCRYPTION
1305+#ifdef CONFIG_FS_ENCRYPTION
13061306 if (ext4_should_dioread_nolock(inode))
13071307 ret = ext4_block_write_begin(page, pos, len,
13081308 ext4_get_block_unwritten);
@@ -3104,7 +3104,7 @@ retry_journal: · 1795 unmodified lines
31043104 /* In case writeback began while the page was unlocked */
31053105 wait_for_stable_page(page);
31063106
3107−#ifdef CONFIG_EXT4_FS_ENCRYPTION
3107+#ifdef CONFIG_FS_ENCRYPTION
31083108 ret = ext4_block_write_begin(page, pos, len,
31093109 ext4_da_get_block_prep);
31103110 #else
@@ -3879,7 +3879,7 @@ static ssize_t ext4_direct_IO(struct kiocb *iocb, struct iov_iter *iter) · 768 unmodified lines
38793879 loff_t offset = iocb->ki_pos;
38803880 ssize_t ret;
38813881
3882−#ifdef CONFIG_EXT4_FS_ENCRYPTION
3882+#ifdef CONFIG_FS_ENCRYPTION
38833883 if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode))
38843884 return 0;
38853885 #endif
fs/ext4/ioctl.c+2−2
@@ -210,7 +210,7 @@ journal_err_out: · 209 unmodified lines
210210 return err;
211211 }
212212
213−#ifdef CONFIG_EXT4_FS_ENCRYPTION
213+#ifdef CONFIG_FS_ENCRYPTION
214214 static int uuid_is_zero(__u8 u[16])
215215 {
216216 int i;
@@ -978,7 +978,7 @@ resizefs_out: · 761 unmodified lines
978978 return fscrypt_ioctl_set_policy(filp, (const void __user *)arg);
979979
980980 case EXT4_IOC_GET_ENCRYPTION_PWSALT: {
981−#ifdef CONFIG_EXT4_FS_ENCRYPTION
981+#ifdef CONFIG_FS_ENCRYPTION
982982 int err, err2;
983983 struct ext4_sb_info *sbi = EXT4_SB(sb);
984984 handle_t *handle;
fs/ext4/namei.c+5−5
@@ -612,7 +612,7 @@ static struct stats dx_show_leaf(struct inode *dir, · 611 unmodified lines
612612 {
613613 if (show_names)
614614 {
615−#ifdef CONFIG_EXT4_FS_ENCRYPTION
615+#ifdef CONFIG_FS_ENCRYPTION
616616 int len;
617617 char *name;
618618 struct fscrypt_str fname_crypto_str =
@@ -984,7 +984,7 @@ static int htree_dirblock_to_tree(struct file *dir_file, · 365 unmodified lines
984984 top = (struct ext4_dir_entry_2 *) ((char *) de +
985985 dir->i_sb->s_blocksize -
986986 EXT4_DIR_REC_LEN(0));
987−#ifdef CONFIG_EXT4_FS_ENCRYPTION
987+#ifdef CONFIG_FS_ENCRYPTION
988988 /* Check if the directory is encrypted */
989989 if (IS_ENCRYPTED(dir)) {
990990 err = fscrypt_get_encryption_info(dir);
@@ -1047,7 +1047,7 @@ static int htree_dirblock_to_tree(struct file *dir_file, · 56 unmodified lines
10471047 }
10481048 errout:
10491049 brelse(bh);
1050−#ifdef CONFIG_EXT4_FS_ENCRYPTION
1050+#ifdef CONFIG_FS_ENCRYPTION
10511051 fscrypt_fname_free_buffer(&fname_crypto_str);
10521052 #endif
10531053 return count;
@@ -1267,7 +1267,7 @@ static inline bool ext4_match(const struct ext4_filename *fname, · 213 unmodified lines
12671267
12681268 f.usr_fname = fname->usr_fname;
12691269 f.disk_name = fname->disk_name;
1270−#ifdef CONFIG_EXT4_FS_ENCRYPTION
1270+#ifdef CONFIG_FS_ENCRYPTION
12711271 f.crypto_buf = fname->crypto_buf;
12721272 #endif
12731273 return fscrypt_match_name(&f, de->name, de->name_len);
@@ -1498,7 +1498,7 @@ static struct buffer_head * ext4_dx_find_entry(struct inode *dir, · 224 unmodified lines
14981498 ext4_lblk_t block;
14991499 int retval;
15001500
1501−#ifdef CONFIG_EXT4_FS_ENCRYPTION
1501+#ifdef CONFIG_FS_ENCRYPTION
15021502 *res_dir = NULL;
15031503 #endif
15041504 frame = dx_probe(fname, dir, NULL, frames);
fs/ext4/page-io.c+3−3
@@ -66,7 +66,7 @@ static void ext4_finish_bio(struct bio *bio) · 65 unmodified lines
6666
6767 bio_for_each_segment_all(bvec, bio, i) {
6868 struct page *page = bvec->bv_page;
69−#ifdef CONFIG_EXT4_FS_ENCRYPTION
69+#ifdef CONFIG_FS_ENCRYPTION
7070 struct page *data_page = NULL;
7171 #endif
7272 struct buffer_head *bh, *head;
@@ -78,7 +78,7 @@ static void ext4_finish_bio(struct bio *bio) · 5 unmodified lines
7878 if (!page)
7979 continue;
8080
81−#ifdef CONFIG_EXT4_FS_ENCRYPTION
81+#ifdef CONFIG_FS_ENCRYPTION
8282 if (!page->mapping) {
8383 /* The bounce data pages are unmapped. */
8484 data_page = page;
@@ -111,7 +111,7 @@ static void ext4_finish_bio(struct bio *bio) · 26 unmodified lines
111111 bit_spin_unlock(BH_Uptodate_Lock, &head->b_state);
112112 local_irq_restore(flags);
113113 if (!under_io) {
114−#ifdef CONFIG_EXT4_FS_ENCRYPTION
114+#ifdef CONFIG_FS_ENCRYPTION
115115 if (data_page)
116116 fscrypt_restore_control_page(data_page);
117117 #endif
fs/ext4/readpage.c+1−1
@@ -49,7 +49,7 @@ · 48 unmodified lines
4949
5050 static inline bool ext4_bio_encrypted(struct bio *bio)
5151 {
52−#ifdef CONFIG_EXT4_FS_ENCRYPTION
52+#ifdef CONFIG_FS_ENCRYPTION
5353 return unlikely(bio->bi_private != NULL);
5454 #else
5555 return false;
fs/ext4/super.c+3−3
@@ -1232,7 +1232,7 @@ static int bdev_try_to_free_page(struct super_block *sb, struct page *page, · 1231 unmodified lines
12321232 return try_to_free_buffers(page);
12331233 }
12341234
1235−#ifdef CONFIG_EXT4_FS_ENCRYPTION
1235+#ifdef CONFIG_FS_ENCRYPTION
12361236 static int ext4_get_context(struct inode *inode, void *ctx, size_t len)
12371237 {
12381238 return ext4_xattr_get(inode, EXT4_XATTR_INDEX_ENCRYPTION,
@@ -1922,7 +1922,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, · 683 unmodified lines
19221922 *journal_ioprio =
19231923 IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, arg);
19241924 } else if (token == Opt_test_dummy_encryption) {
1925−#ifdef CONFIG_EXT4_FS_ENCRYPTION
1925+#ifdef CONFIG_FS_ENCRYPTION
19261926 sbi->s_mount_flags |= EXT4_MF_TEST_DUMMY_ENCRYPTION;
19271927 ext4_msg(sb, KERN_WARNING,
19281928 "Test dummy encryption mode enabled");
@@ -4167,7 +4167,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) · 2238 unmodified lines
41674167 sb->s_op = &ext4_sops;
41684168 sb->s_export_op = &ext4_export_ops;
41694169 sb->s_xattr = ext4_xattr_handlers;
4170−#ifdef CONFIG_EXT4_FS_ENCRYPTION
4170+#ifdef CONFIG_FS_ENCRYPTION
41714171 sb->s_cop = &ext4_cryptops;
41724172 #endif
41734173 #ifdef CONFIG_QUOTA
fs/ext4/sysfs.c+2−2
@@ -224,7 +224,7 @@ static struct attribute *ext4_attrs[] = { · 223 unmodified lines
224224 EXT4_ATTR_FEATURE(lazy_itable_init);
225225 EXT4_ATTR_FEATURE(batched_discard);
226226 EXT4_ATTR_FEATURE(meta_bg_resize);
227−#ifdef CONFIG_EXT4_FS_ENCRYPTION
227+#ifdef CONFIG_FS_ENCRYPTION
228228 EXT4_ATTR_FEATURE(encryption);
229229 #endif
230230 EXT4_ATTR_FEATURE(metadata_csum_seed);
@@ -233,7 +233,7 @@ static struct attribute *ext4_feat_attrs[] = { · 2 unmodified lines
233233 ATTR_LIST(lazy_itable_init),
234234 ATTR_LIST(batched_discard),
235235 ATTR_LIST(meta_bg_resize),
236−#ifdef CONFIG_EXT4_FS_ENCRYPTION
236+#ifdef CONFIG_FS_ENCRYPTION
237237 ATTR_LIST(encryption),
238238 #endif
239239 ATTR_LIST(metadata_csum_seed),
fs/f2fs/Kconfig+1−11
@@ -3,6 +3,7 @@ config F2FS_FS · 2 unmodified lines
33 depends on BLOCK
44 select CRYPTO
55 select CRYPTO_CRC32
6+ select F2FS_FS_XATTR if FS_ENCRYPTION
67 help
78 F2FS is based on Log-structured File System (LFS), which supports
89 versatile "flash-friendly" features. The design has been focused on
@@ -70,17 +71,6 @@ config F2FS_CHECK_FS · 61 unmodified lines
7071
7172 If you want to improve the performance, say N.
7273
73−config F2FS_FS_ENCRYPTION
74− bool "F2FS Encryption"
75− depends on F2FS_FS
76− depends on F2FS_FS_XATTR
77− select FS_ENCRYPTION
78− help
79− Enable encryption of f2fs files and directories. This
80− feature is similar to ecryptfs, but it is more memory
81− efficient since it avoids caching the encrypted and
82− decrypted pages in the page cache.
83−
8474 config F2FS_IO_TRACE
8575 bool "F2FS IO tracer"
8676 depends on F2FS_FS
fs/f2fs/f2fs.h+3−4
@@ -24,7 +24,6 @@ · 23 unmodified lines
2424 #include <linux/quotaops.h>
2525 #include <crypto/hash.h>
2626
27−#define __FS_HAS_ENCRYPTION IS_ENABLED(CONFIG_F2FS_FS_ENCRYPTION)
2827 #include <linux/fscrypt.h>
2928
3029 #ifdef CONFIG_F2FS_CHECK_FS
@@ -1137,7 +1136,7 @@ enum fsync_mode { · 1106 unmodified lines
11371136 FSYNC_MODE_NOBARRIER, /* fsync behaves nobarrier based on posix */
11381137 };
11391138
1140−#ifdef CONFIG_F2FS_FS_ENCRYPTION
1139+#ifdef CONFIG_FS_ENCRYPTION
11411140 #define DUMMY_ENCRYPTION_ENABLED(sbi) \
11421141 (unlikely(F2FS_OPTION(sbi).test_dummy_encryption))
11431142 #else
@@ -3470,7 +3469,7 @@ static inline bool f2fs_encrypted_file(struct inode *inode) · 2326 unmodified lines
34703469
34713470 static inline void f2fs_set_encrypted_inode(struct inode *inode)
34723471 {
3473−#ifdef CONFIG_F2FS_FS_ENCRYPTION
3472+#ifdef CONFIG_FS_ENCRYPTION
34743473 file_set_encrypt(inode);
34753474 f2fs_set_inode_flags(inode);
34763475 #endif
@@ -3549,7 +3548,7 @@ static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) · 72 unmodified lines
35493548
35503549 static inline bool f2fs_may_encrypt(struct inode *inode)
35513550 {
3552−#ifdef CONFIG_F2FS_FS_ENCRYPTION
3551+#ifdef CONFIG_FS_ENCRYPTION
35533552 umode_t mode = inode->i_mode;
35543553
35553554 return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
fs/f2fs/super.c+4−4
@@ -757,7 +757,7 @@ static int parse_options(struct super_block *sb, char *options) · 756 unmodified lines
757757 kvfree(name);
758758 break;
759759 case Opt_test_dummy_encryption:
760−#ifdef CONFIG_F2FS_FS_ENCRYPTION
760+#ifdef CONFIG_FS_ENCRYPTION
761761 if (!f2fs_sb_has_encrypt(sbi)) {
762762 f2fs_msg(sb, KERN_ERR, "Encrypt feature is off");
763763 return -EINVAL;
@@ -1390,7 +1390,7 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root) · 626 unmodified lines
13901390 seq_printf(seq, ",whint_mode=%s", "user-based");
13911391 else if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_FS)
13921392 seq_printf(seq, ",whint_mode=%s", "fs-based");
1393−#ifdef CONFIG_F2FS_FS_ENCRYPTION
1393+#ifdef CONFIG_FS_ENCRYPTION
13941394 if (F2FS_OPTION(sbi).test_dummy_encryption)
13951395 seq_puts(seq, ",test_dummy_encryption");
13961396 #endif
@@ -2154,7 +2154,7 @@ static const struct super_operations f2fs_sops = { · 757 unmodified lines
21542154 .remount_fs = f2fs_remount,
21552155 };
21562156
2157−#ifdef CONFIG_F2FS_FS_ENCRYPTION
2157+#ifdef CONFIG_FS_ENCRYPTION
21582158 static int f2fs_get_context(struct inode *inode, void *ctx, size_t len)
21592159 {
21602160 return f2fs_getxattr(inode, F2FS_XATTR_INDEX_ENCRYPTION,
@@ -3116,7 +3116,7 @@ try_onemore: · 955 unmodified lines
31163116 #endif
31173117
31183118 sb->s_op = &f2fs_sops;
3119−#ifdef CONFIG_F2FS_FS_ENCRYPTION
3119+#ifdef CONFIG_FS_ENCRYPTION
31203120 sb->s_cop = &f2fs_cryptops;
31213121 #endif
31223122 sb->s_xattr = f2fs_xattr_handlers;
fs/f2fs/sysfs.c+2−2
@@ -431,7 +431,7 @@ F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes); · 430 unmodified lines
431431 F2FS_GENERAL_RO_ATTR(features);
432432 F2FS_GENERAL_RO_ATTR(current_reserved_blocks);
433433
434−#ifdef CONFIG_F2FS_FS_ENCRYPTION
434+#ifdef CONFIG_FS_ENCRYPTION
435435 F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO);
436436 #endif
437437 #ifdef CONFIG_BLK_DEV_ZONED
@@ -492,7 +492,7 @@ static struct attribute *f2fs_attrs[] = { · 54 unmodified lines
492492 };
493493
494494 static struct attribute *f2fs_feat_attrs[] = {
495−#ifdef CONFIG_F2FS_FS_ENCRYPTION
495+#ifdef CONFIG_FS_ENCRYPTION
496496 ATTR_LIST(encryption),
497497 #endif
498498 #ifdef CONFIG_BLK_DEV_ZONED
fs/ubifs/Kconfig+1−11
@@ -8,6 +8,7 @@ config UBIFS_FS · 7 unmodified lines
88 select CRYPTO_LZO if UBIFS_FS_LZO
99 select CRYPTO_DEFLATE if UBIFS_FS_ZLIB
1010 select CRYPTO_HASH_INFO
11+ select UBIFS_FS_XATTR if FS_ENCRYPTION
1112 depends on MTD_UBI
1213 help
1314 UBIFS is a file system for flash devices which works on top of UBI.
@@ -60,17 +61,6 @@ config UBIFS_FS_XATTR · 46 unmodified lines
6061
6162 If unsure, say Y.
6263
63−config UBIFS_FS_ENCRYPTION
64− bool "UBIFS Encryption"
65− depends on UBIFS_FS_XATTR && BLOCK
66− select FS_ENCRYPTION
67− default n
68− help
69− Enable encryption of UBIFS files and directories. This
70− feature is similar to ecryptfs, but it is more memory
71− efficient since it avoids caching the encrypted and
72− decrypted pages in the page cache.
73−
7464 config UBIFS_FS_SECURITY
7565 bool "UBIFS Security Labels"
7666 depends on UBIFS_FS_XATTR
fs/ubifs/Makefile+1−1
@@ -6,6 +6,6 @@ ubifs-y += tnc.o master.o scan.o replay.o log.o commit.o gc.o orphan.o · 5 unmodified lines
66 ubifs-y += budget.o find.o tnc_commit.o compress.o lpt.o lprops.o
77 ubifs-y += recovery.o ioctl.o lpt_commit.o tnc_misc.o debug.o
88 ubifs-y += misc.o
9−ubifs-$(CONFIG_UBIFS_FS_ENCRYPTION) += crypto.o
9+ubifs-$(CONFIG_FS_ENCRYPTION) += crypto.o
1010 ubifs-$(CONFIG_UBIFS_FS_XATTR) += xattr.o
1111 ubifs-$(CONFIG_UBIFS_FS_AUTHENTICATION) += auth.o
fs/ubifs/ioctl.c+2−2
@@ -185,7 +185,7 @@ long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) · 184 unmodified lines
185185 return err;
186186 }
187187 case FS_IOC_SET_ENCRYPTION_POLICY: {
188−#ifdef CONFIG_UBIFS_FS_ENCRYPTION
188+#ifdef CONFIG_FS_ENCRYPTION
189189 struct ubifs_info *c = inode->i_sb->s_fs_info;
190190
191191 err = ubifs_enable_encryption(c);
@@ -198,7 +198,7 @@ long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) · 6 unmodified lines
198198 #endif
199199 }
200200 case FS_IOC_GET_ENCRYPTION_POLICY: {
201−#ifdef CONFIG_UBIFS_FS_ENCRYPTION
201+#ifdef CONFIG_FS_ENCRYPTION
202202 return fscrypt_ioctl_get_policy(file, (void __user *)arg);
203203 #else
204204 return -EOPNOTSUPP;
fs/ubifs/sb.c+1−1
@@ -748,7 +748,7 @@ int ubifs_read_superblock(struct ubifs_info *c) · 747 unmodified lines
748748 goto out;
749749 }
750750
751−#ifndef CONFIG_UBIFS_FS_ENCRYPTION
751+#ifndef CONFIG_FS_ENCRYPTION
752752 if (c->encrypted) {
753753 ubifs_err(c, "file system contains encrypted files but UBIFS"
754754 " was built without crypto support.");
fs/ubifs/super.c+1−1
@@ -2146,7 +2146,7 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent) · 2145 unmodified lines
21462146 #ifdef CONFIG_UBIFS_FS_XATTR
21472147 sb->s_xattr = ubifs_xattr_handlers;
21482148 #endif
2149−#ifdef CONFIG_UBIFS_FS_ENCRYPTION
2149+#ifdef CONFIG_FS_ENCRYPTION
21502150 sb->s_cop = &ubifs_crypt_operations;
21512151 #endif
21522152
fs/ubifs/ubifs.h+2−3
@@ -43,7 +43,6 @@ · 42 unmodified lines
4343 #include <crypto/hash.h>
4444 #include <crypto/algapi.h>
4545
46−#define __FS_HAS_ENCRYPTION IS_ENABLED(CONFIG_UBIFS_FS_ENCRYPTION)
4746 #include <linux/fscrypt.h>
4847
4948 #include "ubifs-media.h"
@@ -142,7 +141,7 @@ · 92 unmodified lines
142141 */
143142 #define WORST_COMPR_FACTOR 2
144143
145−#ifdef CONFIG_UBIFS_FS_ENCRYPTION
144+#ifdef CONFIG_FS_ENCRYPTION
146145 #define UBIFS_CIPHER_BLOCK_SIZE FS_CRYPTO_BLOCK_SIZE
147146 #else
148147 #define UBIFS_CIPHER_BLOCK_SIZE 0
@@ -2072,7 +2071,7 @@ int ubifs_decompress(const struct ubifs_info *c, const void *buf, int len, · 1923 unmodified lines
20722071 #include "misc.h"
20732072 #include "key.h"
20742073
2075−#ifndef CONFIG_UBIFS_FS_ENCRYPTION
2074+#ifndef CONFIG_FS_ENCRYPTION
20762075 static inline int ubifs_encrypt(const struct inode *inode,
20772076 struct ubifs_data_node *dn,
20782077 unsigned int in_len, unsigned int *out_len,
include/linux/fs.h+2−2
@@ -698,7 +698,7 @@ struct inode { · 697 unmodified lines
698698 struct fsnotify_mark_connector __rcu *i_fsnotify_marks;
699699 #endif
700700
701−#if IS_ENABLED(CONFIG_FS_ENCRYPTION)
701+#ifdef CONFIG_FS_ENCRYPTION
702702 struct fscrypt_info *i_crypt_info;
703703 #endif
704704
@@ -1403,7 +1403,7 @@ struct super_block { · 698 unmodified lines
14031403 void *s_security;
14041404 #endif
14051405 const struct xattr_handler **s_xattr;
1406−#if IS_ENABLED(CONFIG_FS_ENCRYPTION)
1406+#ifdef CONFIG_FS_ENCRYPTION
14071407 const struct fscrypt_operations *s_cop;
14081408 #endif
14091409 struct hlist_bl_head s_roots; /* alternate root dentries for NFS */
include/linux/fscrypt.h+408−8
@@ -2,9 +2,8 @@ · 1 unmodified line
22 /*
33 * fscrypt.h: declarations for per-file encryption
44 *
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.
5+ * Filesystems that implement per-file encryption must include this header
6+ * file.
87 *
98 * Copyright (C) 2015, Google, Inc.
109 *
@@ -15,6 +14,8 @@ · 4 unmodified lines
1514 #define _LINUX_FSCRYPT_H
1615
1716 #include <linux/fs.h>
17+#include <linux/mm.h>
18+#include <linux/slab.h>
1819
1920 #define FS_CRYPTO_BLOCK_SIZE 16
2021
@@ -42,11 +43,410 @@ struct fscrypt_name { · 21 unmodified lines
4243 /* Maximum value for the third parameter of fscrypt_operations.set_context(). */
4344 #define FSCRYPT_SET_CONTEXT_MAX_SIZE 28
4445
45−#if __FS_HAS_ENCRYPTION
46−#include <linux/fscrypt_supp.h>
47−#else
48−#include <linux/fscrypt_notsupp.h>
49−#endif
46+#ifdef CONFIG_FS_ENCRYPTION
47+/*
48+ * fscrypt superblock flags
49+ */
50+#define FS_CFLG_OWN_PAGES (1U << 1)
51+
52+/*
53+ * crypto operations for filesystems
54+ */
55+struct fscrypt_operations {
56+ unsigned int flags;
57+ const char *key_prefix;
58+ int (*get_context)(struct inode *, void *, size_t);
59+ int (*set_context)(struct inode *, const void *, size_t, void *);
60+ bool (*dummy_context)(struct inode *);
61+ bool (*empty_dir)(struct inode *);
62+ unsigned int max_namelen;
63+};
64+
65+struct fscrypt_ctx {
66+ union {
67+ struct {
68+ struct page *bounce_page; /* Ciphertext page */
69+ struct page *control_page; /* Original page */
70+ } w;
71+ struct {
72+ struct bio *bio;
73+ struct work_struct work;
74+ } r;
75+ struct list_head free_list; /* Free list */
76+ };
77+ u8 flags; /* Flags */
78+};
79+
80+static inline bool fscrypt_has_encryption_key(const struct inode *inode)
81+{
82+ return (inode->i_crypt_info != NULL);
83+}
84+
85+static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
86+{
87+ return inode->i_sb->s_cop->dummy_context &&
88+ inode->i_sb->s_cop->dummy_context(inode);
89+}
90+
91+/* crypto.c */
92+extern void fscrypt_enqueue_decrypt_work(struct work_struct *);
93+extern struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *, gfp_t);
94+extern void fscrypt_release_ctx(struct fscrypt_ctx *);
95+extern struct page *fscrypt_encrypt_page(const struct inode *, struct page *,
96+ unsigned int, unsigned int,
97+ u64, gfp_t);
98+extern int fscrypt_decrypt_page(const struct inode *, struct page *, unsigned int,
99+ unsigned int, u64);
100+
101+static inline struct page *fscrypt_control_page(struct page *page)
102+{
103+ return ((struct fscrypt_ctx *)page_private(page))->w.control_page;
104+}
105+
106+extern void fscrypt_restore_control_page(struct page *);
107+
108+/* policy.c */
109+extern int fscrypt_ioctl_set_policy(struct file *, const void __user *);
110+extern int fscrypt_ioctl_get_policy(struct file *, void __user *);
111+extern int fscrypt_has_permitted_context(struct inode *, struct inode *);
112+extern int fscrypt_inherit_context(struct inode *, struct inode *,
113+ void *, bool);
114+/* keyinfo.c */
115+extern int fscrypt_get_encryption_info(struct inode *);
116+extern void fscrypt_put_encryption_info(struct inode *);
117+
118+/* fname.c */
119+extern int fscrypt_setup_filename(struct inode *, const struct qstr *,
120+ int lookup, struct fscrypt_name *);
121+
122+static inline void fscrypt_free_filename(struct fscrypt_name *fname)
123+{
124+ kfree(fname->crypto_buf.name);
125+}
126+
127+extern int fscrypt_fname_alloc_buffer(const struct inode *, u32,
128+ struct fscrypt_str *);
129+extern void fscrypt_fname_free_buffer(struct fscrypt_str *);
130+extern int fscrypt_fname_disk_to_usr(struct inode *, u32, u32,
131+ const struct fscrypt_str *, struct fscrypt_str *);
132+
133+#define FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE 32
134+
135+/* Extracts the second-to-last ciphertext block; see explanation below */
136+#define FSCRYPT_FNAME_DIGEST(name, len) \
137+ ((name) + round_down((len) - FS_CRYPTO_BLOCK_SIZE - 1, \
138+ FS_CRYPTO_BLOCK_SIZE))
139+
140+#define FSCRYPT_FNAME_DIGEST_SIZE FS_CRYPTO_BLOCK_SIZE
141+
142+/**
143+ * fscrypt_digested_name - alternate identifier for an on-disk filename
144+ *
145+ * When userspace lists an encrypted directory without access to the key,
146+ * filenames whose ciphertext is longer than FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE
147+ * bytes are shown in this abbreviated form (base64-encoded) rather than as the
148+ * full ciphertext (base64-encoded). This is necessary to allow supporting
149+ * filenames up to NAME_MAX bytes, since base64 encoding expands the length.
150+ *
151+ * To make it possible for filesystems to still find the correct directory entry
152+ * despite not knowing the full on-disk name, we encode any filesystem-specific
153+ * 'hash' and/or 'minor_hash' which the filesystem may need for its lookups,
154+ * followed by the second-to-last ciphertext block of the filename. Due to the
155+ * use of the CBC-CTS encryption mode, the second-to-last ciphertext block
156+ * depends on the full plaintext. (Note that ciphertext stealing causes the
157+ * last two blocks to appear "flipped".) This makes accidental collisions very
158+ * unlikely: just a 1 in 2^128 chance for two filenames to collide even if they
159+ * share the same filesystem-specific hashes.
160+ *
161+ * However, this scheme isn't immune to intentional collisions, which can be
162+ * created by anyone able to create arbitrary plaintext filenames and view them
163+ * without the key. Making the "digest" be a real cryptographic hash like
164+ * SHA-256 over the full ciphertext would prevent this, although it would be
165+ * less efficient and harder to implement, especially since the filesystem would
166+ * need to calculate it for each directory entry examined during a search.
167+ */
168+struct fscrypt_digested_name {
169+ u32 hash;
170+ u32 minor_hash;
171+ u8 digest[FSCRYPT_FNAME_DIGEST_SIZE];
172+};
173+
174+/**
175+ * fscrypt_match_name() - test whether the given name matches a directory entry
176+ * @fname: the name being searched for
177+ * @de_name: the name from the directory entry
178+ * @de_name_len: the length of @de_name in bytes
179+ *
180+ * Normally @fname->disk_name will be set, and in that case we simply compare
181+ * that to the name stored in the directory entry. The only exception is that
182+ * if we don't have the key for an encrypted directory and a filename in it is
183+ * very long, then we won't have the full disk_name and we'll instead need to
184+ * match against the fscrypt_digested_name.
185+ *
186+ * Return: %true if the name matches, otherwise %false.
187+ */
188+static inline bool fscrypt_match_name(const struct fscrypt_name *fname,
189+ const u8 *de_name, u32 de_name_len)
190+{
191+ if (unlikely(!fname->disk_name.name)) {
192+ const struct fscrypt_digested_name *n =
193+ (const void *)fname->crypto_buf.name;
194+ if (WARN_ON_ONCE(fname->usr_fname->name[0] != '_'))
195+ return false;
196+ if (de_name_len <= FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE)
197+ return false;
198+ return !memcmp(FSCRYPT_FNAME_DIGEST(de_name, de_name_len),
199+ n->digest, FSCRYPT_FNAME_DIGEST_SIZE);
200+ }
201+
202+ if (de_name_len != fname->disk_name.len)
203+ return false;
204+ return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len);
205+}
206+
207+/* bio.c */
208+extern void fscrypt_decrypt_bio(struct bio *);
209+extern void fscrypt_enqueue_decrypt_bio(struct fscrypt_ctx *ctx,
210+ struct bio *bio);
211+extern void fscrypt_pullback_bio_page(struct page **, bool);
212+extern int fscrypt_zeroout_range(const struct inode *, pgoff_t, sector_t,
213+ unsigned int);
214+
215+/* hooks.c */
216+extern int fscrypt_file_open(struct inode *inode, struct file *filp);
217+extern int __fscrypt_prepare_link(struct inode *inode, struct inode *dir);
218+extern int __fscrypt_prepare_rename(struct inode *old_dir,
219+ struct dentry *old_dentry,
220+ struct inode *new_dir,
221+ struct dentry *new_dentry,
222+ unsigned int flags);
223+extern int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry);
224+extern int __fscrypt_prepare_symlink(struct inode *dir, unsigned int len,
225+ unsigned int max_len,
226+ struct fscrypt_str *disk_link);
227+extern int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
228+ unsigned int len,
229+ struct fscrypt_str *disk_link);
230+extern const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
231+ unsigned int max_size,
232+ struct delayed_call *done);
233+#else /* !CONFIG_FS_ENCRYPTION */
234+
235+static inline bool fscrypt_has_encryption_key(const struct inode *inode)
236+{
237+ return false;
238+}
239+
240+static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
241+{
242+ return false;
243+}
244+
245+/* crypto.c */
246+static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work)
247+{
248+}
249+
250+static inline struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *inode,
251+ gfp_t gfp_flags)
252+{
253+ return ERR_PTR(-EOPNOTSUPP);
254+}
255+
256+static inline void fscrypt_release_ctx(struct fscrypt_ctx *ctx)
257+{
258+ return;
259+}
260+
261+static inline struct page *fscrypt_encrypt_page(const struct inode *inode,
262+ struct page *page,
263+ unsigned int len,
264+ unsigned int offs,
265+ u64 lblk_num, gfp_t gfp_flags)
266+{
267+ return ERR_PTR(-EOPNOTSUPP);
268+}
269+
270+static inline int fscrypt_decrypt_page(const struct inode *inode,
271+ struct page *page,
272+ unsigned int len, unsigned int offs,
273+ u64 lblk_num)
274+{
275+ return -EOPNOTSUPP;
276+}
277+
278+static inline struct page *fscrypt_control_page(struct page *page)
279+{
280+ WARN_ON_ONCE(1);
281+ return ERR_PTR(-EINVAL);
282+}
283+
284+static inline void fscrypt_restore_control_page(struct page *page)
285+{
286+ return;
287+}
288+
289+/* policy.c */
290+static inline int fscrypt_ioctl_set_policy(struct file *filp,
291+ const void __user *arg)
292+{
293+ return -EOPNOTSUPP;
294+}
295+
296+static inline int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg)
297+{
298+ return -EOPNOTSUPP;
299+}
300+
301+static inline int fscrypt_has_permitted_context(struct inode *parent,
302+ struct inode *child)
303+{
304+ return 0;
305+}
306+
307+static inline int fscrypt_inherit_context(struct inode *parent,
308+ struct inode *child,
309+ void *fs_data, bool preload)
310+{
311+ return -EOPNOTSUPP;
312+}
313+
314+/* keyinfo.c */
315+static inline int fscrypt_get_encryption_info(struct inode *inode)
316+{
317+ return -EOPNOTSUPP;
318+}
319+
320+static inline void fscrypt_put_encryption_info(struct inode *inode)
321+{
322+ return;
323+}
324+
325+ /* fname.c */
326+static inline int fscrypt_setup_filename(struct inode *dir,
327+ const struct qstr *iname,
328+ int lookup, struct fscrypt_name *fname)
329+{
330+ if (IS_ENCRYPTED(dir))
331+ return -EOPNOTSUPP;
332+
333+ memset(fname, 0, sizeof(struct fscrypt_name));
334+ fname->usr_fname = iname;
335+ fname->disk_name.name = (unsigned char *)iname->name;
336+ fname->disk_name.len = iname->len;
337+ return 0;
338+}
339+
340+static inline void fscrypt_free_filename(struct fscrypt_name *fname)
341+{
342+ return;
343+}
344+
345+static inline int fscrypt_fname_alloc_buffer(const struct inode *inode,
346+ u32 max_encrypted_len,
347+ struct fscrypt_str *crypto_str)
348+{
349+ return -EOPNOTSUPP;
350+}
351+
352+static inline void fscrypt_fname_free_buffer(struct fscrypt_str *crypto_str)
353+{
354+ return;
355+}
356+
357+static inline int fscrypt_fname_disk_to_usr(struct inode *inode,
358+ u32 hash, u32 minor_hash,
359+ const struct fscrypt_str *iname,
360+ struct fscrypt_str *oname)
361+{
362+ return -EOPNOTSUPP;
363+}
364+
365+static inline bool fscrypt_match_name(const struct fscrypt_name *fname,
366+ const u8 *de_name, u32 de_name_len)
367+{
368+ /* Encryption support disabled; use standard comparison */
369+ if (de_name_len != fname->disk_name.len)
370+ return false;
371+ return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len);
372+}
373+
374+/* bio.c */
375+static inline void fscrypt_decrypt_bio(struct bio *bio)
376+{
377+}
378+
379+static inline void fscrypt_enqueue_decrypt_bio(struct fscrypt_ctx *ctx,
380+ struct bio *bio)
381+{
382+}
383+
384+static inline void fscrypt_pullback_bio_page(struct page **page, bool restore)
385+{
386+ return;
387+}
388+
389+static inline int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
390+ sector_t pblk, unsigned int len)
391+{
392+ return -EOPNOTSUPP;
393+}
394+
395+/* hooks.c */
396+
397+static inline int fscrypt_file_open(struct inode *inode, struct file *filp)
398+{
399+ if (IS_ENCRYPTED(inode))
400+ return -EOPNOTSUPP;
401+ return 0;
402+}
403+
404+static inline int __fscrypt_prepare_link(struct inode *inode,
405+ struct inode *dir)
406+{
407+ return -EOPNOTSUPP;
408+}
409+
410+static inline int __fscrypt_prepare_rename(struct inode *old_dir,
411+ struct dentry *old_dentry,
412+ struct inode *new_dir,
413+ struct dentry *new_dentry,
414+ unsigned int flags)
415+{
416+ return -EOPNOTSUPP;
417+}
418+
419+static inline int __fscrypt_prepare_lookup(struct inode *dir,
420+ struct dentry *dentry)
421+{
422+ return -EOPNOTSUPP;
423+}
424+
425+static inline int __fscrypt_prepare_symlink(struct inode *dir,
426+ unsigned int len,
427+ unsigned int max_len,
428+ struct fscrypt_str *disk_link)
429+{
430+ return -EOPNOTSUPP;
431+}
432+
433+
434+static inline int __fscrypt_encrypt_symlink(struct inode *inode,
435+ const char *target,
436+ unsigned int len,
437+ struct fscrypt_str *disk_link)
438+{
439+ return -EOPNOTSUPP;
440+}
441+
442+static inline const char *fscrypt_get_symlink(struct inode *inode,
443+ const void *caddr,
444+ unsigned int max_size,
445+ struct delayed_call *done)
446+{
447+ return ERR_PTR(-EOPNOTSUPP);
448+}
449+#endif /* !CONFIG_FS_ENCRYPTION */
50450
51451 /**
52452 * fscrypt_require_key - require an inode's encryption key
include/linux/fscrypt_notsupp.h+0−231
@@ -1,231 +0,0 @@
1−/* SPDX-License-Identifier: GPL-2.0 */
2−/*
3− * fscrypt_notsupp.h
4− *
5− * This stubs out the fscrypt functions for filesystems configured without
6− * encryption support.
7− *
8− * Do not include this file directly. Use fscrypt.h instead!
9− */
10−#ifndef _LINUX_FSCRYPT_H
11−#error "Incorrect include of linux/fscrypt_notsupp.h!"
12−#endif
13−
14−#ifndef _LINUX_FSCRYPT_NOTSUPP_H
15−#define _LINUX_FSCRYPT_NOTSUPP_H
16−
17−static inline bool fscrypt_has_encryption_key(const struct inode *inode)
18−{
19− return false;
20−}
21−
22−static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
23−{
24− return false;
25−}
26−
27−/* crypto.c */
28−static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work)
29−{
30−}
31−
32−static inline struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *inode,
33− gfp_t gfp_flags)
34−{
35− return ERR_PTR(-EOPNOTSUPP);
36−}
37−
38−static inline void fscrypt_release_ctx(struct fscrypt_ctx *ctx)
39−{
40− return;
41−}
42−
43−static inline struct page *fscrypt_encrypt_page(const struct inode *inode,
44− struct page *page,
45− unsigned int len,
46− unsigned int offs,
47− u64 lblk_num, gfp_t gfp_flags)
48−{
49− return ERR_PTR(-EOPNOTSUPP);
50−}
51−
52−static inline int fscrypt_decrypt_page(const struct inode *inode,
53− struct page *page,
54− unsigned int len, unsigned int offs,
55− u64 lblk_num)
56−{
57− return -EOPNOTSUPP;
58−}
59−
60−static inline struct page *fscrypt_control_page(struct page *page)
61−{
62− WARN_ON_ONCE(1);
63− return ERR_PTR(-EINVAL);
64−}
65−
66−static inline void fscrypt_restore_control_page(struct page *page)
67−{
68− return;
69−}
70−
71−/* policy.c */
72−static inline int fscrypt_ioctl_set_policy(struct file *filp,
73− const void __user *arg)
74−{
75− return -EOPNOTSUPP;
76−}
77−
78−static inline int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg)
79−{
80− return -EOPNOTSUPP;
81−}
82−
83−static inline int fscrypt_has_permitted_context(struct inode *parent,
84− struct inode *child)
85−{
86− return 0;
87−}
88−
89−static inline int fscrypt_inherit_context(struct inode *parent,
90− struct inode *child,
91− void *fs_data, bool preload)
92−{
93− return -EOPNOTSUPP;
94−}
95−
96−/* keyinfo.c */
97−static inline int fscrypt_get_encryption_info(struct inode *inode)
98−{
99− return -EOPNOTSUPP;
100−}
101−
102−static inline void fscrypt_put_encryption_info(struct inode *inode)
103−{
104− return;
105−}
106−
107− /* fname.c */
108−static inline int fscrypt_setup_filename(struct inode *dir,
109− const struct qstr *iname,
110− int lookup, struct fscrypt_name *fname)
111−{
112− if (IS_ENCRYPTED(dir))
113− return -EOPNOTSUPP;
114−
115− memset(fname, 0, sizeof(struct fscrypt_name));
116− fname->usr_fname = iname;
117− fname->disk_name.name = (unsigned char *)iname->name;
118− fname->disk_name.len = iname->len;
119− return 0;
120−}
121−
122−static inline void fscrypt_free_filename(struct fscrypt_name *fname)
123−{
124− return;
125−}
126−
127−static inline int fscrypt_fname_alloc_buffer(const struct inode *inode,
128− u32 max_encrypted_len,
129− struct fscrypt_str *crypto_str)
130−{
131− return -EOPNOTSUPP;
132−}
133−
134−static inline void fscrypt_fname_free_buffer(struct fscrypt_str *crypto_str)
135−{
136− return;
137−}
138−
139−static inline int fscrypt_fname_disk_to_usr(struct inode *inode,
140− u32 hash, u32 minor_hash,
141− const struct fscrypt_str *iname,
142− struct fscrypt_str *oname)
143−{
144− return -EOPNOTSUPP;
145−}
146−
147−static inline bool fscrypt_match_name(const struct fscrypt_name *fname,
148− const u8 *de_name, u32 de_name_len)
149−{
150− /* Encryption support disabled; use standard comparison */
151− if (de_name_len != fname->disk_name.len)
152− return false;
153− return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len);
154−}
155−
156−/* bio.c */
157−static inline void fscrypt_decrypt_bio(struct bio *bio)
158−{
159−}
160−
161−static inline void fscrypt_enqueue_decrypt_bio(struct fscrypt_ctx *ctx,
162− struct bio *bio)
163−{
164−}
165−
166−static inline void fscrypt_pullback_bio_page(struct page **page, bool restore)
167−{
168− return;
169−}
170−
171−static inline int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
172− sector_t pblk, unsigned int len)
173−{
174− return -EOPNOTSUPP;
175−}
176−
177−/* hooks.c */
178−
179−static inline int fscrypt_file_open(struct inode *inode, struct file *filp)
180−{
181− if (IS_ENCRYPTED(inode))
182− return -EOPNOTSUPP;
183− return 0;
184−}
185−
186−static inline int __fscrypt_prepare_link(struct inode *inode,
187− struct inode *dir)
188−{
189− return -EOPNOTSUPP;
190−}
191−
192−static inline int __fscrypt_prepare_rename(struct inode *old_dir,
193− struct dentry *old_dentry,
194− struct inode *new_dir,
195− struct dentry *new_dentry,
196− unsigned int flags)
197−{
198− return -EOPNOTSUPP;
199−}
200−
201−static inline int __fscrypt_prepare_lookup(struct inode *dir,
202− struct dentry *dentry)
203−{
204− return -EOPNOTSUPP;
205−}
206−
207−static inline int __fscrypt_prepare_symlink(struct inode *dir,
208− unsigned int len,
209− unsigned int max_len,
210− struct fscrypt_str *disk_link)
211−{
212− return -EOPNOTSUPP;
213−}
214−
215−static inline int __fscrypt_encrypt_symlink(struct inode *inode,
216− const char *target,
217− unsigned int len,
218− struct fscrypt_str *disk_link)
219−{
220− return -EOPNOTSUPP;
221−}
222−
223−static inline const char *fscrypt_get_symlink(struct inode *inode,
224− const void *caddr,
225− unsigned int max_size,
226− struct delayed_call *done)
227−{
228− return ERR_PTR(-EOPNOTSUPP);
229−}
230−
231−#endif /* _LINUX_FSCRYPT_NOTSUPP_H */
include/linux/fscrypt_supp.h+0−204
@@ -1,204 +0,0 @@
1−/* SPDX-License-Identifier: GPL-2.0 */
2−/*
3− * fscrypt_supp.h
4− *
5− * Do not include this file directly. Use fscrypt.h instead!
6− */
7−#ifndef _LINUX_FSCRYPT_H
8−#error "Incorrect include of linux/fscrypt_supp.h!"
9−#endif
10−
11−#ifndef _LINUX_FSCRYPT_SUPP_H
12−#define _LINUX_FSCRYPT_SUPP_H
13−
14−#include <linux/mm.h>
15−#include <linux/slab.h>
16−
17−/*
18− * fscrypt superblock flags
19− */
20−#define FS_CFLG_OWN_PAGES (1U << 1)
21−
22−/*
23− * crypto operations for filesystems
24− */
25−struct fscrypt_operations {
26− unsigned int flags;
27− const char *key_prefix;
28− int (*get_context)(struct inode *, void *, size_t);
29− int (*set_context)(struct inode *, const void *, size_t, void *);
30− bool (*dummy_context)(struct inode *);
31− bool (*empty_dir)(struct inode *);
32− unsigned int max_namelen;
33−};
34−
35−struct fscrypt_ctx {
36− union {
37− struct {
38− struct page *bounce_page; /* Ciphertext page */
39− struct page *control_page; /* Original page */
40− } w;
41− struct {
42− struct bio *bio;
43− struct work_struct work;
44− } r;
45− struct list_head free_list; /* Free list */
46− };
47− u8 flags; /* Flags */
48−};
49−
50−static inline bool fscrypt_has_encryption_key(const struct inode *inode)
51−{
52− return (inode->i_crypt_info != NULL);
53−}
54−
55−static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
56−{
57− return inode->i_sb->s_cop->dummy_context &&
58− inode->i_sb->s_cop->dummy_context(inode);
59−}
60−
61−/* crypto.c */
62−extern void fscrypt_enqueue_decrypt_work(struct work_struct *);
63−extern struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *, gfp_t);
64−extern void fscrypt_release_ctx(struct fscrypt_ctx *);
65−extern struct page *fscrypt_encrypt_page(const struct inode *, struct page *,
66− unsigned int, unsigned int,
67− u64, gfp_t);
68−extern int fscrypt_decrypt_page(const struct inode *, struct page *, unsigned int,
69− unsigned int, u64);
70−
71−static inline struct page *fscrypt_control_page(struct page *page)
72−{
73− return ((struct fscrypt_ctx *)page_private(page))->w.control_page;
74−}
75−
76−extern void fscrypt_restore_control_page(struct page *);
77−
78−/* policy.c */
79−extern int fscrypt_ioctl_set_policy(struct file *, const void __user *);
80−extern int fscrypt_ioctl_get_policy(struct file *, void __user *);
81−extern int fscrypt_has_permitted_context(struct inode *, struct inode *);
82−extern int fscrypt_inherit_context(struct inode *, struct inode *,
83− void *, bool);
84−/* keyinfo.c */
85−extern int fscrypt_get_encryption_info(struct inode *);
86−extern void fscrypt_put_encryption_info(struct inode *);
87−
88−/* fname.c */
89−extern int fscrypt_setup_filename(struct inode *, const struct qstr *,
90− int lookup, struct fscrypt_name *);
91−
92−static inline void fscrypt_free_filename(struct fscrypt_name *fname)
93−{
94− kfree(fname->crypto_buf.name);
95−}
96−
97−extern int fscrypt_fname_alloc_buffer(const struct inode *, u32,
98− struct fscrypt_str *);
99−extern void fscrypt_fname_free_buffer(struct fscrypt_str *);
100−extern int fscrypt_fname_disk_to_usr(struct inode *, u32, u32,
101− const struct fscrypt_str *, struct fscrypt_str *);
102−
103−#define FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE 32
104−
105−/* Extracts the second-to-last ciphertext block; see explanation below */
106−#define FSCRYPT_FNAME_DIGEST(name, len) \
107− ((name) + round_down((len) - FS_CRYPTO_BLOCK_SIZE - 1, \
108− FS_CRYPTO_BLOCK_SIZE))
109−
110−#define FSCRYPT_FNAME_DIGEST_SIZE FS_CRYPTO_BLOCK_SIZE
111−
112−/**
113− * fscrypt_digested_name - alternate identifier for an on-disk filename
114− *
115− * When userspace lists an encrypted directory without access to the key,
116− * filenames whose ciphertext is longer than FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE
117− * bytes are shown in this abbreviated form (base64-encoded) rather than as the
118− * full ciphertext (base64-encoded). This is necessary to allow supporting
119− * filenames up to NAME_MAX bytes, since base64 encoding expands the length.
120− *
121− * To make it possible for filesystems to still find the correct directory entry
122− * despite not knowing the full on-disk name, we encode any filesystem-specific
123− * 'hash' and/or 'minor_hash' which the filesystem may need for its lookups,
124− * followed by the second-to-last ciphertext block of the filename. Due to the
125− * use of the CBC-CTS encryption mode, the second-to-last ciphertext block
126− * depends on the full plaintext. (Note that ciphertext stealing causes the
127− * last two blocks to appear "flipped".) This makes accidental collisions very
128− * unlikely: just a 1 in 2^128 chance for two filenames to collide even if they
129− * share the same filesystem-specific hashes.
130− *
131− * However, this scheme isn't immune to intentional collisions, which can be
132− * created by anyone able to create arbitrary plaintext filenames and view them
133− * without the key. Making the "digest" be a real cryptographic hash like
134− * SHA-256 over the full ciphertext would prevent this, although it would be
135− * less efficient and harder to implement, especially since the filesystem would
136− * need to calculate it for each directory entry examined during a search.
137− */
138−struct fscrypt_digested_name {
139− u32 hash;
140− u32 minor_hash;
141− u8 digest[FSCRYPT_FNAME_DIGEST_SIZE];
142−};
143−
144−/**
145− * fscrypt_match_name() - test whether the given name matches a directory entry
146− * @fname: the name being searched for
147− * @de_name: the name from the directory entry
148− * @de_name_len: the length of @de_name in bytes
149− *
150− * Normally @fname->disk_name will be set, and in that case we simply compare
151− * that to the name stored in the directory entry. The only exception is that
152− * if we don't have the key for an encrypted directory and a filename in it is
153− * very long, then we won't have the full disk_name and we'll instead need to
154− * match against the fscrypt_digested_name.
155− *
156− * Return: %true if the name matches, otherwise %false.
157− */
158−static inline bool fscrypt_match_name(const struct fscrypt_name *fname,
159− const u8 *de_name, u32 de_name_len)
160−{
161− if (unlikely(!fname->disk_name.name)) {
162− const struct fscrypt_digested_name *n =
163− (const void *)fname->crypto_buf.name;
164− if (WARN_ON_ONCE(fname->usr_fname->name[0] != '_'))
165− return false;
166− if (de_name_len <= FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE)
167− return false;
168− return !memcmp(FSCRYPT_FNAME_DIGEST(de_name, de_name_len),
169− n->digest, FSCRYPT_FNAME_DIGEST_SIZE);
170− }
171−
172− if (de_name_len != fname->disk_name.len)
173− return false;
174− return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len);
175−}
176−
177−/* bio.c */
178−extern void fscrypt_decrypt_bio(struct bio *);
179−extern void fscrypt_enqueue_decrypt_bio(struct fscrypt_ctx *ctx,
180− struct bio *bio);
181−extern void fscrypt_pullback_bio_page(struct page **, bool);
182−extern int fscrypt_zeroout_range(const struct inode *, pgoff_t, sector_t,
183− unsigned int);
184−
185−/* hooks.c */
186−extern int fscrypt_file_open(struct inode *inode, struct file *filp);
187−extern int __fscrypt_prepare_link(struct inode *inode, struct inode *dir);
188−extern int __fscrypt_prepare_rename(struct inode *old_dir,
189− struct dentry *old_dentry,
190− struct inode *new_dir,
191− struct dentry *new_dentry,
192− unsigned int flags);
193−extern int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry);
194−extern int __fscrypt_prepare_symlink(struct inode *dir, unsigned int len,
195− unsigned int max_len,
196− struct fscrypt_str *disk_link);
197−extern int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
198− unsigned int len,
199− struct fscrypt_str *disk_link);
200−extern const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
201− unsigned int max_size,
202− struct delayed_call *done);
203−
204−#endif /* _LINUX_FSCRYPT_SUPP_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t