Skip to content

Commit

Permalink
rlimits: selinux, do rlimits changes under task_lock
Browse files Browse the repository at this point in the history
When doing an exec, selinux updates rlimits in its code of current
process depending on current max. Make sure max or cur doesn't change
in the meantime by grabbing task_lock which do_prlimit needs for
changing limits too.

While at it, use rlimit helper for accessing CPU rlimit a line below.
To have a volatile access too.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Oleg Nesterov <oleg@redhat.com>
  • Loading branch information
Oleg Nesterov authored and Jiri Slaby committed Jul 16, 2010
1 parent 2fb9d26 commit eb2d55a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -2333,13 +2333,15 @@ static void selinux_bprm_committing_creds(struct linux_binprm *bprm)
rc = avc_has_perm(new_tsec->osid, new_tsec->sid, SECCLASS_PROCESS,
PROCESS__RLIMITINH, NULL);
if (rc) {
/* protect against do_prlimit() */
task_lock(current);
for (i = 0; i < RLIM_NLIMITS; i++) {
rlim = current->signal->rlim + i;
initrlim = init_task.signal->rlim + i;
rlim->rlim_cur = min(rlim->rlim_max, initrlim->rlim_cur);
}
update_rlimit_cpu(current,
current->signal->rlim[RLIMIT_CPU].rlim_cur);
task_unlock(current);
update_rlimit_cpu(current, rlimit(RLIMIT_CPU));
}
}

Expand Down

0 comments on commit eb2d55a

Please sign in to comment.