Skip to content

Commit

Permalink
rlimits: security, add task_struct to setrlimit
Browse files Browse the repository at this point in the history
Add task_struct to task_setrlimit of security_operations to be able to set
rlimit of task other than current.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Acked-by: Eric Paris <eparis@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
  • Loading branch information
Jiri Slaby committed Jul 16, 2010
1 parent 2f7989e commit 8fd00b4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
9 changes: 6 additions & 3 deletions include/linux/security.h
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,8 @@ struct security_operations {
int (*task_setnice) (struct task_struct *p, int nice);
int (*task_setioprio) (struct task_struct *p, int ioprio);
int (*task_getioprio) (struct task_struct *p);
int (*task_setrlimit) (unsigned int resource, struct rlimit *new_rlim);
int (*task_setrlimit) (struct task_struct *p, unsigned int resource,
struct rlimit *new_rlim);
int (*task_setscheduler) (struct task_struct *p, int policy,
struct sched_param *lp);
int (*task_getscheduler) (struct task_struct *p);
Expand Down Expand Up @@ -1751,7 +1752,8 @@ void security_task_getsecid(struct task_struct *p, u32 *secid);
int security_task_setnice(struct task_struct *p, int nice);
int security_task_setioprio(struct task_struct *p, int ioprio);
int security_task_getioprio(struct task_struct *p);
int security_task_setrlimit(unsigned int resource, struct rlimit *new_rlim);
int security_task_setrlimit(struct task_struct *p, unsigned int resource,
struct rlimit *new_rlim);
int security_task_setscheduler(struct task_struct *p,
int policy, struct sched_param *lp);
int security_task_getscheduler(struct task_struct *p);
Expand Down Expand Up @@ -2313,7 +2315,8 @@ static inline int security_task_getioprio(struct task_struct *p)
return 0;
}

static inline int security_task_setrlimit(unsigned int resource,
static inline int security_task_setrlimit(struct task_struct *p,
unsigned int resource,
struct rlimit *new_rlim)
{
return 0;
Expand Down
2 changes: 1 addition & 1 deletion kernel/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int, resource, struct rlimit __user *, rlim)
if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
return -EPERM;

retval = security_task_setrlimit(resource, &new_rlim);
retval = security_task_setrlimit(current, resource, &new_rlim);
if (retval)
return retval;

Expand Down
3 changes: 2 additions & 1 deletion security/capability.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ static int cap_task_getioprio(struct task_struct *p)
return 0;
}

static int cap_task_setrlimit(unsigned int resource, struct rlimit *new_rlim)
static int cap_task_setrlimit(struct task_struct *p, unsigned int resource,
struct rlimit *new_rlim)
{
return 0;
}
Expand Down
5 changes: 3 additions & 2 deletions security/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,9 +769,10 @@ int security_task_getioprio(struct task_struct *p)
return security_ops->task_getioprio(p);
}

int security_task_setrlimit(unsigned int resource, struct rlimit *new_rlim)
int security_task_setrlimit(struct task_struct *p, unsigned int resource,
struct rlimit *new_rlim)
{
return security_ops->task_setrlimit(resource, new_rlim);
return security_ops->task_setrlimit(p, resource, new_rlim);
}

int security_task_setscheduler(struct task_struct *p,
Expand Down
7 changes: 4 additions & 3 deletions security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -3371,16 +3371,17 @@ static int selinux_task_getioprio(struct task_struct *p)
return current_has_perm(p, PROCESS__GETSCHED);
}

static int selinux_task_setrlimit(unsigned int resource, struct rlimit *new_rlim)
static int selinux_task_setrlimit(struct task_struct *p, unsigned int resource,
struct rlimit *new_rlim)
{
struct rlimit *old_rlim = current->signal->rlim + resource;
struct rlimit *old_rlim = p->signal->rlim + resource;

/* Control the ability to change the hard limit (whether
lowering or raising it), so that the hard limit can
later be used as a safe reset point for the soft limit
upon context transitions. See selinux_bprm_committing_creds. */
if (old_rlim->rlim_max != new_rlim->rlim_max)
return current_has_perm(current, PROCESS__SETRLIMIT);
return current_has_perm(p, PROCESS__SETRLIMIT);

return 0;
}
Expand Down

0 comments on commit 8fd00b4

Please sign in to comment.