mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 20:22:09 +00:00
prlimit: make do_prlimit() static
There are no other callers in the kernel. Fixed up a comment format and whitespace issue when moving do_prlimit() higher in sys.c. Signed-off-by: Barret Rhoden <brho@google.com> Link: https://lkml.kernel.org/r/20220106172041.522167-3-brho@google.com Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
This commit is contained in:
parent
ffb217a13a
commit
c57bef0287
@ -8,7 +8,5 @@
|
||||
struct task_struct;
|
||||
|
||||
void getrusage(struct task_struct *p, int who, struct rusage *ru);
|
||||
int do_prlimit(struct task_struct *tsk, unsigned int resource,
|
||||
struct rlimit *new_rlim, struct rlimit *old_rlim);
|
||||
|
||||
#endif
|
||||
|
116
kernel/sys.c
116
kernel/sys.c
@ -1424,6 +1424,65 @@ SYSCALL_DEFINE2(setdomainname, char __user *, name, int, len)
|
||||
return errno;
|
||||
}
|
||||
|
||||
/* make sure you are allowed to change @tsk limits before calling this */
|
||||
static int do_prlimit(struct task_struct *tsk, unsigned int resource,
|
||||
struct rlimit *new_rlim, struct rlimit *old_rlim)
|
||||
{
|
||||
struct rlimit *rlim;
|
||||
int retval = 0;
|
||||
|
||||
if (resource >= RLIM_NLIMITS)
|
||||
return -EINVAL;
|
||||
if (new_rlim) {
|
||||
if (new_rlim->rlim_cur > new_rlim->rlim_max)
|
||||
return -EINVAL;
|
||||
if (resource == RLIMIT_NOFILE &&
|
||||
new_rlim->rlim_max > sysctl_nr_open)
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
/* protect tsk->signal and tsk->sighand from disappearing */
|
||||
read_lock(&tasklist_lock);
|
||||
if (!tsk->sighand) {
|
||||
retval = -ESRCH;
|
||||
goto out;
|
||||
}
|
||||
|
||||
rlim = tsk->signal->rlim + resource;
|
||||
task_lock(tsk->group_leader);
|
||||
if (new_rlim) {
|
||||
/*
|
||||
* Keep the capable check against init_user_ns until cgroups can
|
||||
* contain all limits.
|
||||
*/
|
||||
if (new_rlim->rlim_max > rlim->rlim_max &&
|
||||
!capable(CAP_SYS_RESOURCE))
|
||||
retval = -EPERM;
|
||||
if (!retval)
|
||||
retval = security_task_setrlimit(tsk, resource, new_rlim);
|
||||
}
|
||||
if (!retval) {
|
||||
if (old_rlim)
|
||||
*old_rlim = *rlim;
|
||||
if (new_rlim)
|
||||
*rlim = *new_rlim;
|
||||
}
|
||||
task_unlock(tsk->group_leader);
|
||||
|
||||
/*
|
||||
* RLIMIT_CPU handling. Arm the posix CPU timer if the limit is not
|
||||
* infinite. In case of RLIM_INFINITY the posix CPU timer code
|
||||
* ignores the rlimit.
|
||||
*/
|
||||
if (!retval && new_rlim && resource == RLIMIT_CPU &&
|
||||
new_rlim->rlim_cur != RLIM_INFINITY &&
|
||||
IS_ENABLED(CONFIG_POSIX_TIMERS))
|
||||
update_rlimit_cpu(tsk, new_rlim->rlim_cur);
|
||||
out:
|
||||
read_unlock(&tasklist_lock);
|
||||
return retval;
|
||||
}
|
||||
|
||||
SYSCALL_DEFINE2(getrlimit, unsigned int, resource, struct rlimit __user *, rlim)
|
||||
{
|
||||
struct rlimit value;
|
||||
@ -1567,63 +1626,6 @@ static void rlim64_to_rlim(const struct rlimit64 *rlim64, struct rlimit *rlim)
|
||||
rlim->rlim_max = (unsigned long)rlim64->rlim_max;
|
||||
}
|
||||
|
||||
/* make sure you are allowed to change @tsk limits before calling this */
|
||||
int do_prlimit(struct task_struct *tsk, unsigned int resource,
|
||||
struct rlimit *new_rlim, struct rlimit *old_rlim)
|
||||
{
|
||||
struct rlimit *rlim;
|
||||
int retval = 0;
|
||||
|
||||
if (resource >= RLIM_NLIMITS)
|
||||
return -EINVAL;
|
||||
if (new_rlim) {
|
||||
if (new_rlim->rlim_cur > new_rlim->rlim_max)
|
||||
return -EINVAL;
|
||||
if (resource == RLIMIT_NOFILE &&
|
||||
new_rlim->rlim_max > sysctl_nr_open)
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
/* protect tsk->signal and tsk->sighand from disappearing */
|
||||
read_lock(&tasklist_lock);
|
||||
if (!tsk->sighand) {
|
||||
retval = -ESRCH;
|
||||
goto out;
|
||||
}
|
||||
|
||||
rlim = tsk->signal->rlim + resource;
|
||||
task_lock(tsk->group_leader);
|
||||
if (new_rlim) {
|
||||
/* Keep the capable check against init_user_ns until
|
||||
cgroups can contain all limits */
|
||||
if (new_rlim->rlim_max > rlim->rlim_max &&
|
||||
!capable(CAP_SYS_RESOURCE))
|
||||
retval = -EPERM;
|
||||
if (!retval)
|
||||
retval = security_task_setrlimit(tsk, resource, new_rlim);
|
||||
}
|
||||
if (!retval) {
|
||||
if (old_rlim)
|
||||
*old_rlim = *rlim;
|
||||
if (new_rlim)
|
||||
*rlim = *new_rlim;
|
||||
}
|
||||
task_unlock(tsk->group_leader);
|
||||
|
||||
/*
|
||||
* RLIMIT_CPU handling. Arm the posix CPU timer if the limit is not
|
||||
* infinite. In case of RLIM_INFINITY the posix CPU timer code
|
||||
* ignores the rlimit.
|
||||
*/
|
||||
if (!retval && new_rlim && resource == RLIMIT_CPU &&
|
||||
new_rlim->rlim_cur != RLIM_INFINITY &&
|
||||
IS_ENABLED(CONFIG_POSIX_TIMERS))
|
||||
update_rlimit_cpu(tsk, new_rlim->rlim_cur);
|
||||
out:
|
||||
read_unlock(&tasklist_lock);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* rcu lock must be held */
|
||||
static int check_prlimit_permission(struct task_struct *task,
|
||||
unsigned int flags)
|
||||
|
Loading…
Reference in New Issue
Block a user