diff options
author | Paul Mundt <lethal@linux-sh.org> | 2011-01-13 01:06:28 -0500 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2011-01-13 01:06:28 -0500 |
commit | f43dc23d5ea91fca257be02138a255f02d98e806 (patch) | |
tree | b29722f6e965316e90ac97abf79923ced250dc21 /fs/ecryptfs/main.c | |
parent | f8e53553f452dcbf67cb89c8cba63a1cd6eb4cc0 (diff) | |
parent | 4162cf64973df51fc885825bc9ca4d055891c49f (diff) |
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/torvalds/linux-2.6 into common/serial-rework
Conflicts:
arch/sh/kernel/cpu/sh2/setup-sh7619.c
arch/sh/kernel/cpu/sh2a/setup-mxg.c
arch/sh/kernel/cpu/sh2a/setup-sh7201.c
arch/sh/kernel/cpu/sh2a/setup-sh7203.c
arch/sh/kernel/cpu/sh2a/setup-sh7206.c
arch/sh/kernel/cpu/sh3/setup-sh7705.c
arch/sh/kernel/cpu/sh3/setup-sh770x.c
arch/sh/kernel/cpu/sh3/setup-sh7710.c
arch/sh/kernel/cpu/sh3/setup-sh7720.c
arch/sh/kernel/cpu/sh4/setup-sh4-202.c
arch/sh/kernel/cpu/sh4/setup-sh7750.c
arch/sh/kernel/cpu/sh4/setup-sh7760.c
arch/sh/kernel/cpu/sh4a/setup-sh7343.c
arch/sh/kernel/cpu/sh4a/setup-sh7366.c
arch/sh/kernel/cpu/sh4a/setup-sh7722.c
arch/sh/kernel/cpu/sh4a/setup-sh7723.c
arch/sh/kernel/cpu/sh4a/setup-sh7724.c
arch/sh/kernel/cpu/sh4a/setup-sh7763.c
arch/sh/kernel/cpu/sh4a/setup-sh7770.c
arch/sh/kernel/cpu/sh4a/setup-sh7780.c
arch/sh/kernel/cpu/sh4a/setup-sh7785.c
arch/sh/kernel/cpu/sh4a/setup-sh7786.c
arch/sh/kernel/cpu/sh4a/setup-shx3.c
arch/sh/kernel/cpu/sh5/setup-sh5.c
drivers/serial/sh-sci.c
drivers/serial/sh-sci.h
include/linux/serial_sci.h
Diffstat (limited to 'fs/ecryptfs/main.c')
-rw-r--r-- | fs/ecryptfs/main.c | 186 |
1 files changed, 97 insertions, 89 deletions
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c index 9f0aa9883c28..351038675376 100644 --- a/fs/ecryptfs/main.c +++ b/fs/ecryptfs/main.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/key.h> | 35 | #include <linux/key.h> |
36 | #include <linux/parser.h> | 36 | #include <linux/parser.h> |
37 | #include <linux/fs_stack.h> | 37 | #include <linux/fs_stack.h> |
38 | #include <linux/slab.h> | ||
38 | #include "ecryptfs_kernel.h" | 39 | #include "ecryptfs_kernel.h" |
39 | 40 | ||
40 | /** | 41 | /** |
@@ -129,11 +130,10 @@ int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry) | |||
129 | lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry); | 130 | lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry); |
130 | rc = ecryptfs_privileged_open(&inode_info->lower_file, | 131 | rc = ecryptfs_privileged_open(&inode_info->lower_file, |
131 | lower_dentry, lower_mnt, cred); | 132 | lower_dentry, lower_mnt, cred); |
132 | if (rc || IS_ERR(inode_info->lower_file)) { | 133 | if (rc) { |
133 | printk(KERN_ERR "Error opening lower persistent file " | 134 | printk(KERN_ERR "Error opening lower persistent file " |
134 | "for lower_dentry [0x%p] and lower_mnt [0x%p]; " | 135 | "for lower_dentry [0x%p] and lower_mnt [0x%p]; " |
135 | "rc = [%d]\n", lower_dentry, lower_mnt, rc); | 136 | "rc = [%d]\n", lower_dentry, lower_mnt, rc); |
136 | rc = PTR_ERR(inode_info->lower_file); | ||
137 | inode_info->lower_file = NULL; | 137 | inode_info->lower_file = NULL; |
138 | } | 138 | } |
139 | } | 139 | } |
@@ -189,8 +189,8 @@ int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry, | |||
189 | if (special_file(lower_inode->i_mode)) | 189 | if (special_file(lower_inode->i_mode)) |
190 | init_special_inode(inode, lower_inode->i_mode, | 190 | init_special_inode(inode, lower_inode->i_mode, |
191 | lower_inode->i_rdev); | 191 | lower_inode->i_rdev); |
192 | dentry->d_op = &ecryptfs_dops; | 192 | d_set_d_op(dentry, &ecryptfs_dops); |
193 | fsstack_copy_attr_all(inode, lower_inode, NULL); | 193 | fsstack_copy_attr_all(inode, lower_inode); |
194 | /* This size will be overwritten for real files w/ headers and | 194 | /* This size will be overwritten for real files w/ headers and |
195 | * other metadata */ | 195 | * other metadata */ |
196 | fsstack_copy_inode_size(inode, lower_inode); | 196 | fsstack_copy_inode_size(inode, lower_inode); |
@@ -208,7 +208,8 @@ enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig, | |||
208 | ecryptfs_opt_passthrough, ecryptfs_opt_xattr_metadata, | 208 | ecryptfs_opt_passthrough, ecryptfs_opt_xattr_metadata, |
209 | ecryptfs_opt_encrypted_view, ecryptfs_opt_fnek_sig, | 209 | ecryptfs_opt_encrypted_view, ecryptfs_opt_fnek_sig, |
210 | ecryptfs_opt_fn_cipher, ecryptfs_opt_fn_cipher_key_bytes, | 210 | ecryptfs_opt_fn_cipher, ecryptfs_opt_fn_cipher_key_bytes, |
211 | ecryptfs_opt_unlink_sigs, ecryptfs_opt_err }; | 211 | ecryptfs_opt_unlink_sigs, ecryptfs_opt_mount_auth_tok_only, |
212 | ecryptfs_opt_err }; | ||
212 | 213 | ||
213 | static const match_table_t tokens = { | 214 | static const match_table_t tokens = { |
214 | {ecryptfs_opt_sig, "sig=%s"}, | 215 | {ecryptfs_opt_sig, "sig=%s"}, |
@@ -223,6 +224,7 @@ static const match_table_t tokens = { | |||
223 | {ecryptfs_opt_fn_cipher, "ecryptfs_fn_cipher=%s"}, | 224 | {ecryptfs_opt_fn_cipher, "ecryptfs_fn_cipher=%s"}, |
224 | {ecryptfs_opt_fn_cipher_key_bytes, "ecryptfs_fn_key_bytes=%u"}, | 225 | {ecryptfs_opt_fn_cipher_key_bytes, "ecryptfs_fn_key_bytes=%u"}, |
225 | {ecryptfs_opt_unlink_sigs, "ecryptfs_unlink_sigs"}, | 226 | {ecryptfs_opt_unlink_sigs, "ecryptfs_unlink_sigs"}, |
227 | {ecryptfs_opt_mount_auth_tok_only, "ecryptfs_mount_auth_tok_only"}, | ||
226 | {ecryptfs_opt_err, NULL} | 228 | {ecryptfs_opt_err, NULL} |
227 | }; | 229 | }; |
228 | 230 | ||
@@ -281,7 +283,7 @@ static void ecryptfs_init_mount_crypt_stat( | |||
281 | * | 283 | * |
282 | * Returns zero on success; non-zero on error | 284 | * Returns zero on success; non-zero on error |
283 | */ | 285 | */ |
284 | static int ecryptfs_parse_options(struct super_block *sb, char *options) | 286 | static int ecryptfs_parse_options(struct ecryptfs_sb_info *sbi, char *options) |
285 | { | 287 | { |
286 | char *p; | 288 | char *p; |
287 | int rc = 0; | 289 | int rc = 0; |
@@ -293,7 +295,7 @@ static int ecryptfs_parse_options(struct super_block *sb, char *options) | |||
293 | int fn_cipher_key_bytes; | 295 | int fn_cipher_key_bytes; |
294 | int fn_cipher_key_bytes_set = 0; | 296 | int fn_cipher_key_bytes_set = 0; |
295 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat = | 297 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat = |
296 | &ecryptfs_superblock_to_private(sb)->mount_crypt_stat; | 298 | &sbi->mount_crypt_stat; |
297 | substring_t args[MAX_OPT_ARGS]; | 299 | substring_t args[MAX_OPT_ARGS]; |
298 | int token; | 300 | int token; |
299 | char *sig_src; | 301 | char *sig_src; |
@@ -406,6 +408,10 @@ static int ecryptfs_parse_options(struct super_block *sb, char *options) | |||
406 | case ecryptfs_opt_unlink_sigs: | 408 | case ecryptfs_opt_unlink_sigs: |
407 | mount_crypt_stat->flags |= ECRYPTFS_UNLINK_SIGS; | 409 | mount_crypt_stat->flags |= ECRYPTFS_UNLINK_SIGS; |
408 | break; | 410 | break; |
411 | case ecryptfs_opt_mount_auth_tok_only: | ||
412 | mount_crypt_stat->flags |= | ||
413 | ECRYPTFS_GLOBAL_MOUNT_AUTH_TOK_ONLY; | ||
414 | break; | ||
409 | case ecryptfs_opt_err: | 415 | case ecryptfs_opt_err: |
410 | default: | 416 | default: |
411 | printk(KERN_WARNING | 417 | printk(KERN_WARNING |
@@ -483,60 +489,7 @@ out: | |||
483 | } | 489 | } |
484 | 490 | ||
485 | struct kmem_cache *ecryptfs_sb_info_cache; | 491 | struct kmem_cache *ecryptfs_sb_info_cache; |
486 | 492 | static struct file_system_type ecryptfs_fs_type; | |
487 | /** | ||
488 | * ecryptfs_fill_super | ||
489 | * @sb: The ecryptfs super block | ||
490 | * @raw_data: The options passed to mount | ||
491 | * @silent: Not used but required by function prototype | ||
492 | * | ||
493 | * Sets up what we can of the sb, rest is done in ecryptfs_read_super | ||
494 | * | ||
495 | * Returns zero on success; non-zero otherwise | ||
496 | */ | ||
497 | static int | ||
498 | ecryptfs_fill_super(struct super_block *sb, void *raw_data, int silent) | ||
499 | { | ||
500 | int rc = 0; | ||
501 | |||
502 | /* Released in ecryptfs_put_super() */ | ||
503 | ecryptfs_set_superblock_private(sb, | ||
504 | kmem_cache_zalloc(ecryptfs_sb_info_cache, | ||
505 | GFP_KERNEL)); | ||
506 | if (!ecryptfs_superblock_to_private(sb)) { | ||
507 | ecryptfs_printk(KERN_WARNING, "Out of memory\n"); | ||
508 | rc = -ENOMEM; | ||
509 | goto out; | ||
510 | } | ||
511 | sb->s_op = &ecryptfs_sops; | ||
512 | /* Released through deactivate_super(sb) from get_sb_nodev */ | ||
513 | sb->s_root = d_alloc(NULL, &(const struct qstr) { | ||
514 | .hash = 0,.name = "/",.len = 1}); | ||
515 | if (!sb->s_root) { | ||
516 | ecryptfs_printk(KERN_ERR, "d_alloc failed\n"); | ||
517 | rc = -ENOMEM; | ||
518 | goto out; | ||
519 | } | ||
520 | sb->s_root->d_op = &ecryptfs_dops; | ||
521 | sb->s_root->d_sb = sb; | ||
522 | sb->s_root->d_parent = sb->s_root; | ||
523 | /* Released in d_release when dput(sb->s_root) is called */ | ||
524 | /* through deactivate_super(sb) from get_sb_nodev() */ | ||
525 | ecryptfs_set_dentry_private(sb->s_root, | ||
526 | kmem_cache_zalloc(ecryptfs_dentry_info_cache, | ||
527 | GFP_KERNEL)); | ||
528 | if (!ecryptfs_dentry_to_private(sb->s_root)) { | ||
529 | ecryptfs_printk(KERN_ERR, | ||
530 | "dentry_info_cache alloc failed\n"); | ||
531 | rc = -ENOMEM; | ||
532 | goto out; | ||
533 | } | ||
534 | rc = 0; | ||
535 | out: | ||
536 | /* Should be able to rely on deactivate_super called from | ||
537 | * get_sb_nodev */ | ||
538 | return rc; | ||
539 | } | ||
540 | 493 | ||
541 | /** | 494 | /** |
542 | * ecryptfs_read_super | 495 | * ecryptfs_read_super |
@@ -557,6 +510,13 @@ static int ecryptfs_read_super(struct super_block *sb, const char *dev_name) | |||
557 | ecryptfs_printk(KERN_WARNING, "path_lookup() failed\n"); | 510 | ecryptfs_printk(KERN_WARNING, "path_lookup() failed\n"); |
558 | goto out; | 511 | goto out; |
559 | } | 512 | } |
513 | if (path.dentry->d_sb->s_type == &ecryptfs_fs_type) { | ||
514 | rc = -EINVAL; | ||
515 | printk(KERN_ERR "Mount on filesystem of type " | ||
516 | "eCryptfs explicitly disallowed due to " | ||
517 | "known incompatibilities\n"); | ||
518 | goto out_free; | ||
519 | } | ||
560 | ecryptfs_set_superblock_lower(sb, path.dentry->d_sb); | 520 | ecryptfs_set_superblock_lower(sb, path.dentry->d_sb); |
561 | sb->s_maxbytes = path.dentry->d_sb->s_maxbytes; | 521 | sb->s_maxbytes = path.dentry->d_sb->s_maxbytes; |
562 | sb->s_blocksize = path.dentry->d_sb->s_blocksize; | 522 | sb->s_blocksize = path.dentry->d_sb->s_blocksize; |
@@ -580,44 +540,87 @@ out: | |||
580 | * @dev_name: The path to mount over | 540 | * @dev_name: The path to mount over |
581 | * @raw_data: The options passed into the kernel | 541 | * @raw_data: The options passed into the kernel |
582 | * | 542 | * |
583 | * The whole ecryptfs_get_sb process is broken into 4 functions: | 543 | * The whole ecryptfs_get_sb process is broken into 3 functions: |
584 | * ecryptfs_parse_options(): handle options passed to ecryptfs, if any | 544 | * ecryptfs_parse_options(): handle options passed to ecryptfs, if any |
585 | * ecryptfs_fill_super(): used by get_sb_nodev, fills out the super_block | ||
586 | * with as much information as it can before needing | ||
587 | * the lower filesystem. | ||
588 | * ecryptfs_read_super(): this accesses the lower filesystem and uses | 545 | * ecryptfs_read_super(): this accesses the lower filesystem and uses |
589 | * ecryptfs_interpolate to perform most of the linking | 546 | * ecryptfs_interpose to perform most of the linking |
590 | * ecryptfs_interpolate(): links the lower filesystem into ecryptfs | 547 | * ecryptfs_interpose(): links the lower filesystem into ecryptfs (inode.c) |
591 | */ | 548 | */ |
592 | static int ecryptfs_get_sb(struct file_system_type *fs_type, int flags, | 549 | static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags, |
593 | const char *dev_name, void *raw_data, | 550 | const char *dev_name, void *raw_data) |
594 | struct vfsmount *mnt) | ||
595 | { | 551 | { |
552 | struct super_block *s; | ||
553 | struct ecryptfs_sb_info *sbi; | ||
554 | struct ecryptfs_dentry_info *root_info; | ||
555 | const char *err = "Getting sb failed"; | ||
596 | int rc; | 556 | int rc; |
597 | struct super_block *sb; | ||
598 | 557 | ||
599 | rc = get_sb_nodev(fs_type, flags, raw_data, ecryptfs_fill_super, mnt); | 558 | sbi = kmem_cache_zalloc(ecryptfs_sb_info_cache, GFP_KERNEL); |
600 | if (rc < 0) { | 559 | if (!sbi) { |
601 | printk(KERN_ERR "Getting sb failed; rc = [%d]\n", rc); | 560 | rc = -ENOMEM; |
602 | goto out; | 561 | goto out; |
603 | } | 562 | } |
604 | sb = mnt->mnt_sb; | 563 | |
605 | rc = ecryptfs_parse_options(sb, raw_data); | 564 | rc = ecryptfs_parse_options(sbi, raw_data); |
606 | if (rc) { | 565 | if (rc) { |
607 | printk(KERN_ERR "Error parsing options; rc = [%d]\n", rc); | 566 | err = "Error parsing options"; |
608 | goto out_abort; | 567 | goto out; |
568 | } | ||
569 | |||
570 | s = sget(fs_type, NULL, set_anon_super, NULL); | ||
571 | if (IS_ERR(s)) { | ||
572 | rc = PTR_ERR(s); | ||
573 | goto out; | ||
609 | } | 574 | } |
610 | rc = ecryptfs_read_super(sb, dev_name); | 575 | |
576 | s->s_flags = flags; | ||
577 | rc = bdi_setup_and_register(&sbi->bdi, "ecryptfs", BDI_CAP_MAP_COPY); | ||
611 | if (rc) { | 578 | if (rc) { |
612 | printk(KERN_ERR "Reading sb failed; rc = [%d]\n", rc); | 579 | deactivate_locked_super(s); |
613 | goto out_abort; | 580 | goto out; |
614 | } | 581 | } |
615 | goto out; | 582 | |
616 | out_abort: | 583 | ecryptfs_set_superblock_private(s, sbi); |
617 | dput(sb->s_root); /* aka mnt->mnt_root, as set by get_sb_nodev() */ | 584 | s->s_bdi = &sbi->bdi; |
618 | deactivate_locked_super(sb); | 585 | |
586 | /* ->kill_sb() will take care of sbi after that point */ | ||
587 | sbi = NULL; | ||
588 | s->s_op = &ecryptfs_sops; | ||
589 | |||
590 | rc = -ENOMEM; | ||
591 | s->s_root = d_alloc(NULL, &(const struct qstr) { | ||
592 | .hash = 0,.name = "/",.len = 1}); | ||
593 | if (!s->s_root) { | ||
594 | deactivate_locked_super(s); | ||
595 | goto out; | ||
596 | } | ||
597 | d_set_d_op(s->s_root, &ecryptfs_dops); | ||
598 | s->s_root->d_sb = s; | ||
599 | s->s_root->d_parent = s->s_root; | ||
600 | |||
601 | root_info = kmem_cache_zalloc(ecryptfs_dentry_info_cache, GFP_KERNEL); | ||
602 | if (!root_info) { | ||
603 | deactivate_locked_super(s); | ||
604 | goto out; | ||
605 | } | ||
606 | /* ->kill_sb() will take care of root_info */ | ||
607 | ecryptfs_set_dentry_private(s->s_root, root_info); | ||
608 | s->s_flags |= MS_ACTIVE; | ||
609 | rc = ecryptfs_read_super(s, dev_name); | ||
610 | if (rc) { | ||
611 | deactivate_locked_super(s); | ||
612 | err = "Reading sb failed"; | ||
613 | goto out; | ||
614 | } | ||
615 | return dget(s->s_root); | ||
616 | |||
619 | out: | 617 | out: |
620 | return rc; | 618 | if (sbi) { |
619 | ecryptfs_destroy_mount_crypt_stat(&sbi->mount_crypt_stat); | ||
620 | kmem_cache_free(ecryptfs_sb_info_cache, sbi); | ||
621 | } | ||
622 | printk(KERN_ERR "%s; rc = [%d]\n", err, rc); | ||
623 | return ERR_PTR(rc); | ||
621 | } | 624 | } |
622 | 625 | ||
623 | /** | 626 | /** |
@@ -625,17 +628,22 @@ out: | |||
625 | * @sb: The ecryptfs super block | 628 | * @sb: The ecryptfs super block |
626 | * | 629 | * |
627 | * Used to bring the superblock down and free the private data. | 630 | * Used to bring the superblock down and free the private data. |
628 | * Private data is free'd in ecryptfs_put_super() | ||
629 | */ | 631 | */ |
630 | static void ecryptfs_kill_block_super(struct super_block *sb) | 632 | static void ecryptfs_kill_block_super(struct super_block *sb) |
631 | { | 633 | { |
632 | generic_shutdown_super(sb); | 634 | struct ecryptfs_sb_info *sb_info = ecryptfs_superblock_to_private(sb); |
635 | kill_anon_super(sb); | ||
636 | if (!sb_info) | ||
637 | return; | ||
638 | ecryptfs_destroy_mount_crypt_stat(&sb_info->mount_crypt_stat); | ||
639 | bdi_destroy(&sb_info->bdi); | ||
640 | kmem_cache_free(ecryptfs_sb_info_cache, sb_info); | ||
633 | } | 641 | } |
634 | 642 | ||
635 | static struct file_system_type ecryptfs_fs_type = { | 643 | static struct file_system_type ecryptfs_fs_type = { |
636 | .owner = THIS_MODULE, | 644 | .owner = THIS_MODULE, |
637 | .name = "ecryptfs", | 645 | .name = "ecryptfs", |
638 | .get_sb = ecryptfs_get_sb, | 646 | .mount = ecryptfs_mount, |
639 | .kill_sb = ecryptfs_kill_block_super, | 647 | .kill_sb = ecryptfs_kill_block_super, |
640 | .fs_flags = 0 | 648 | .fs_flags = 0 |
641 | }; | 649 | }; |