@@ -239,18 +239,12 @@ static void ecryptfs_init_mount_crypt_stat(
239
239
*
240
240
* Returns zero on success; non-zero on error
241
241
*/
242
- static int ecryptfs_parse_options (struct ecryptfs_sb_info * sbi , char * options ,
243
- uid_t * check_ruid )
242
+ static int ecryptfs_parse_options (struct ecryptfs_sb_info * sbi , char * options )
244
243
{
245
244
char * p ;
246
245
int rc = 0 ;
247
- int sig_set = 0 ;
248
- int cipher_name_set = 0 ;
249
- int fn_cipher_name_set = 0 ;
250
246
int cipher_key_bytes ;
251
- int cipher_key_bytes_set = 0 ;
252
247
int fn_cipher_key_bytes ;
253
- int fn_cipher_key_bytes_set = 0 ;
254
248
struct ecryptfs_mount_crypt_stat * mount_crypt_stat =
255
249
& sbi -> mount_crypt_stat ;
256
250
substring_t args [MAX_OPT_ARGS ];
@@ -261,9 +255,6 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
261
255
char * fnek_src ;
262
256
char * cipher_key_bytes_src ;
263
257
char * fn_cipher_key_bytes_src ;
264
- u8 cipher_code ;
265
-
266
- * check_ruid = 0 ;
267
258
268
259
if (!options ) {
269
260
rc = - EINVAL ;
@@ -285,14 +276,14 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
285
276
"global sig; rc = [%d]\n" , rc );
286
277
goto out ;
287
278
}
288
- sig_set = 1 ;
279
+ mount_crypt_stat -> sig_set = 1 ;
289
280
break ;
290
281
case ecryptfs_opt_cipher :
291
282
case ecryptfs_opt_ecryptfs_cipher :
292
283
cipher_name_src = args [0 ].from ;
293
284
strscpy (mount_crypt_stat -> global_default_cipher_name ,
294
285
cipher_name_src );
295
- cipher_name_set = 1 ;
286
+ mount_crypt_stat -> cipher_name_set = 1 ;
296
287
break ;
297
288
case ecryptfs_opt_ecryptfs_key_bytes :
298
289
cipher_key_bytes_src = args [0 ].from ;
@@ -301,7 +292,7 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
301
292
& cipher_key_bytes_src , 0 );
302
293
mount_crypt_stat -> global_default_cipher_key_size =
303
294
cipher_key_bytes ;
304
- cipher_key_bytes_set = 1 ;
295
+ mount_crypt_stat -> cipher_key_bytes_set = 1 ;
305
296
break ;
306
297
case ecryptfs_opt_passthrough :
307
298
mount_crypt_stat -> flags |=
@@ -340,7 +331,7 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
340
331
fn_cipher_name_src = args [0 ].from ;
341
332
strscpy (mount_crypt_stat -> global_default_fn_cipher_name ,
342
333
fn_cipher_name_src );
343
- fn_cipher_name_set = 1 ;
334
+ mount_crypt_stat -> fn_cipher_name_set = 1 ;
344
335
break ;
345
336
case ecryptfs_opt_fn_cipher_key_bytes :
346
337
fn_cipher_key_bytes_src = args [0 ].from ;
@@ -349,7 +340,7 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
349
340
& fn_cipher_key_bytes_src , 0 );
350
341
mount_crypt_stat -> global_default_fn_cipher_key_bytes =
351
342
fn_cipher_key_bytes ;
352
- fn_cipher_key_bytes_set = 1 ;
343
+ mount_crypt_stat -> fn_cipher_key_bytes_set = 1 ;
353
344
break ;
354
345
case ecryptfs_opt_unlink_sigs :
355
346
mount_crypt_stat -> flags |= ECRYPTFS_UNLINK_SIGS ;
@@ -359,7 +350,7 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
359
350
ECRYPTFS_GLOBAL_MOUNT_AUTH_TOK_ONLY ;
360
351
break ;
361
352
case ecryptfs_opt_check_dev_ruid :
362
- * check_ruid = 1 ;
353
+ mount_crypt_stat -> check_ruid = 1 ;
363
354
break ;
364
355
case ecryptfs_opt_err :
365
356
default :
@@ -368,28 +359,39 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options,
368
359
__func__ , p );
369
360
}
370
361
}
371
- if (!sig_set ) {
362
+
363
+ out :
364
+ return rc ;
365
+ }
366
+
367
+ static int ecryptfs_validate_options (
368
+ struct ecryptfs_mount_crypt_stat * mount_crypt_stat )
369
+ {
370
+ int rc = 0 ;
371
+ u8 cipher_code ;
372
+
373
+ if (!mount_crypt_stat -> sig_set ) {
372
374
rc = - EINVAL ;
373
375
ecryptfs_printk (KERN_ERR , "You must supply at least one valid "
374
376
"auth tok signature as a mount "
375
377
"parameter; see the eCryptfs README\n" );
376
378
goto out ;
377
379
}
378
- if (!cipher_name_set ) {
380
+ if (!mount_crypt_stat -> cipher_name_set ) {
379
381
int cipher_name_len = strlen (ECRYPTFS_DEFAULT_CIPHER );
380
382
381
383
BUG_ON (cipher_name_len > ECRYPTFS_MAX_CIPHER_NAME_SIZE );
382
384
strcpy (mount_crypt_stat -> global_default_cipher_name ,
383
385
ECRYPTFS_DEFAULT_CIPHER );
384
386
}
385
387
if ((mount_crypt_stat -> flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES )
386
- && !fn_cipher_name_set )
388
+ && !mount_crypt_stat -> fn_cipher_name_set )
387
389
strcpy (mount_crypt_stat -> global_default_fn_cipher_name ,
388
390
mount_crypt_stat -> global_default_cipher_name );
389
- if (!cipher_key_bytes_set )
391
+ if (!mount_crypt_stat -> cipher_key_bytes_set )
390
392
mount_crypt_stat -> global_default_cipher_key_size = 0 ;
391
393
if ((mount_crypt_stat -> flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES )
392
- && !fn_cipher_key_bytes_set )
394
+ && !mount_crypt_stat -> fn_cipher_key_bytes_set )
393
395
mount_crypt_stat -> global_default_fn_cipher_key_bytes =
394
396
mount_crypt_stat -> global_default_cipher_key_size ;
395
397
@@ -469,7 +471,6 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
469
471
const char * err = "Getting sb failed" ;
470
472
struct inode * inode ;
471
473
struct path path ;
472
- uid_t check_ruid ;
473
474
int rc ;
474
475
475
476
sbi = kmem_cache_zalloc (ecryptfs_sb_info_cache , GFP_KERNEL );
@@ -484,12 +485,17 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
484
485
goto out ;
485
486
}
486
487
487
- rc = ecryptfs_parse_options (sbi , raw_data , & check_ruid );
488
+ rc = ecryptfs_parse_options (sbi , raw_data );
488
489
if (rc ) {
489
490
err = "Error parsing options" ;
490
491
goto out ;
491
492
}
492
493
mount_crypt_stat = & sbi -> mount_crypt_stat ;
494
+ rc = ecryptfs_validate_options (mount_crypt_stat );
495
+ if (rc ) {
496
+ err = "Error validationg options" ;
497
+ goto out ;
498
+ }
493
499
494
500
s = sget (fs_type , NULL , set_anon_super , flags , NULL );
495
501
if (IS_ERR (s )) {
@@ -529,7 +535,8 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
529
535
goto out_free ;
530
536
}
531
537
532
- if (check_ruid && !uid_eq (d_inode (path .dentry )-> i_uid , current_uid ())) {
538
+ if (mount_crypt_stat -> check_ruid &&
539
+ !uid_eq (d_inode (path .dentry )-> i_uid , current_uid ())) {
533
540
rc = - EPERM ;
534
541
printk (KERN_ERR "Mount of device (uid: %d) not owned by "
535
542
"requested user (uid: %d)\n" ,
0 commit comments