Skip to content

Commit

Permalink
apparmor: fix module parameters can be changed after policy is locked
Browse files Browse the repository at this point in the history
the policy_lock parameter is a one way switch that prevents policy
from being further modified. Unfortunately some of the module parameters
can effectively modify policy by turning off enforcement.

split policy_admin_capable into a view check and a full admin check,
and update the admin check to test the policy_lock parameter.

Signed-off-by: John Johansen <[email protected]>
  • Loading branch information
John Johansen committed Jul 12, 2016
1 parent 5f20fdf commit 58acf9d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
2 changes: 2 additions & 0 deletions security/apparmor/include/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ static inline int AUDIT_MODE(struct aa_profile *profile)
return profile->audit;
}

bool policy_view_capable(void);
bool policy_admin_capable(void);
bool aa_may_manage_policy(int op);

#endif /* __AA_POLICY_H */
22 changes: 10 additions & 12 deletions security/apparmor/lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,51 +730,49 @@ __setup("apparmor=", apparmor_enabled_setup);
/* set global flag turning off the ability to load policy */
static int param_set_aalockpolicy(const char *val, const struct kernel_param *kp)
{
if (!capable(CAP_MAC_ADMIN))
if (!policy_admin_capable())
return -EPERM;
if (aa_g_lock_policy)
return -EACCES;
return param_set_bool(val, kp);
}

static int param_get_aalockpolicy(char *buffer, const struct kernel_param *kp)
{
if (!capable(CAP_MAC_ADMIN))
if (!policy_view_capable())
return -EPERM;
return param_get_bool(buffer, kp);
}

static int param_set_aabool(const char *val, const struct kernel_param *kp)
{
if (!capable(CAP_MAC_ADMIN))
if (!policy_admin_capable())
return -EPERM;
return param_set_bool(val, kp);
}

static int param_get_aabool(char *buffer, const struct kernel_param *kp)
{
if (!capable(CAP_MAC_ADMIN))
if (!policy_view_capable())
return -EPERM;
return param_get_bool(buffer, kp);
}

static int param_set_aauint(const char *val, const struct kernel_param *kp)
{
if (!capable(CAP_MAC_ADMIN))
if (!policy_admin_capable())
return -EPERM;
return param_set_uint(val, kp);
}

static int param_get_aauint(char *buffer, const struct kernel_param *kp)
{
if (!capable(CAP_MAC_ADMIN))
if (!policy_view_capable())
return -EPERM;
return param_get_uint(buffer, kp);
}

static int param_get_audit(char *buffer, struct kernel_param *kp)
{
if (!capable(CAP_MAC_ADMIN))
if (!policy_view_capable())
return -EPERM;

if (!apparmor_enabled)
Expand All @@ -786,7 +784,7 @@ static int param_get_audit(char *buffer, struct kernel_param *kp)
static int param_set_audit(const char *val, struct kernel_param *kp)
{
int i;
if (!capable(CAP_MAC_ADMIN))
if (!policy_admin_capable())
return -EPERM;

if (!apparmor_enabled)
Expand All @@ -807,7 +805,7 @@ static int param_set_audit(const char *val, struct kernel_param *kp)

static int param_get_mode(char *buffer, struct kernel_param *kp)
{
if (!capable(CAP_MAC_ADMIN))
if (!policy_admin_capable())
return -EPERM;

if (!apparmor_enabled)
Expand All @@ -819,7 +817,7 @@ static int param_get_mode(char *buffer, struct kernel_param *kp)
static int param_set_mode(const char *val, struct kernel_param *kp)
{
int i;
if (!capable(CAP_MAC_ADMIN))
if (!policy_admin_capable())
return -EPERM;

if (!apparmor_enabled)
Expand Down
18 changes: 17 additions & 1 deletion security/apparmor/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,22 @@ static int audit_policy(int op, gfp_t gfp, const char *name, const char *info,
&sa, NULL);
}

bool policy_view_capable(void)
{
struct user_namespace *user_ns = current_user_ns();
bool response = false;

if (ns_capable(user_ns, CAP_MAC_ADMIN))
response = true;

return response;
}

bool policy_admin_capable(void)
{
return policy_view_capable() && !aa_g_lock_policy;
}

/**
* aa_may_manage_policy - can the current task manage policy
* @op: the policy manipulation operation being done
Expand All @@ -932,7 +948,7 @@ bool aa_may_manage_policy(int op)
return 0;
}

if (!capable(CAP_MAC_ADMIN)) {
if (!policy_admin_capable()) {
audit_policy(op, GFP_KERNEL, NULL, "not policy admin", -EACCES);
return 0;
}
Expand Down

0 comments on commit 58acf9d

Please sign in to comment.