Commit fd2a8043 authored by John Johansen's avatar John Johansen

apparmor: add ns being viewed as a param to policy_admin_capable()

Prepare for a tighter pairing of user namespaces and apparmor policy
namespaces, by making the ns to be viewed available.
Signed-off-by: default avatarJohn Johansen <john.johansen@canonical.com>
parent 2bd8dbbf
...@@ -300,7 +300,7 @@ static inline int AUDIT_MODE(struct aa_profile *profile) ...@@ -300,7 +300,7 @@ static inline int AUDIT_MODE(struct aa_profile *profile)
} }
bool policy_view_capable(struct aa_ns *ns); bool policy_view_capable(struct aa_ns *ns);
bool policy_admin_capable(void); bool policy_admin_capable(struct aa_ns *ns);
bool aa_may_manage_policy(int op); bool aa_may_manage_policy(int op);
#endif /* __AA_POLICY_H */ #endif /* __AA_POLICY_H */
...@@ -738,7 +738,7 @@ __setup("apparmor=", apparmor_enabled_setup); ...@@ -738,7 +738,7 @@ __setup("apparmor=", apparmor_enabled_setup);
/* set global flag turning off the ability to load policy */ /* set global flag turning off the ability to load policy */
static int param_set_aalockpolicy(const char *val, const struct kernel_param *kp) static int param_set_aalockpolicy(const char *val, const struct kernel_param *kp)
{ {
if (!policy_admin_capable()) if (!policy_admin_capable(NULL))
return -EPERM; return -EPERM;
return param_set_bool(val, kp); return param_set_bool(val, kp);
} }
...@@ -752,7 +752,7 @@ static int param_get_aalockpolicy(char *buffer, const struct kernel_param *kp) ...@@ -752,7 +752,7 @@ static int param_get_aalockpolicy(char *buffer, const struct kernel_param *kp)
static int param_set_aabool(const char *val, const struct kernel_param *kp) static int param_set_aabool(const char *val, const struct kernel_param *kp)
{ {
if (!policy_admin_capable()) if (!policy_admin_capable(NULL))
return -EPERM; return -EPERM;
return param_set_bool(val, kp); return param_set_bool(val, kp);
} }
...@@ -766,7 +766,7 @@ static int param_get_aabool(char *buffer, const struct kernel_param *kp) ...@@ -766,7 +766,7 @@ static int param_get_aabool(char *buffer, const struct kernel_param *kp)
static int param_set_aauint(const char *val, const struct kernel_param *kp) static int param_set_aauint(const char *val, const struct kernel_param *kp)
{ {
if (!policy_admin_capable()) if (!policy_admin_capable(NULL))
return -EPERM; return -EPERM;
return param_set_uint(val, kp); return param_set_uint(val, kp);
} }
...@@ -792,7 +792,7 @@ static int param_get_audit(char *buffer, struct kernel_param *kp) ...@@ -792,7 +792,7 @@ static int param_get_audit(char *buffer, struct kernel_param *kp)
static int param_set_audit(const char *val, struct kernel_param *kp) static int param_set_audit(const char *val, struct kernel_param *kp)
{ {
int i; int i;
if (!policy_admin_capable()) if (!policy_admin_capable(NULL))
return -EPERM; return -EPERM;
if (!apparmor_enabled) if (!apparmor_enabled)
...@@ -813,7 +813,7 @@ static int param_set_audit(const char *val, struct kernel_param *kp) ...@@ -813,7 +813,7 @@ static int param_set_audit(const char *val, struct kernel_param *kp)
static int param_get_mode(char *buffer, struct kernel_param *kp) static int param_get_mode(char *buffer, struct kernel_param *kp)
{ {
if (!policy_admin_capable()) if (!policy_view_capable(NULL))
return -EPERM; return -EPERM;
if (!apparmor_enabled) if (!apparmor_enabled)
...@@ -825,7 +825,7 @@ static int param_get_mode(char *buffer, struct kernel_param *kp) ...@@ -825,7 +825,7 @@ static int param_get_mode(char *buffer, struct kernel_param *kp)
static int param_set_mode(const char *val, struct kernel_param *kp) static int param_set_mode(const char *val, struct kernel_param *kp)
{ {
int i; int i;
if (!policy_admin_capable()) if (!policy_admin_capable(NULL))
return -EPERM; return -EPERM;
if (!apparmor_enabled) if (!apparmor_enabled)
......
...@@ -637,9 +637,15 @@ bool policy_view_capable(struct aa_ns *ns) ...@@ -637,9 +637,15 @@ bool policy_view_capable(struct aa_ns *ns)
return response; return response;
} }
bool policy_admin_capable(void) bool policy_admin_capable(struct aa_ns *ns)
{ {
return policy_view_capable(NULL) && !aa_g_lock_policy; struct user_namespace *user_ns = current_user_ns();
bool capable = ns_capable(user_ns, CAP_MAC_ADMIN);
AA_DEBUG("cap_mac_admin? %d\n", capable);
AA_DEBUG("policy locked? %d\n", aa_g_lock_policy);
return policy_view_capable(ns) && capable && !aa_g_lock_policy;
} }
/** /**
...@@ -657,7 +663,7 @@ bool aa_may_manage_policy(int op) ...@@ -657,7 +663,7 @@ bool aa_may_manage_policy(int op)
return 0; return 0;
} }
if (!policy_admin_capable()) { if (!policy_admin_capable(NULL)) {
audit_policy(__aa_current_profile(), op, GFP_KERNEL, NULL, audit_policy(__aa_current_profile(), op, GFP_KERNEL, NULL,
"not policy admin", -EACCES); "not policy admin", -EACCES);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment