diff options
Diffstat (limited to 'security/smack/smack_lsm.c')
-rw-r--r-- | security/smack/smack_lsm.c | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 1b40e558f983..87d75417ea93 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c | |||
@@ -87,27 +87,46 @@ struct inode_smack *new_inode_smack(char *smack) | |||
87 | */ | 87 | */ |
88 | 88 | ||
89 | /** | 89 | /** |
90 | * smack_ptrace - Smack approval on ptrace | 90 | * smack_ptrace_may_access - Smack approval on PTRACE_ATTACH |
91 | * @ptp: parent task pointer | ||
92 | * @ctp: child task pointer | 91 | * @ctp: child task pointer |
93 | * | 92 | * |
94 | * Returns 0 if access is OK, an error code otherwise | 93 | * Returns 0 if access is OK, an error code otherwise |
95 | * | 94 | * |
96 | * Do the capability checks, and require read and write. | 95 | * Do the capability checks, and require read and write. |
97 | */ | 96 | */ |
98 | static int smack_ptrace(struct task_struct *ptp, struct task_struct *ctp, | 97 | static int smack_ptrace_may_access(struct task_struct *ctp, unsigned int mode) |
99 | unsigned int mode) | ||
100 | { | 98 | { |
101 | int rc; | 99 | int rc; |
102 | 100 | ||
103 | rc = cap_ptrace(ptp, ctp, mode); | 101 | rc = cap_ptrace_may_access(ctp, mode); |
104 | if (rc != 0) | 102 | if (rc != 0) |
105 | return rc; | 103 | return rc; |
106 | 104 | ||
107 | rc = smk_access(ptp->security, ctp->security, MAY_READWRITE); | 105 | rc = smk_access(current->security, ctp->security, MAY_READWRITE); |
108 | if (rc != 0 && __capable(ptp, CAP_MAC_OVERRIDE)) | 106 | if (rc != 0 && capable(CAP_MAC_OVERRIDE)) |
109 | return 0; | 107 | return 0; |
108 | return rc; | ||
109 | } | ||
110 | |||
111 | /** | ||
112 | * smack_ptrace_traceme - Smack approval on PTRACE_TRACEME | ||
113 | * @ptp: parent task pointer | ||
114 | * | ||
115 | * Returns 0 if access is OK, an error code otherwise | ||
116 | * | ||
117 | * Do the capability checks, and require read and write. | ||
118 | */ | ||
119 | static int smack_ptrace_traceme(struct task_struct *ptp) | ||
120 | { | ||
121 | int rc; | ||
122 | |||
123 | rc = cap_ptrace_traceme(ptp); | ||
124 | if (rc != 0) | ||
125 | return rc; | ||
110 | 126 | ||
127 | rc = smk_access(ptp->security, current->security, MAY_READWRITE); | ||
128 | if (rc != 0 && has_capability(ptp, CAP_MAC_OVERRIDE)) | ||
129 | return 0; | ||
111 | return rc; | 130 | return rc; |
112 | } | 131 | } |
113 | 132 | ||
@@ -923,7 +942,7 @@ static int smack_file_send_sigiotask(struct task_struct *tsk, | |||
923 | */ | 942 | */ |
924 | file = container_of(fown, struct file, f_owner); | 943 | file = container_of(fown, struct file, f_owner); |
925 | rc = smk_access(file->f_security, tsk->security, MAY_WRITE); | 944 | rc = smk_access(file->f_security, tsk->security, MAY_WRITE); |
926 | if (rc != 0 && __capable(tsk, CAP_MAC_OVERRIDE)) | 945 | if (rc != 0 && has_capability(tsk, CAP_MAC_OVERRIDE)) |
927 | return 0; | 946 | return 0; |
928 | return rc; | 947 | return rc; |
929 | } | 948 | } |
@@ -1164,12 +1183,12 @@ static int smack_task_wait(struct task_struct *p) | |||
1164 | * account for the smack labels having gotten to | 1183 | * account for the smack labels having gotten to |
1165 | * be different in the first place. | 1184 | * be different in the first place. |
1166 | * | 1185 | * |
1167 | * This breaks the strict subjet/object access | 1186 | * This breaks the strict subject/object access |
1168 | * control ideal, taking the object's privilege | 1187 | * control ideal, taking the object's privilege |
1169 | * state into account in the decision as well as | 1188 | * state into account in the decision as well as |
1170 | * the smack value. | 1189 | * the smack value. |
1171 | */ | 1190 | */ |
1172 | if (capable(CAP_MAC_OVERRIDE) || __capable(p, CAP_MAC_OVERRIDE)) | 1191 | if (capable(CAP_MAC_OVERRIDE) || has_capability(p, CAP_MAC_OVERRIDE)) |
1173 | return 0; | 1192 | return 0; |
1174 | 1193 | ||
1175 | return rc; | 1194 | return rc; |
@@ -2016,9 +2035,6 @@ static int smack_setprocattr(struct task_struct *p, char *name, | |||
2016 | { | 2035 | { |
2017 | char *newsmack; | 2036 | char *newsmack; |
2018 | 2037 | ||
2019 | if (!__capable(p, CAP_MAC_ADMIN)) | ||
2020 | return -EPERM; | ||
2021 | |||
2022 | /* | 2038 | /* |
2023 | * Changing another process' Smack value is too dangerous | 2039 | * Changing another process' Smack value is too dangerous |
2024 | * and supports no sane use case. | 2040 | * and supports no sane use case. |
@@ -2026,6 +2042,9 @@ static int smack_setprocattr(struct task_struct *p, char *name, | |||
2026 | if (p != current) | 2042 | if (p != current) |
2027 | return -EPERM; | 2043 | return -EPERM; |
2028 | 2044 | ||
2045 | if (!capable(CAP_MAC_ADMIN)) | ||
2046 | return -EPERM; | ||
2047 | |||
2029 | if (value == NULL || size == 0 || size >= SMK_LABELLEN) | 2048 | if (value == NULL || size == 0 || size >= SMK_LABELLEN) |
2030 | return -EINVAL; | 2049 | return -EINVAL; |
2031 | 2050 | ||
@@ -2552,7 +2571,8 @@ static void smack_release_secctx(char *secdata, u32 seclen) | |||
2552 | struct security_operations smack_ops = { | 2571 | struct security_operations smack_ops = { |
2553 | .name = "smack", | 2572 | .name = "smack", |
2554 | 2573 | ||
2555 | .ptrace = smack_ptrace, | 2574 | .ptrace_may_access = smack_ptrace_may_access, |
2575 | .ptrace_traceme = smack_ptrace_traceme, | ||
2556 | .capget = cap_capget, | 2576 | .capget = cap_capget, |
2557 | .capset_check = cap_capset_check, | 2577 | .capset_check = cap_capset_check, |
2558 | .capset_set = cap_capset_set, | 2578 | .capset_set = cap_capset_set, |
@@ -2729,4 +2749,3 @@ static __init int smack_init(void) | |||
2729 | * all processes and objects when they are created. | 2749 | * all processes and objects when they are created. |
2730 | */ | 2750 | */ |
2731 | security_initcall(smack_init); | 2751 | security_initcall(smack_init); |
2732 | |||