Skip to content

Commit

Permalink
AppArmor: Fix security_task_setrlimit logic for 2.6.36 changes
Browse files Browse the repository at this point in the history
2.6.36 introduced the abilitiy to specify the task that is having its
rlimits set.  Update mediation to ensure that confined tasks can only
set their own group_leader as expected by current policy.

Add TODO note about extending policy to support setting other tasks
rlimits.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: James Morris <jmorris@namei.org>
  • Loading branch information
John Johansen authored and James Morris committed Sep 7, 2010
1 parent e819ff5 commit 3a2dc83
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions security/apparmor/include/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ struct aa_rlimit {
};

int aa_map_resource(int resource);
int aa_task_setrlimit(struct aa_profile *profile, unsigned int resource,
struct rlimit *new_rlim);
int aa_task_setrlimit(struct aa_profile *profile, struct task_struct *,
unsigned int resource, struct rlimit *new_rlim);

void __aa_transition_rlimits(struct aa_profile *old, struct aa_profile *new);

Expand Down
2 changes: 1 addition & 1 deletion security/apparmor/lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
int error = 0;

if (!unconfined(profile))
error = aa_task_setrlimit(profile, resource, new_rlim);
error = aa_task_setrlimit(profile, task, resource, new_rlim);

return error;
}
Expand Down
20 changes: 12 additions & 8 deletions security/apparmor/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,29 @@ int aa_map_resource(int resource)
/**
* aa_task_setrlimit - test permission to set an rlimit
* @profile - profile confining the task (NOT NULL)
* @task - task the resource is being set on
* @resource - the resource being set
* @new_rlim - the new resource limit (NOT NULL)
*
* Control raising the processes hard limit.
*
* Returns: 0 or error code if setting resource failed
*/
int aa_task_setrlimit(struct aa_profile *profile, unsigned int resource,
struct rlimit *new_rlim)
int aa_task_setrlimit(struct aa_profile *profile, struct task_struct *task,
unsigned int resource, struct rlimit *new_rlim)
{
int error = 0;

if (profile->rlimits.mask & (1 << resource) &&
new_rlim->rlim_max > profile->rlimits.limits[resource].rlim_max)

error = audit_resource(profile, resource, new_rlim->rlim_max,
-EACCES);
/* TODO: extend resource control to handle other (non current)
* processes. AppArmor rules currently have the implicit assumption
* that the task is setting the resource of the current process
*/
if ((task != current->group_leader) ||
(profile->rlimits.mask & (1 << resource) &&
new_rlim->rlim_max > profile->rlimits.limits[resource].rlim_max))
error = -EACCES;

return error;
return audit_resource(profile, resource, new_rlim->rlim_max, error);
}

/**
Expand Down

0 comments on commit 3a2dc83

Please sign in to comment.