diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2019-03-12 17:08:19 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-03-12 17:08:19 -0400 |
commit | 7b47a9e7c8f672b6fb0b77fca11a63a8a77f5a91 (patch) | |
tree | cf05645120ba2323c36acefdea6e62addf320f8c /security/selinux | |
parent | dbc2fba3fc46084f502aec53183995a632998dcd (diff) | |
parent | c99c2171fc61476afac0dfb59fb2c447a01fb1e0 (diff) |
Merge branch 'work.mount' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs mount infrastructure updates from Al Viro:
"The rest of core infrastructure; no new syscalls in that pile, but the
old parts are switched to new infrastructure. At that point
conversions of individual filesystems can happen independently; some
are done here (afs, cgroup, procfs, etc.), there's also a large series
outside of that pile dealing with NFS (quite a bit of option-parsing
stuff is getting used there - it's one of the most convoluted
filesystems in terms of mount-related logics), but NFS bits are the
next cycle fodder.
It got seriously simplified since the last cycle; documentation is
probably the weakest bit at the moment - I considered dropping the
commit introducing Documentation/filesystems/mount_api.txt (cutting
the size increase by quarter ;-), but decided that it would be better
to fix it up after -rc1 instead.
That pile allows to do followup work in independent branches, which
should make life much easier for the next cycle. fs/super.c size
increase is unpleasant; there's a followup series that allows to
shrink it considerably, but I decided to leave that until the next
cycle"
* 'work.mount' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (41 commits)
afs: Use fs_context to pass parameters over automount
afs: Add fs_context support
vfs: Add some logging to the core users of the fs_context log
vfs: Implement logging through fs_context
vfs: Provide documentation for new mount API
vfs: Remove kern_mount_data()
hugetlbfs: Convert to fs_context
cpuset: Use fs_context
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
cgroup: store a reference to cgroup_ns into cgroup_fs_context
cgroup1_get_tree(): separate "get cgroup_root to use" into a separate helper
cgroup_do_mount(): massage calling conventions
cgroup: stash cgroup_root reference into cgroup_fs_context
cgroup2: switch to option-by-option parsing
cgroup1: switch to option-by-option parsing
cgroup: take options parsing into ->parse_monolithic()
cgroup: fold cgroup1_mount() into cgroup1_get_tree()
cgroup: start switching to fs_context
ipc: Convert mqueue fs to fs_context
proc: Add fs_context support to procfs
...
Diffstat (limited to 'security/selinux')
-rw-r--r-- | security/selinux/hooks.c | 88 | ||||
-rw-r--r-- | security/selinux/include/security.h | 10 |
2 files changed, 88 insertions, 10 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 333606b3a8ef..c5363f0c67ef 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
@@ -48,6 +48,8 @@ | |||
48 | #include <linux/fdtable.h> | 48 | #include <linux/fdtable.h> |
49 | #include <linux/namei.h> | 49 | #include <linux/namei.h> |
50 | #include <linux/mount.h> | 50 | #include <linux/mount.h> |
51 | #include <linux/fs_context.h> | ||
52 | #include <linux/fs_parser.h> | ||
51 | #include <linux/netfilter_ipv4.h> | 53 | #include <linux/netfilter_ipv4.h> |
52 | #include <linux/netfilter_ipv6.h> | 54 | #include <linux/netfilter_ipv6.h> |
53 | #include <linux/tty.h> | 55 | #include <linux/tty.h> |
@@ -410,11 +412,11 @@ static inline int inode_doinit(struct inode *inode) | |||
410 | 412 | ||
411 | enum { | 413 | enum { |
412 | Opt_error = -1, | 414 | Opt_error = -1, |
413 | Opt_context = 1, | 415 | Opt_context = 0, |
416 | Opt_defcontext = 1, | ||
414 | Opt_fscontext = 2, | 417 | Opt_fscontext = 2, |
415 | Opt_defcontext = 3, | 418 | Opt_rootcontext = 3, |
416 | Opt_rootcontext = 4, | 419 | Opt_seclabel = 4, |
417 | Opt_seclabel = 5, | ||
418 | }; | 420 | }; |
419 | 421 | ||
420 | #define A(s, has_arg) {#s, sizeof(#s) - 1, Opt_##s, has_arg} | 422 | #define A(s, has_arg) {#s, sizeof(#s) - 1, Opt_##s, has_arg} |
@@ -1067,6 +1069,7 @@ static int show_sid(struct seq_file *m, u32 sid) | |||
1067 | if (!rc) { | 1069 | if (!rc) { |
1068 | bool has_comma = context && strchr(context, ','); | 1070 | bool has_comma = context && strchr(context, ','); |
1069 | 1071 | ||
1072 | seq_putc(m, '='); | ||
1070 | if (has_comma) | 1073 | if (has_comma) |
1071 | seq_putc(m, '\"'); | 1074 | seq_putc(m, '\"'); |
1072 | seq_escape(m, context, "\"\n\\"); | 1075 | seq_escape(m, context, "\"\n\\"); |
@@ -1120,7 +1123,7 @@ static int selinux_sb_show_options(struct seq_file *m, struct super_block *sb) | |||
1120 | } | 1123 | } |
1121 | if (sbsec->flags & SBLABEL_MNT) { | 1124 | if (sbsec->flags & SBLABEL_MNT) { |
1122 | seq_putc(m, ','); | 1125 | seq_putc(m, ','); |
1123 | seq_puts(m, LABELSUPP_STR); | 1126 | seq_puts(m, SECLABEL_STR); |
1124 | } | 1127 | } |
1125 | return 0; | 1128 | return 0; |
1126 | } | 1129 | } |
@@ -2739,6 +2742,76 @@ static int selinux_umount(struct vfsmount *mnt, int flags) | |||
2739 | FILESYSTEM__UNMOUNT, NULL); | 2742 | FILESYSTEM__UNMOUNT, NULL); |
2740 | } | 2743 | } |
2741 | 2744 | ||
2745 | static int selinux_fs_context_dup(struct fs_context *fc, | ||
2746 | struct fs_context *src_fc) | ||
2747 | { | ||
2748 | const struct selinux_mnt_opts *src = src_fc->security; | ||
2749 | struct selinux_mnt_opts *opts; | ||
2750 | |||
2751 | if (!src) | ||
2752 | return 0; | ||
2753 | |||
2754 | fc->security = kzalloc(sizeof(struct selinux_mnt_opts), GFP_KERNEL); | ||
2755 | if (!fc->security) | ||
2756 | return -ENOMEM; | ||
2757 | |||
2758 | opts = fc->security; | ||
2759 | |||
2760 | if (src->fscontext) { | ||
2761 | opts->fscontext = kstrdup(src->fscontext, GFP_KERNEL); | ||
2762 | if (!opts->fscontext) | ||
2763 | return -ENOMEM; | ||
2764 | } | ||
2765 | if (src->context) { | ||
2766 | opts->context = kstrdup(src->context, GFP_KERNEL); | ||
2767 | if (!opts->context) | ||
2768 | return -ENOMEM; | ||
2769 | } | ||
2770 | if (src->rootcontext) { | ||
2771 | opts->rootcontext = kstrdup(src->rootcontext, GFP_KERNEL); | ||
2772 | if (!opts->rootcontext) | ||
2773 | return -ENOMEM; | ||
2774 | } | ||
2775 | if (src->defcontext) { | ||
2776 | opts->defcontext = kstrdup(src->defcontext, GFP_KERNEL); | ||
2777 | if (!opts->defcontext) | ||
2778 | return -ENOMEM; | ||
2779 | } | ||
2780 | return 0; | ||
2781 | } | ||
2782 | |||
2783 | static const struct fs_parameter_spec selinux_param_specs[] = { | ||
2784 | fsparam_string(CONTEXT_STR, Opt_context), | ||
2785 | fsparam_string(DEFCONTEXT_STR, Opt_defcontext), | ||
2786 | fsparam_string(FSCONTEXT_STR, Opt_fscontext), | ||
2787 | fsparam_string(ROOTCONTEXT_STR, Opt_rootcontext), | ||
2788 | fsparam_flag (SECLABEL_STR, Opt_seclabel), | ||
2789 | {} | ||
2790 | }; | ||
2791 | |||
2792 | static const struct fs_parameter_description selinux_fs_parameters = { | ||
2793 | .name = "SELinux", | ||
2794 | .specs = selinux_param_specs, | ||
2795 | }; | ||
2796 | |||
2797 | static int selinux_fs_context_parse_param(struct fs_context *fc, | ||
2798 | struct fs_parameter *param) | ||
2799 | { | ||
2800 | struct fs_parse_result result; | ||
2801 | int opt, rc; | ||
2802 | |||
2803 | opt = fs_parse(fc, &selinux_fs_parameters, param, &result); | ||
2804 | if (opt < 0) | ||
2805 | return opt; | ||
2806 | |||
2807 | rc = selinux_add_opt(opt, param->string, &fc->security); | ||
2808 | if (!rc) { | ||
2809 | param->string = NULL; | ||
2810 | rc = 1; | ||
2811 | } | ||
2812 | return rc; | ||
2813 | } | ||
2814 | |||
2742 | /* inode security operations */ | 2815 | /* inode security operations */ |
2743 | 2816 | ||
2744 | static int selinux_inode_alloc_security(struct inode *inode) | 2817 | static int selinux_inode_alloc_security(struct inode *inode) |
@@ -6592,6 +6665,9 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = { | |||
6592 | LSM_HOOK_INIT(bprm_committing_creds, selinux_bprm_committing_creds), | 6665 | LSM_HOOK_INIT(bprm_committing_creds, selinux_bprm_committing_creds), |
6593 | LSM_HOOK_INIT(bprm_committed_creds, selinux_bprm_committed_creds), | 6666 | LSM_HOOK_INIT(bprm_committed_creds, selinux_bprm_committed_creds), |
6594 | 6667 | ||
6668 | LSM_HOOK_INIT(fs_context_dup, selinux_fs_context_dup), | ||
6669 | LSM_HOOK_INIT(fs_context_parse_param, selinux_fs_context_parse_param), | ||
6670 | |||
6595 | LSM_HOOK_INIT(sb_alloc_security, selinux_sb_alloc_security), | 6671 | LSM_HOOK_INIT(sb_alloc_security, selinux_sb_alloc_security), |
6596 | LSM_HOOK_INIT(sb_free_security, selinux_sb_free_security), | 6672 | LSM_HOOK_INIT(sb_free_security, selinux_sb_free_security), |
6597 | LSM_HOOK_INIT(sb_eat_lsm_opts, selinux_sb_eat_lsm_opts), | 6673 | LSM_HOOK_INIT(sb_eat_lsm_opts, selinux_sb_eat_lsm_opts), |
@@ -6837,6 +6913,8 @@ static __init int selinux_init(void) | |||
6837 | else | 6913 | else |
6838 | pr_debug("SELinux: Starting in permissive mode\n"); | 6914 | pr_debug("SELinux: Starting in permissive mode\n"); |
6839 | 6915 | ||
6916 | fs_validate_description(&selinux_fs_parameters); | ||
6917 | |||
6840 | return 0; | 6918 | return 0; |
6841 | } | 6919 | } |
6842 | 6920 | ||
diff --git a/security/selinux/include/security.h b/security/selinux/include/security.h index f68fb25b5702..b5b7c5aade8c 100644 --- a/security/selinux/include/security.h +++ b/security/selinux/include/security.h | |||
@@ -59,11 +59,11 @@ | |||
59 | #define SE_SBPROC 0x0200 | 59 | #define SE_SBPROC 0x0200 |
60 | #define SE_SBGENFS 0x0400 | 60 | #define SE_SBGENFS 0x0400 |
61 | 61 | ||
62 | #define CONTEXT_STR "context=" | 62 | #define CONTEXT_STR "context" |
63 | #define FSCONTEXT_STR "fscontext=" | 63 | #define FSCONTEXT_STR "fscontext" |
64 | #define ROOTCONTEXT_STR "rootcontext=" | 64 | #define ROOTCONTEXT_STR "rootcontext" |
65 | #define DEFCONTEXT_STR "defcontext=" | 65 | #define DEFCONTEXT_STR "defcontext" |
66 | #define LABELSUPP_STR "seclabel" | 66 | #define SECLABEL_STR "seclabel" |
67 | 67 | ||
68 | struct netlbl_lsm_secattr; | 68 | struct netlbl_lsm_secattr; |
69 | 69 | ||