aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux/hooks.c
diff options
context:
space:
mode:
authorStephen Smalley <sds@tycho.nsa.gov>2017-04-20 11:31:30 -0400
committerPaul Moore <paul@paul-moore.com>2017-05-23 10:23:22 -0400
commitdb59000ab760f8d77b07b7f2898ff61110f88607 (patch)
treedf6808b9f383cc449bff7630f8448319acaa475c /security/selinux/hooks.c
parent46be14d2b6fbc20c9e7008ec8c28b40609ef6f22 (diff)
selinux: only invoke capabilities and selinux for CAP_MAC_ADMIN checks
SELinux uses CAP_MAC_ADMIN to control the ability to get or set a raw, uninterpreted security context unknown to the currently loaded security policy. When performing these checks, we only want to perform a base capabilities check and a SELinux permission check. If any other modules that implement a capable hook are stacked with SELinux, we do not want to require them to also have to authorize CAP_MAC_ADMIN, since it may have different implications for their security model. Rework the CAP_MAC_ADMIN checks within SELinux to only invoke the capabilities module and the SELinux permission checking. Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov> Signed-off-by: Paul Moore <paul@paul-moore.com>
Diffstat (limited to 'security/selinux/hooks.c')
-rw-r--r--security/selinux/hooks.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 735609b19e76..dddb81e06d2d 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3107,6 +3107,18 @@ static int selinux_inode_setotherxattr(struct dentry *dentry, const char *name)
3107 return dentry_has_perm(cred, dentry, FILE__SETATTR); 3107 return dentry_has_perm(cred, dentry, FILE__SETATTR);
3108} 3108}
3109 3109
3110static bool has_cap_mac_admin(bool audit)
3111{
3112 const struct cred *cred = current_cred();
3113 int cap_audit = audit ? SECURITY_CAP_AUDIT : SECURITY_CAP_NOAUDIT;
3114
3115 if (cap_capable(cred, &init_user_ns, CAP_MAC_ADMIN, cap_audit))
3116 return false;
3117 if (cred_has_capability(cred, CAP_MAC_ADMIN, cap_audit, true))
3118 return false;
3119 return true;
3120}
3121
3110static int selinux_inode_setxattr(struct dentry *dentry, const char *name, 3122static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
3111 const void *value, size_t size, int flags) 3123 const void *value, size_t size, int flags)
3112{ 3124{
@@ -3138,7 +3150,7 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
3138 3150
3139 rc = security_context_to_sid(value, size, &newsid, GFP_KERNEL); 3151 rc = security_context_to_sid(value, size, &newsid, GFP_KERNEL);
3140 if (rc == -EINVAL) { 3152 if (rc == -EINVAL) {
3141 if (!capable(CAP_MAC_ADMIN)) { 3153 if (!has_cap_mac_admin(true)) {
3142 struct audit_buffer *ab; 3154 struct audit_buffer *ab;
3143 size_t audit_size; 3155 size_t audit_size;
3144 const char *str; 3156 const char *str;
@@ -3264,13 +3276,8 @@ static int selinux_inode_getsecurity(struct inode *inode, const char *name, void
3264 * and lack of permission just means that we fall back to the 3276 * and lack of permission just means that we fall back to the
3265 * in-core context value, not a denial. 3277 * in-core context value, not a denial.
3266 */ 3278 */
3267 error = cap_capable(current_cred(), &init_user_ns, CAP_MAC_ADMIN,
3268 SECURITY_CAP_NOAUDIT);
3269 if (!error)
3270 error = cred_has_capability(current_cred(), CAP_MAC_ADMIN,
3271 SECURITY_CAP_NOAUDIT, true);
3272 isec = inode_security(inode); 3279 isec = inode_security(inode);
3273 if (!error) 3280 if (has_cap_mac_admin(false))
3274 error = security_sid_to_context_force(isec->sid, &context, 3281 error = security_sid_to_context_force(isec->sid, &context,
3275 &size); 3282 &size);
3276 else 3283 else
@@ -5919,7 +5926,7 @@ static int selinux_setprocattr(const char *name, void *value, size_t size)
5919 } 5926 }
5920 error = security_context_to_sid(value, size, &sid, GFP_KERNEL); 5927 error = security_context_to_sid(value, size, &sid, GFP_KERNEL);
5921 if (error == -EINVAL && !strcmp(name, "fscreate")) { 5928 if (error == -EINVAL && !strcmp(name, "fscreate")) {
5922 if (!capable(CAP_MAC_ADMIN)) { 5929 if (!has_cap_mac_admin(true)) {
5923 struct audit_buffer *ab; 5930 struct audit_buffer *ab;
5924 size_t audit_size; 5931 size_t audit_size;
5925 5932