@@ -87,7 +87,7 @@ static struct inode *ext4_get_journal_inode(struct super_block *sb,
87
87
static int ext4_validate_options (struct fs_context * fc );
88
88
static int ext4_check_opt_consistency (struct fs_context * fc ,
89
89
struct super_block * sb );
90
- static int ext4_apply_options (struct fs_context * fc , struct super_block * sb );
90
+ static void ext4_apply_options (struct fs_context * fc , struct super_block * sb );
91
91
static int ext4_parse_param (struct fs_context * fc , struct fs_parameter * param );
92
92
static int ext4_get_tree (struct fs_context * fc );
93
93
static int ext4_reconfigure (struct fs_context * fc );
@@ -1870,31 +1870,12 @@ ext4_sb_read_encoding(const struct ext4_super_block *es)
1870
1870
}
1871
1871
#endif
1872
1872
1873
- static int ext4_set_test_dummy_encryption (struct super_block * sb , char * arg )
1874
- {
1875
- #ifdef CONFIG_FS_ENCRYPTION
1876
- struct ext4_sb_info * sbi = EXT4_SB (sb );
1877
- int err ;
1878
-
1879
- err = fscrypt_set_test_dummy_encryption (sb , arg ,
1880
- & sbi -> s_dummy_enc_policy );
1881
- if (err ) {
1882
- ext4_msg (sb , KERN_WARNING ,
1883
- "Error while setting test dummy encryption [%d]" , err );
1884
- return err ;
1885
- }
1886
- ext4_msg (sb , KERN_WARNING , "Test dummy encryption mode enabled" );
1887
- #endif
1888
- return 0 ;
1889
- }
1890
-
1891
1873
#define EXT4_SPEC_JQUOTA (1 << 0)
1892
1874
#define EXT4_SPEC_JQFMT (1 << 1)
1893
1875
#define EXT4_SPEC_DATAJ (1 << 2)
1894
1876
#define EXT4_SPEC_SB_BLOCK (1 << 3)
1895
1877
#define EXT4_SPEC_JOURNAL_DEV (1 << 4)
1896
1878
#define EXT4_SPEC_JOURNAL_IOPRIO (1 << 5)
1897
- #define EXT4_SPEC_DUMMY_ENCRYPTION (1 << 6)
1898
1879
#define EXT4_SPEC_s_want_extra_isize (1 << 7)
1899
1880
#define EXT4_SPEC_s_max_batch_time (1 << 8)
1900
1881
#define EXT4_SPEC_s_min_batch_time (1 << 9)
@@ -1911,7 +1892,7 @@ static int ext4_set_test_dummy_encryption(struct super_block *sb, char *arg)
1911
1892
1912
1893
struct ext4_fs_context {
1913
1894
char * s_qf_names [EXT4_MAXQUOTAS ];
1914
- char * test_dummy_enc_arg ;
1895
+ struct fscrypt_dummy_policy dummy_enc_policy ;
1915
1896
int s_jquota_fmt ; /* Format of quota to use */
1916
1897
#ifdef CONFIG_EXT4_DEBUG
1917
1898
int s_fc_debug_max_replay ;
@@ -1953,7 +1934,7 @@ static void ext4_fc_free(struct fs_context *fc)
1953
1934
for (i = 0 ; i < EXT4_MAXQUOTAS ; i ++ )
1954
1935
kfree (ctx -> s_qf_names [i ]);
1955
1936
1956
- kfree ( ctx -> test_dummy_enc_arg );
1937
+ fscrypt_free_dummy_policy ( & ctx -> dummy_enc_policy );
1957
1938
kfree (ctx );
1958
1939
}
1959
1940
@@ -2029,6 +2010,29 @@ static int unnote_qf_name(struct fs_context *fc, int qtype)
2029
2010
}
2030
2011
#endif
2031
2012
2013
+ static int ext4_parse_test_dummy_encryption (const struct fs_parameter * param ,
2014
+ struct ext4_fs_context * ctx )
2015
+ {
2016
+ int err ;
2017
+
2018
+ if (!IS_ENABLED (CONFIG_FS_ENCRYPTION )) {
2019
+ ext4_msg (NULL , KERN_WARNING ,
2020
+ "test_dummy_encryption option not supported" );
2021
+ return - EINVAL ;
2022
+ }
2023
+ err = fscrypt_parse_test_dummy_encryption (param ,
2024
+ & ctx -> dummy_enc_policy );
2025
+ if (err == - EINVAL ) {
2026
+ ext4_msg (NULL , KERN_WARNING ,
2027
+ "Value of option \"%s\" is unrecognized" , param -> key );
2028
+ } else if (err == - EEXIST ) {
2029
+ ext4_msg (NULL , KERN_WARNING ,
2030
+ "Conflicting test_dummy_encryption options" );
2031
+ return - EINVAL ;
2032
+ }
2033
+ return err ;
2034
+ }
2035
+
2032
2036
#define EXT4_SET_CTX (name ) \
2033
2037
static inline void ctx_set_##name(struct ext4_fs_context *ctx, \
2034
2038
unsigned long flag) \
@@ -2291,29 +2295,7 @@ static int ext4_parse_param(struct fs_context *fc, struct fs_parameter *param)
2291
2295
ctx -> spec |= EXT4_SPEC_JOURNAL_IOPRIO ;
2292
2296
return 0 ;
2293
2297
case Opt_test_dummy_encryption :
2294
- #ifdef CONFIG_FS_ENCRYPTION
2295
- if (param -> type == fs_value_is_flag ) {
2296
- ctx -> spec |= EXT4_SPEC_DUMMY_ENCRYPTION ;
2297
- ctx -> test_dummy_enc_arg = NULL ;
2298
- return 0 ;
2299
- }
2300
- if (* param -> string &&
2301
- !(!strcmp (param -> string , "v1" ) ||
2302
- !strcmp (param -> string , "v2" ))) {
2303
- ext4_msg (NULL , KERN_WARNING ,
2304
- "Value of option \"%s\" is unrecognized" ,
2305
- param -> key );
2306
- return - EINVAL ;
2307
- }
2308
- ctx -> spec |= EXT4_SPEC_DUMMY_ENCRYPTION ;
2309
- ctx -> test_dummy_enc_arg = kmemdup_nul (param -> string , param -> size ,
2310
- GFP_KERNEL );
2311
- return 0 ;
2312
- #else
2313
- ext4_msg (NULL , KERN_WARNING ,
2314
- "test_dummy_encryption option not supported" );
2315
- return - EINVAL ;
2316
- #endif
2298
+ return ext4_parse_test_dummy_encryption (param , ctx );
2317
2299
case Opt_dax :
2318
2300
case Opt_dax_type :
2319
2301
#ifdef CONFIG_FS_DAX
@@ -2504,7 +2486,8 @@ static int parse_apply_sb_mount_options(struct super_block *sb,
2504
2486
if (s_ctx -> spec & EXT4_SPEC_JOURNAL_IOPRIO )
2505
2487
m_ctx -> journal_ioprio = s_ctx -> journal_ioprio ;
2506
2488
2507
- ret = ext4_apply_options (fc , sb );
2489
+ ext4_apply_options (fc , sb );
2490
+ ret = 0 ;
2508
2491
2509
2492
out_free :
2510
2493
if (fc ) {
@@ -2673,11 +2656,11 @@ static int ext4_check_quota_consistency(struct fs_context *fc,
2673
2656
static int ext4_check_test_dummy_encryption (const struct fs_context * fc ,
2674
2657
struct super_block * sb )
2675
2658
{
2676
- #ifdef CONFIG_FS_ENCRYPTION
2677
2659
const struct ext4_fs_context * ctx = fc -> fs_private ;
2678
2660
const struct ext4_sb_info * sbi = EXT4_SB (sb );
2661
+ int err ;
2679
2662
2680
- if (!( ctx -> spec & EXT4_SPEC_DUMMY_ENCRYPTION ))
2663
+ if (!fscrypt_is_dummy_policy_set ( & ctx -> dummy_enc_policy ))
2681
2664
return 0 ;
2682
2665
2683
2666
if (!ext4_has_feature_encrypt (sb )) {
@@ -2691,14 +2674,46 @@ static int ext4_check_test_dummy_encryption(const struct fs_context *fc,
2691
2674
* needed to allow it to be set or changed during remount. We do allow
2692
2675
* it to be specified during remount, but only if there is no change.
2693
2676
*/
2694
- if (fc -> purpose == FS_CONTEXT_FOR_RECONFIGURE &&
2695
- !sbi -> s_dummy_enc_policy .policy ) {
2677
+ if (fc -> purpose == FS_CONTEXT_FOR_RECONFIGURE ) {
2678
+ if (fscrypt_dummy_policies_equal (& sbi -> s_dummy_enc_policy ,
2679
+ & ctx -> dummy_enc_policy ))
2680
+ return 0 ;
2696
2681
ext4_msg (NULL , KERN_WARNING ,
2697
- "Can't set test_dummy_encryption on remount" );
2682
+ "Can't set or change test_dummy_encryption on remount" );
2698
2683
return - EINVAL ;
2699
2684
}
2700
- #endif /* CONFIG_FS_ENCRYPTION */
2701
- return 0 ;
2685
+ /* Also make sure s_mount_opts didn't contain a conflicting value. */
2686
+ if (fscrypt_is_dummy_policy_set (& sbi -> s_dummy_enc_policy )) {
2687
+ if (fscrypt_dummy_policies_equal (& sbi -> s_dummy_enc_policy ,
2688
+ & ctx -> dummy_enc_policy ))
2689
+ return 0 ;
2690
+ ext4_msg (NULL , KERN_WARNING ,
2691
+ "Conflicting test_dummy_encryption options" );
2692
+ return - EINVAL ;
2693
+ }
2694
+ /*
2695
+ * fscrypt_add_test_dummy_key() technically changes the super_block, so
2696
+ * technically it should be delayed until ext4_apply_options() like the
2697
+ * other changes. But since we never get here for remounts (see above),
2698
+ * and this is the last chance to report errors, we do it here.
2699
+ */
2700
+ err = fscrypt_add_test_dummy_key (sb , & ctx -> dummy_enc_policy );
2701
+ if (err )
2702
+ ext4_msg (NULL , KERN_WARNING ,
2703
+ "Error adding test dummy encryption key [%d]" , err );
2704
+ return err ;
2705
+ }
2706
+
2707
+ static void ext4_apply_test_dummy_encryption (struct ext4_fs_context * ctx ,
2708
+ struct super_block * sb )
2709
+ {
2710
+ if (!fscrypt_is_dummy_policy_set (& ctx -> dummy_enc_policy ) ||
2711
+ /* if already set, it was already verified to be the same */
2712
+ fscrypt_is_dummy_policy_set (& EXT4_SB (sb )-> s_dummy_enc_policy ))
2713
+ return ;
2714
+ EXT4_SB (sb )-> s_dummy_enc_policy = ctx -> dummy_enc_policy ;
2715
+ memset (& ctx -> dummy_enc_policy , 0 , sizeof (ctx -> dummy_enc_policy ));
2716
+ ext4_msg (sb , KERN_WARNING , "Test dummy encryption mode enabled" );
2702
2717
}
2703
2718
2704
2719
static int ext4_check_opt_consistency (struct fs_context * fc ,
@@ -2785,11 +2800,10 @@ static int ext4_check_opt_consistency(struct fs_context *fc,
2785
2800
return ext4_check_quota_consistency (fc , sb );
2786
2801
}
2787
2802
2788
- static int ext4_apply_options (struct fs_context * fc , struct super_block * sb )
2803
+ static void ext4_apply_options (struct fs_context * fc , struct super_block * sb )
2789
2804
{
2790
2805
struct ext4_fs_context * ctx = fc -> fs_private ;
2791
2806
struct ext4_sb_info * sbi = fc -> s_fs_info ;
2792
- int ret = 0 ;
2793
2807
2794
2808
sbi -> s_mount_opt &= ~ctx -> mask_s_mount_opt ;
2795
2809
sbi -> s_mount_opt |= ctx -> vals_s_mount_opt ;
@@ -2825,11 +2839,7 @@ static int ext4_apply_options(struct fs_context *fc, struct super_block *sb)
2825
2839
#endif
2826
2840
2827
2841
ext4_apply_quota_options (fc , sb );
2828
-
2829
- if (ctx -> spec & EXT4_SPEC_DUMMY_ENCRYPTION )
2830
- ret = ext4_set_test_dummy_encryption (sb , ctx -> test_dummy_enc_arg );
2831
-
2832
- return ret ;
2842
+ ext4_apply_test_dummy_encryption (ctx , sb );
2833
2843
}
2834
2844
2835
2845
@@ -4552,9 +4562,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
4552
4562
if (err < 0 )
4553
4563
goto failed_mount ;
4554
4564
4555
- err = ext4_apply_options (fc , sb );
4556
- if (err < 0 )
4557
- goto failed_mount ;
4565
+ ext4_apply_options (fc , sb );
4558
4566
4559
4567
#if IS_ENABLED (CONFIG_UNICODE )
4560
4568
if (ext4_has_feature_casefold (sb ) && !sb -> s_encoding ) {
0 commit comments