SECURITY: selinux, fix update_rlimit_cpu parameter
Subsystems (22)
PATCH v3 1/27 SECURITY: selinux, fix update_rlimit_cpu parameter
From: Jiri Slaby <[email protected]>
Don't pass rlim_cur member of RLIM_NLIMITS-1=RLIMIT_RTTIME limit to update_rlimit_cpu() in selinux_bprm_committing_creds.
Use proper rlim[RLIMIT_CPU].rlim_cur instead.
--- security/selinux/hooks.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
security/selinux/hooks.c +1 -1
@@ -2366,7 +2366,7 @@ static void selinux_bprm_committing_creds(struct linux_binprm *bprm) initrlim = init_task.signal->rlim + i; rlim->rlim_cur =min (rlim->rlim_max, initrlim->rlim_cur); } -update_rlimit_cpu (rlim->rlim_cur); +update_rlimit_cpu (current->signal->rlim[RLIMIT_CPU ].rlim_cur); } }
Signature · 1 line
1.6.5.3
PATCH v3 2/27 SECURITY: add task_struct to setrlimit
From: Jiri Slaby <[email protected]>
Add task_struct to task_setrlimit of security_operations to be able to set rlimit of different task than current.
--- include/linux/security.h | 9 ++++++--- kernel/sys.c | 2 +- security/capability.c | 3 ++- security/security.c | 5 +++-- security/selinux/hooks.c | 7 ++++--- 5 files changed, 16 insertions(+), 10 deletions(-)
include/linux/security.h +6 -3
@@ -1570,7 +1570,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);
@@ -1835,7 +1836,8 @@ int security_task_setgroups(struct group_info *group_info);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);
@@ -2451,7 +2453,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 ;
kernel/sys.c +1 -1
@@ -1256,7 +1256,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;
security/capability.c +2 -1
@@ -450,7 +450,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 ; }
security/security.c +3 -2
@@ -781,9 +781,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,
security/selinux/hooks.c +4 -3
@@ -3390,16 +3390,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 ; }
Signature · 1 line
1.6.5.3
PATCH v3 3/27 core: add task_struct to update_rlimit_cpu
In reply to Jiri SlabyFrom: Jiri Slaby <[email protected]>
Add task_struct as a parameter to update_rlimit_cpu to be able to set rlimit_cpu of different task than current.
--- include/linux/posix-timers.h | 2 +- kernel/posix-cpu-timers.c | 10 +++++----- kernel/sys.c | 2 +- security/selinux/hooks.c | 3 ++- 4 files changed, 9 insertions(+), 8 deletions(-)
include/linux/posix-timers.h +1 -1
@@ -117,6 +117,6 @@ void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,long clock_nanosleep_restart (struct restart_block *restart_block); -void update_rlimit_cpu (unsigned long rlim_new); +void update_rlimit_cpu (struct task_struct *task,unsigned long rlim_new);#endif
kernel/posix-cpu-timers.c +5 -5
@@ -13,16 +13,16 @@/* * Called after updating RLIMIT_CPU to set timer expiration if necessary. */ -void update_rlimit_cpu (unsigned long rlim_new) +void update_rlimit_cpu (struct task_struct *task,unsigned long rlim_new) {cputime_t cputime =secs_to_cputime (rlim_new); -struct signal_struct *const sig = current->signal; +struct signal_struct *const sig = task->signal;if (cputime_eq (sig->it[CPUCLOCK_PROF ].expires, cputime_zero) ||cputime_gt (sig->it[CPUCLOCK_PROF ].expires, cputime)) { -spin_lock_irq (¤t->sighand->siglock); -set_process_cpu_timer (current,CPUCLOCK_PROF , &cputime,NULL ); -spin_unlock_irq (¤t->sighand->siglock); +spin_lock_irq (&task->sighand->siglock); +set_process_cpu_timer (task,CPUCLOCK_PROF , &cputime,NULL ); +spin_unlock_irq (&task->sighand->siglock); } }
kernel/sys.c +1 -1
@@ -1286,7 +1286,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int, resource, struct rlimit __user *, rlim)if (new_rlim.rlim_cur ==RLIM_INFINITY ) goto out; -update_rlimit_cpu (new_rlim.rlim_cur); +update_rlimit_cpu (current, new_rlim.rlim_cur); out:return 0 ; }
security/selinux/hooks.c +2 -1
@@ -2366,7 +2366,8 @@ static void selinux_bprm_committing_creds(struct linux_binprm *bprm) initrlim = init_task.signal->rlim + i; rlim->rlim_cur =min (rlim->rlim_max, initrlim->rlim_cur); } -update_rlimit_cpu (current->signal->rlim[RLIMIT_CPU ].rlim_cur); +update_rlimit_cpu (current, + current->signal->rlim[RLIMIT_CPU ].rlim_cur); } }
Signature · 1 line
1.6.5.3
PATCH v3 4/27 sys_setrlimit: make sure ->rlim_max never grows
In reply to Jiri SlabyFrom: Oleg Nesterov <[email protected]>
Mostly preparation for Jiri's changes, but probably makes sense anyway.
sys_setrlimit() checks new_rlim.rlim_max <= old_rlim->rlim_max, but when it takes task_lock() old_rlim->rlim_max can be already lowered. Move this check under task_lock().
Currently this is not important, we can only race with our sub-thread, this means the application is stupid. But when we change the code to allow the update of !current task's limits, it becomes important to make sure ->rlim_max can be lowered "reliably" even if we race with the application doing sys_setrlimit().
--- kernel/sys.c | 15 ++++++++------- 1 files changed, 8 insertions(+), 7 deletions(-)
kernel/sys.c +8 -7
@@ -1249,10 +1249,6 @@ SYSCALL_DEFINE2(setrlimit, unsigned int, resource, struct rlimit __user *, rlim)return -EFAULT ;if (new_rlim.rlim_cur > new_rlim.rlim_max)return -EINVAL ; - old_rlim = current->signal->rlim + resource; -if ((new_rlim.rlim_max > old_rlim->rlim_max) && - !capable (CAP_SYS_RESOURCE )) -return -EPERM ;if (resource ==RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)return -EPERM ;
@@ -1270,11 +1266,16 @@ SYSCALL_DEFINE2(setrlimit, unsigned int, resource, struct rlimit __user *, rlim) new_rlim.rlim_cur =1 ; } + old_rlim = current->signal->rlim + resource;task_lock (current->group_leader); - *old_rlim = new_rlim; +if ((new_rlim.rlim_max <= old_rlim->rlim_max) || +capable (CAP_SYS_RESOURCE )) + *old_rlim = new_rlim; +else + retval = -EPERM ;task_unlock (current->group_leader); -if (resource !=RLIMIT_CPU ) +if (retval || resource !=RLIMIT_CPU ) goto out;/*
@@ -1288,7 +1289,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int, resource, struct rlimit __user *, rlim)update_rlimit_cpu (current, new_rlim.rlim_cur); out: -return 0 ; +return retval; }/*
Signature · 1 line
1.6.5.3
PATCH v3 5/27 core: split sys_setrlimit
In reply to Jiri SlabyFrom: Jiri Slaby <[email protected]>
Create setrlimit from sys_setrlimit and declare setrlimit in the resource header. This is to allow rlimits to be changed not only by syscall, but later from proc code too.
--- include/linux/resource.h | 2 ++ kernel/sys.c | 44 ++++++++++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 18 deletions(-)
include/linux/resource.h +2 -0
@@ -71,5 +71,7 @@ struct rlimit {#include <asm/resource.h> int getrusage (struct task_struct *p,int who,struct rusage __user *ru); +int setrlimit (struct task_struct *tsk,unsigned int resource, +struct rlimit *new_rlim);#endif
kernel/sys.c +26 -18
82 lines not on this page · raw message
Signature · 1 line
1.6.5.3
A message that is not in the archive (sent off-list or not yet received): 1259363167-9347-1-git-send-email-jslaby-AlSwsSmVLrQ@public.gmane.org
PATCH v3 23/27 misc: use helpers for rlimits
Make sure compiler won't do weird things with limits. E.g. fetching them twice may return 2 different values after writable limits are implemented.
I.e. either use newly added rlimit helpers or ACCESS_ONCE if not applicable.
--- drivers/infiniband/core/umem.c | 2 +- drivers/infiniband/hw/ipath/ipath_user_pages.c | 3 +-- ipc/mqueue.c | 2 +- ipc/shm.c | 3 +-- 4 files changed, 4 insertions(+), 6 deletions(-)
drivers/infiniband/core/umem.c +1 -1
@@ -136,7 +136,7 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,down_write (¤t->mm->mmap_sem); locked = npages + current->mm->locked_vm; - lock_limit = current->signal->rlim[RLIMIT_MEMLOCK ].rlim_cur >>PAGE_SHIFT ; + lock_limit =rlim_get_cur (RLIMIT_MEMLOCK ) >>PAGE_SHIFT ;if ((locked > lock_limit) && !capable (CAP_IPC_LOCK )) { ret = -ENOMEM ;
drivers/infiniband/hw/ipath/ipath_user_pages.c +1 -2
@@ -59,8 +59,7 @@ static int __get_user_pages(unsigned long start_page, size_t num_pages,size_t got;int ret; - lock_limit = current->signal->rlim[RLIMIT_MEMLOCK ].rlim_cur >> -PAGE_SHIFT ; + lock_limit =rlim_get_cur (RLIMIT_MEMLOCK ) >>PAGE_SHIFT ;if (num_pages > lock_limit) { ret = -ENOMEM ;
ipc/mqueue.c +1 -1
@@ -153,7 +153,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,spin_lock (&mq_lock);if (u->mq_bytes + mq_bytes < u->mq_bytes || u->mq_bytes + mq_bytes > - p->signal->rlim[RLIMIT_MSGQUEUE ].rlim_cur) { +task_rlim_get_cur (p,RLIMIT_MSGQUEUE )) {spin_unlock (&mq_lock); goto out_inode; }
ipc/shm.c +1 -2
@@ -761,8 +761,7 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf)if (euid != shp->shm_perm.uid && euid != shp->shm_perm.cuid) goto out_unlock; -if (cmd ==SHM_LOCK && - !current->signal->rlim[RLIMIT_MEMLOCK ].rlim_cur) +if (cmd ==SHM_LOCK && !rlim_get_cur (RLIMIT_MEMLOCK )) goto out_unlock; }
Signature · 6 lines
1.6.5.3 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 6/27 core: allow setrlimit to non-current tasks
In reply to Jiri SlabyFrom: Jiri Slaby <[email protected]>
Add locking to allow setrlimit accept task parameter other than current.
Namely, lock tasklist_lock for read and check whether the task structure has sighand non-null. Do all the signal processing under that lock still held.
--- kernel/sys.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-)
kernel/sys.c +10 -1
@@ -1238,6 +1238,7 @@ SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,#endif +/* make sure you are allowed to change @tsk limits before calling this */ int setrlimit (struct task_struct *tsk,unsigned int resource,struct rlimit *new_rlim) {
@@ -1249,9 +1250,16 @@ int setrlimit(struct task_struct *tsk, unsigned int resource,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; + } + retval =security_task_setrlimit (tsk, resource, new_rlim);if (retval) -return retval; + goto out;if (resource ==RLIMIT_CPU && new_rlim->rlim_cur ==0 ) {/*
@@ -1286,6 +1294,7 @@ int setrlimit(struct task_struct *tsk, unsigned int resource,update_rlimit_cpu (tsk, new_rlim->rlim_cur); out: +read_unlock (&tasklist_lock);return retval; }
Signature · 1 line
1.6.5.3
PATCH v3 7/27 core: optimize setrlimit for current task
In reply to Jiri SlabyFrom: Jiri Slaby <[email protected]>
Don't take tasklist lock for 'current'. It's not needed, since current->sighand/signal can't disappear.
This improves serlimit called especially via sys_setrlimit.
--- kernel/sys.c | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-)
kernel/sys.c +10 -6
@@ -1250,11 +1250,14 @@ int setrlimit(struct task_struct *tsk, unsigned int resource,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; +/* optimization: 'current' doesn't need locking, e.g. setrlimit */ +if (tsk != current) { +/* protect tsk->signal and tsk->sighand from disappearing */ +read_lock (&tasklist_lock); +if (!tsk->sighand) { + retval = -ESRCH ; + goto out; + } } retval =security_task_setrlimit (tsk, resource, new_rlim);
@@ -1294,7 +1297,8 @@ int setrlimit(struct task_struct *tsk, unsigned int resource,update_rlimit_cpu (tsk, new_rlim->rlim_cur); out: -read_unlock (&tasklist_lock); +if (tsk != current) +read_unlock (&tasklist_lock);return retval; }
Signature · 1 line
1.6.5.3
PATCH v3 8/27 FS: proc, switch limits reading to fops
In reply to Jiri SlabyFrom: Jiri Slaby <[email protected]>
Use fops instead of proc_info_read. We will need fops for limits writing and the code would look ugly if we used NOD("limits", S_IFREG|S_IRUSR|S_IWUSR, NULL,
&proc_pid_limits_operations, { .proc_read = proc_pid_limits }),
We will just useREG("limits", S_IRUSR|S_IWUSR, proc_pid_limits_operations),
--- fs/proc/base.c | 37 ++++++++++++++++++++++++++++--------- 1 files changed, 28 insertions(+), 9 deletions(-)
fs/proc/base.c +28 -9
@@ -477,19 +477,30 @@ static const struct limit_names lnames[RLIM_NLIMITS] = { };/* Display limits for a process */ -static int proc_pid_limits (struct task_struct *task,char *buffer) +static ssize_t limits_read (struct file *file,char __user *buf,size_t rcount, +loff_t *ppos) { -unsigned int i; -int count =0 ; -unsigned long flags; -char *bufptr = buffer; -struct rlimit rlim[RLIM_NLIMITS ]; +struct task_struct *task; +unsigned long flags; +unsigned int i; +ssize_t count =0 ; +char *bufptr; -if (!lock_task_sighand (task, &flags)) + task =get_proc_task (file->f_path.dentry->d_inode); +if (!task) +return -ESRCH ; +if (!lock_task_sighand (task, &flags)) { +put_task_struct (task);return 0 ; + }memcpy (rlim, task->signal->rlim,sizeof (struct rlimit ) *RLIM_NLIMITS );unlock_task_sighand (task, &flags); +put_task_struct (task); + + bufptr = (char *)__get_free_page (GFP_TEMPORARY ); +if (!bufptr) +return -ENOMEM ;/* * print the file header
@@ -518,9 +529,17 @@ static int proc_pid_limits(struct task_struct *task, char *buffer) count +=sprintf (&bufptr[count],"\n" ); } + count =simple_read_from_buffer (buf, rcount, ppos, bufptr, count); + +free_page ((unsigned long )bufptr); +return count; } +static const struct file_operations proc_pid_limits_operations = { + .read = limits_read, +}; +#ifdef CONFIG_HAVE_ARCH_TRACEHOOK static int proc_pid_syscall (struct task_struct *task,char *buffer) {
@@ -2500,7 +2519,7 @@ static const struct pid_entry tgid_base_stuff[] = {INF ("auxv" ,S_IRUSR , proc_pid_auxv),ONE ("status" ,S_IRUGO , proc_pid_status),ONE ("personality" ,S_IRUSR , proc_pid_personality), -INF ("limits" ,S_IRUSR , proc_pid_limits), +REG ("limits" ,S_IRUSR , proc_pid_limits_operations), #ifdef CONFIG_SCHED_DEBUG REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations), #endif
@@ -2834,7 +2853,7 @@ static const struct pid_entry tid_base_stuff[] = {INF ("auxv" ,S_IRUSR , proc_pid_auxv),ONE ("status" ,S_IRUGO , proc_pid_status),ONE ("personality" ,S_IRUSR , proc_pid_personality), -INF ("limits" ,S_IRUSR , proc_pid_limits), +REG ("limits" ,S_IRUSR , proc_pid_limits_operations), #ifdef CONFIG_SCHED_DEBUG REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations), #endif
Signature · 1 line
1.6.5.3
PATCH v3 9/27 FS: proc, make limits writable
In reply to Jiri SlabyFrom: Jiri Slaby <[email protected]>
Allow writing strings such as
Max core file size=0:unlimited
to /proc/<pid>/limits to change limits.
--- fs/proc/base.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 66 insertions(+), 2 deletions(-)
fs/proc/base.c +66 -2
@@ -536,8 +536,72 @@ static ssize_t limits_read(struct file *file, char __user *buf, size_t rcount,return count; } +static ssize_t limits_write (struct file *file,const char __user *buf, +size_t count,loff_t *ppos) +{ +struct task_struct *task =get_proc_task (file->f_path.dentry->d_inode); +char str[32 +1 +16 +1 +16 +1 ], *delim, *next; +struct rlimit new_rlimit; +unsigned int i; +int ret; + +if (!task) { + count = -ESRCH ; + goto out; + } +if (copy_from_user (str, buf,min (count,sizeof (str) -1 ))) { + count = -EFAULT ; + goto put_task; + } + + str[min (count,sizeof (str) -1 )] =0 ; + + delim =strchr (str,'=' ); +if (!delim) { + count = -EINVAL ; + goto put_task; + } + *delim++ =0 ;/* for easy 'str' usage */ + new_rlimit.rlim_cur =simple_strtoul (delim, &next,0 ); +if (*next !=':' ) { +if (strncmp (delim,"unlimited:" ,10 )) { + count = -EINVAL ; + goto put_task; + } + new_rlimit.rlim_cur =RLIM_INFINITY ; + next = delim +9 ;/* move to ':' */ + } + delim = next +1 ; + new_rlimit.rlim_max =simple_strtoul (delim, &next,0 ); +if (*next !=0 ) { +if (strcmp (delim,"unlimited" )) { + count = -EINVAL ; + goto put_task; + } + new_rlimit.rlim_max =RLIM_INFINITY ; + } + +for (i =0 ; i <RLIM_NLIMITS ; i++) +if (!strcmp (str, lnames[i].name)) +break ; +if (i >=RLIM_NLIMITS ) { + count = -EINVAL ; + goto put_task; + } + + ret =setrlimit (task, i, &new_rlimit); +if (ret) + count = ret; + +put_task: +put_task_struct (task); +out: +return count; +} +static const struct file_operations proc_pid_limits_operations = { .read = limits_read, + .write = limits_write, };#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
@@ -2519,7 +2583,7 @@ static const struct pid_entry tgid_base_stuff[] = {INF ("auxv" ,S_IRUSR , proc_pid_auxv),ONE ("status" ,S_IRUGO , proc_pid_status),ONE ("personality" ,S_IRUSR , proc_pid_personality), -REG ("limits" ,S_IRUSR , proc_pid_limits_operations), +REG ("limits" ,S_IRUSR |S_IWUSR , proc_pid_limits_operations), #ifdef CONFIG_SCHED_DEBUG REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations), #endif
@@ -2853,7 +2917,7 @@ static const struct pid_entry tid_base_stuff[] = {INF ("auxv" ,S_IRUSR , proc_pid_auxv),ONE ("status" ,S_IRUGO , proc_pid_status),ONE ("personality" ,S_IRUSR , proc_pid_personality), -REG ("limits" ,S_IRUSR , proc_pid_limits_operations), +REG ("limits" ,S_IRUSR |S_IWUSR , proc_pid_limits_operations), #ifdef CONFIG_SCHED_DEBUG REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations), #endif
Signature · 1 line
1.6.5.3
PATCH v3 10/27 core: do security check under task_lock
In reply to Jiri SlabyDo security_task_setrlimit under task_lock. Other tasks may change limits under our hands while we are checking limits inside the function. From now on, they can't.
--- kernel/sys.c | 16 +++++++--------- 1 files changed, 7 insertions(+), 9 deletions(-)
kernel/sys.c +7 -9
@@ -1243,7 +1243,7 @@ int setrlimit(struct task_struct *tsk, unsigned int resource, struct rlimit *new_rlim) {struct rlimit *old_rlim; -int retval; +int retval =0 ;if (new_rlim->rlim_cur > new_rlim->rlim_max)return -EINVAL ;
@@ -1260,10 +1260,6 @@ int setrlimit(struct task_struct *tsk, unsigned int resource, } } - retval =security_task_setrlimit (tsk, resource, new_rlim); -if (retval) - goto out; -if (resource ==RLIMIT_CPU && new_rlim->rlim_cur ==0 ) {/* * The caller is asking for an immediate RLIMIT_CPU
@@ -1276,11 +1272,13 @@ int setrlimit(struct task_struct *tsk, unsigned int resource, old_rlim = tsk->signal->rlim + resource;task_lock (tsk->group_leader); -if ((new_rlim->rlim_max <= old_rlim->rlim_max) || -capable (CAP_SYS_RESOURCE )) - *old_rlim = *new_rlim; -else +if ((new_rlim->rlim_max > old_rlim->rlim_max) && + !capable (CAP_SYS_RESOURCE )) retval = -EPERM ; +if (!retval) + retval =security_task_setrlimit (tsk, resource, new_rlim); +if (!retval) + *old_rlim = *new_rlim;task_unlock (tsk->group_leader);if (retval || resource !=RLIMIT_CPU )
Signature · 1 line
1.6.5.3
PATCH v3 11/27 core: rename setrlimit to do_setrlimit
In reply to Jiri SlabyRename it so that it makes more sense in the field of syscalls (i.e. do_* is used for functions called by syscall wrappers but also when called from other paths).
--- fs/proc/base.c | 2 +- include/linux/resource.h | 2 +- kernel/sys.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
fs/proc/base.c +1 -1
@@ -589,7 +589,7 @@ static ssize_t limits_write(struct file *file, const char __user *buf, goto put_task; } - ret =setrlimit (task, i, &new_rlimit); + ret =do_setrlimit (task, i, &new_rlimit);if (ret) count = ret;
include/linux/resource.h +1 -1
@@ -71,7 +71,7 @@ struct rlimit {#include <asm/resource.h> int getrusage (struct task_struct *p,int who,struct rusage __user *ru); -int setrlimit (struct task_struct *tsk,unsigned int resource, +int do_setrlimit (struct task_struct *tsk,unsigned int resource,struct rlimit *new_rlim);#endif
kernel/sys.c +2 -2
@@ -1239,7 +1239,7 @@ SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,#endif /* make sure you are allowed to change @tsk limits before calling this */ -int setrlimit (struct task_struct *tsk,unsigned int resource, +int do_setrlimit (struct task_struct *tsk,unsigned int resource,struct rlimit *new_rlim) {struct rlimit *old_rlim;
@@ -1308,7 +1308,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int, resource, struct rlimit __user *, rlim)return -EINVAL ;if (copy_from_user (&new_rlim, rlim,sizeof (*rlim)))return -EFAULT ; -return setrlimit (current, resource, &new_rlim); +return do_setrlimit (current, resource, &new_rlim); }/*
Signature · 1 line
1.6.5.3
PATCH v3 12/27 resource: move kernel functions inside __KERNEL__
In reply to Jiri SlabyThese are internal functions. Move them inside __KERNEL__ ifdef.
This needs also unifdef of resource.h before installing. Change that too.
--- include/linux/Kbuild | 2 +- include/linux/resource.h | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-)
include/linux/Kbuild +1 -1
@@ -140,7 +140,6 @@ header-y += qnxtypes.h header-y += qnx4_fs.h header-y += radeonfb.h header-y += raw.h -header-y += resource.h header-y += romfs_fs.h header-y += rose.h header-y += serial_reg.h
@@ -323,6 +322,7 @@ unifdef-y += irqnr.h unifdef-y += reboot.h unifdef-y += reiserfs_fs.h unifdef-y += reiserfs_xattr.h +unifdef-y += resource.h unifdef-y += route.h unifdef-y += rtc.h unifdef-y += rtnetlink.h
include/linux/resource.h +6 -2
@@ -3,8 +3,6 @@#include <linux/time.h> -struct task_struct ; -/* * Resource control/accounting header file for linux */
@@ -70,8 +68,14 @@ struct rlimit {*/ #include <asm/resource.h> +#ifdef __KERNEL__ + +struct task_struct ; +int getrusage (struct task_struct *p,int who,struct rusage __user *ru);int do_setrlimit (struct task_struct *tsk,unsigned int resource,struct rlimit *new_rlim); +#endif /* __KERNEL__ */ +#endif
Signature · 1 line
1.6.5.3
PATCH v3 13/27 core: posix-cpu-timers, cleanup rlimits usage
In reply to Jiri SlabyFetch rlimit (both hard and soft) values only once and work on them. It removes many accesses through sig structure and makes the code cleaner.
Mostly a preparation for writable resource limits support.
--- kernel/posix-cpu-timers.c | 32 +++++++++++++++++--------------- 1 files changed, 17 insertions(+), 15 deletions(-)
kernel/posix-cpu-timers.c +17 -15
@@ -983,6 +983,7 @@ static void check_thread_timers(struct task_struct *tsk,int maxfire;struct list_head *timers = tsk->cpu_timers;struct signal_struct *const sig = tsk->signal; +unsigned long soft; maxfire =20 ; tsk->cputime_expires.prof_exp = cputime_zero;
@@ -1031,9 +1032,9 @@ static void check_thread_timers(struct task_struct *tsk,/* * Check for the special case thread timers. */ -if (sig->rlim[RLIMIT_RTTIME ].rlim_cur !=RLIM_INFINITY ) { + soft = sig->rlim[RLIMIT_RTTIME ].rlim_cur; +if (soft !=RLIM_INFINITY ) {unsigned long hard = sig->rlim[RLIMIT_RTTIME ].rlim_max; -unsigned long *soft = &sig->rlim[RLIMIT_RTTIME ].rlim_cur;if (hard !=RLIM_INFINITY && tsk->rt.timeout >DIV_ROUND_UP (hard,USEC_PER_SEC /HZ )) {
@@ -1044,14 +1045,13 @@ static void check_thread_timers(struct task_struct *tsk,__group_send_sig_info (SIGKILL ,SEND_SIG_PRIV , tsk);return ; } -if (tsk->rt.timeout >DIV_ROUND_UP (*soft,USEC_PER_SEC /HZ )) { +if (tsk->rt.timeout >DIV_ROUND_UP (soft,USEC_PER_SEC /HZ )) {/* * At the soft limit, send a SIGXCPU every second. */ -if (sig->rlim[RLIMIT_RTTIME ].rlim_cur - < sig->rlim[RLIMIT_RTTIME ].rlim_max) { - sig->rlim[RLIMIT_RTTIME ].rlim_cur += -USEC_PER_SEC ; +if (soft < hard) { + soft +=USEC_PER_SEC ; + sig->rlim[RLIMIT_RTTIME ].rlim_cur = soft; } printk(KERN_INFO "RT Watchdog Timeout: %s[%d]\n",
@@ -1122,13 +1122,14 @@ static void check_process_timers(struct task_struct *tsk,unsigned long long sum_sched_runtime, sched_expires;struct list_head *timers = sig->cpu_timers;struct task_cputime cputime; +unsigned long cpu_cur_lim = sig->rlim[RLIMIT_CPU ].rlim_cur;/* * Don't sample the current process CPU clocks if there are no timers. */ if (list_empty (&timers[CPUCLOCK_PROF ]) &&cputime_eq (sig->it[CPUCLOCK_PROF ].expires, cputime_zero) && - sig->rlim[RLIMIT_CPU ].rlim_cur ==RLIM_INFINITY && + cpu_cur_lim ==RLIM_INFINITY &&list_empty (&timers[CPUCLOCK_VIRT ]) &&cputime_eq (sig->it[CPUCLOCK_VIRT ].expires, cputime_zero) &&list_empty (&timers[CPUCLOCK_SCHED ])) {
@@ -1195,10 +1196,11 @@ static void check_process_timers(struct task_struct *tsk,check_cpu_itimer (tsk, &sig->it[CPUCLOCK_VIRT ], &virt_expires, utime,SIGVTALRM ); -if (sig->rlim[RLIMIT_CPU ].rlim_cur !=RLIM_INFINITY ) { +if (cpu_cur_lim !=RLIM_INFINITY ) {unsigned long psecs =cputime_to_secs (ptime); +unsigned long hard = sig->rlim[RLIMIT_CPU ].rlim_max;cputime_t x; -if (psecs >= sig->rlim[RLIMIT_CPU ].rlim_max) { +if (psecs >= hard) {/* * At the hard limit, we just die. * No need to calculate anything else now.
@@ -1206,17 +1208,17 @@ static void check_process_timers(struct task_struct *tsk,__group_send_sig_info (SIGKILL ,SEND_SIG_PRIV , tsk);return ; } -if (psecs >= sig->rlim[RLIMIT_CPU ].rlim_cur) { +if (psecs >= cpu_cur_lim) {/* * At the soft limit, send a SIGXCPU every second. */ __group_send_sig_info (SIGXCPU ,SEND_SIG_PRIV , tsk); -if (sig->rlim[RLIMIT_CPU ].rlim_cur - < sig->rlim[RLIMIT_CPU ].rlim_max) { - sig->rlim[RLIMIT_CPU ].rlim_cur++; +if (cpu_cur_lim < hard) { + cpu_cur_lim++; + sig->rlim[RLIMIT_CPU ].rlim_cur = cpu_cur_lim; } } - x =secs_to_cputime (sig->rlim[RLIMIT_CPU ].rlim_cur); + x =secs_to_cputime (cpu_cur_lim);if (cputime_eq (prof_expires, cputime_zero) ||cputime_lt (x, prof_expires)) { prof_expires = x;
Signature · 1 line
1.6.5.3
PATCH v3 14/27 resource: add helpers for fetching rlimits
In reply to Jiri SlabyWe want to be sure that compiler fetches the limit variable only once, so add helpers for fetching current and maximal resource limits which do that.
Add them to sched.h (instead of resource.h) due to circular dependency
sched.h->resource.h->task_struct
Alternative would be to create a separate res_access.h or similar.
--- include/linux/sched.h | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-)
include/linux/sched.h +22 -0
@@ -2574,6 +2574,28 @@ static inline void mm_init_owner(struct mm_struct *mm, struct task_struct *p) }#endif /* CONFIG_MM_OWNER */ +static inline unsigned long task_rlim_get_cur (const struct task_struct *tsk, +unsigned int limit) +{ +return ACCESS_ONCE (tsk->signal->rlim[limit].rlim_cur); +} + +static inline unsigned long task_rlim_get_max (const struct task_struct *tsk, +unsigned int limit) +{ +return ACCESS_ONCE (tsk->signal->rlim[limit].rlim_max); +} + +static inline unsigned long rlim_get_cur (unsigned int limit) +{ +return task_rlim_get_cur (current, limit); +} + +static inline unsigned long rlim_get_max (unsigned int limit) +{ +return task_rlim_get_max (current, limit); +} +#define TASK_STATE_TO_CHAR_STR "RSDTtZX"#endif /* __KERNEL__ */
Signature · 1 line
1.6.5.3
PATCH v3 15/27 IA64: use helpers for rlimits
In reply to Jiri SlabyMake sure compiler won't do weird things with limits. E.g. fetching them twice may return 2 different values after writable limits are implemented.
I.e. either use newly added rlimit helpers or ACCESS_ONCE if not applicable.
--- arch/ia64/kernel/perfmon.c | 2 +- arch/ia64/kernel/sys_ia64.c | 2 +- arch/ia64/mm/init.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
arch/ia64/kernel/perfmon.c +1 -1
@@ -2298,7 +2298,7 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_t* if ((mm->total_vm << PAGE_SHIFT) + len> task->rlim[RLIMIT_AS].rlim_cur) * return -ENOMEM; */ -if (size > task->signal->rlim[RLIMIT_MEMLOCK ].rlim_cur) +if (size >task_rlim_get_cur (task,RLIMIT_MEMLOCK ))return -ENOMEM ;/*
arch/ia64/kernel/sys_ia64.c +1 -1
@@ -129,7 +129,7 @@ ia64_brk (unsigned long brk) goto out;/* Check against rlimit.. */ - rlim = current->signal->rlim[RLIMIT_DATA ].rlim_cur; + rlim =rlim_get_cur (RLIMIT_DATA );if (rlim <RLIM_INFINITY && brk - mm->start_data > rlim) goto out;
arch/ia64/mm/init.c +1 -1
@@ -91,7 +91,7 @@ dma_mark_clean(void *addr, size_t size)inline void ia64_set_rbs_bot (void ) { -unsigned long stack_size = current->signal->rlim[RLIMIT_STACK ].rlim_max &-16 ; +unsigned long stack_size =rlim_get_max (RLIMIT_STACK ) &-16 ;if (stack_size >MAX_USER_STACK_SIZE ) stack_size =MAX_USER_STACK_SIZE ;
Signature · 1 line
1.6.5.3
PATCH v3 16/27 PPC: use helpers for rlimits
In reply to Jiri SlabyMake sure compiler won't do weird things with limits. E.g. fetching them twice may return 2 different values after writable limits are implemented.
I.e. either use newly added rlimit helpers or ACCESS_ONCE if not applicable.
--- arch/powerpc/mm/mmap_64.c | 4 ++-- arch/powerpc/platforms/cell/spufs/coredump.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/mm/mmap_64.c +2 -2
@@ -47,7 +47,7 @@ static inline int mmap_is_legacy(void)if (current->personality &ADDR_COMPAT_LAYOUT )return 1 ; -if (current->signal->rlim[RLIMIT_STACK ].rlim_cur ==RLIM_INFINITY ) +if (rlim_get_cur (RLIMIT_STACK ) ==RLIM_INFINITY )return 1 ;return sysctl_legacy_va_layout;
@@ -77,7 +77,7 @@ static unsigned long mmap_rnd(void)static inline unsigned long mmap_base (void ) { -unsigned long gap = current->signal->rlim[RLIMIT_STACK ].rlim_cur; +unsigned long gap =rlim_get_cur (RLIMIT_STACK );if (gap <MIN_GAP ) gap =MIN_GAP ;
arch/powerpc/platforms/cell/spufs/coredump.c +1 -1
@@ -54,7 +54,7 @@ static ssize_t do_coredump_read(int num, struct spu_context *ctx, void *buffer,*/ static int spufs_dump_write (struct file *file,const void *addr,int nr,loff_t *foffset) { -unsigned long limit = current->signal->rlim[RLIMIT_CORE ].rlim_cur; +unsigned long limit =rlim_get_cur (RLIMIT_CORE );ssize_t written;if (*foffset + nr > limit)
Signature · 1 line
1.6.5.3
Re: [PATCH v3 16/27] PPC: use helpers for rlimits
Quoted 6 lines · Jiri Slaby
Make sure compiler won't do weird things with limits. E.g. fetching them twice may return 2 different values after writable limits are implemented.
I.e. either use newly added rlimit helpers or
ACCESS_ONCEif not applicable.
Thanks. I have that already queued up.
Cheers,
Ben.
Quoted 48 lines
Signed-off-by Jiri Slaby <[email protected]>Cc James Morris <[email protected]>Cc Heiko Carstens <[email protected]>Cc Andrew Morton <[email protected]>Cc Ingo Molnar <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>Cc Paul Mackerras <[email protected]>--- arch/powerpc/mm/mmap_64.c | 4 ++-- arch/powerpc/platforms/cell/spufs/coredump.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)arch/powerpc/mm/mmap_64.c +2
-2@@ -47,7 +47,7 @@ static inline int mmap_is_legacy(void)if (current->personality &ADDR_COMPAT_LAYOUT )return 1 ; -if (current->signal->rlim[RLIMIT_STACK ].rlim_cur ==RLIM_INFINITY ) +if (rlim_get_cur (RLIMIT_STACK ) ==RLIM_INFINITY )return 1 ;return sysctl_legacy_va_layout;@@ -77,7 +77,7 @@ static unsigned long mmap_rnd(void)static inline unsigned long mmap_base (void ) { -unsigned long gap = current->signal->rlim[RLIMIT_STACK ].rlim_cur; +unsigned long gap =rlim_get_cur (RLIMIT_STACK );if (gap <MIN_GAP ) gap =MIN_GAP ;arch/powerpc/platforms/cell/spufs/coredump.c +1
-1@@ -54,7 +54,7 @@ static ssize_t do_coredump_read(int num, struct spu_context *ctx, void *buffer,*/ static int spufs_dump_write (struct file *file,const void *addr,int nr,loff_t *foffset) { -unsigned long limit = current->signal->rlim[RLIMIT_CORE ].rlim_cur; +unsigned long limit =rlim_get_cur (RLIMIT_CORE );ssize_t written;if (*foffset + nr > limit)
Re: [PATCH v3 16/27] PPC: use helpers for rlimits
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 6 lines · Jiri Slaby
Make sure compiler won't do weird things with limits. E.g. fetching them twice may return 2 different values after writable limits are implemented.
I.e. either use newly added rlimit helpers or
ACCESS_ONCEif not applicable.Thanks. I have that already queued up.
Are you sure? The previous version with ACCESS_ONCE was generally NACKed. This one uses a newly added helper which is much more cleaner way to do it.
thanks,
Signature · 1 line
js
Re: [PATCH v3 16/27] PPC: use helpers for rlimits
Quoted 3 lines · Jiri Slaby
Are you sure? The previous version with
ACCESS_ONCEwas generally NACKed. This one uses a newly added helper which is much more cleaner way to do it.
I haven't seen a nack, but then I haven't pushed out yet so I can easily back it off and replace it with this one.
Cheers,
Ben.
Re: [PATCH v3 16/27] PPC: use helpers for rlimits
Hi Ben,
Quoted 8 lines · On Sun, 29 Nov 2009 08:16:03 +1100 Benjamin Herrenschmidt…
Quoted 3 lines · Jiri Slaby
Are you sure? The previous version with
ACCESS_ONCEwas generally NACKed. This one uses a newly added helper which is much more cleaner way to do it.I haven't seen a nack, but then I haven't pushed out yet so I can easily back it off and replace it with this one.
You need to hold off adding this to your tree until after patch 14/27 ("resource: add helpers for fetching rlimits") of this series (or a modified version of it) reaches Linus' tree.
Signature · 3 lines
Cheers, Stephen Rothwell [email protected] http://www.canb.auug.org.au/~sfr/
PATCH v3 17/27 S390: use helpers for rlimits
In reply to Jiri SlabyMake sure compiler won't do weird things with limits. E.g. fetching them twice may return 2 different values after writable limits are implemented.
I.e. either use newly added rlimit helpers or ACCESS_ONCE if not applicable.
--- arch/s390/mm/mmap.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
arch/s390/mm/mmap.c +2 -2
@@ -40,7 +40,7 @@static inline unsigned long mmap_base (void ) { -unsigned long gap = current->signal->rlim[RLIMIT_STACK ].rlim_cur; +unsigned long gap =rlim_get_cur (RLIMIT_STACK );if (gap <MIN_GAP ) gap =MIN_GAP ;
@@ -61,7 +61,7 @@ static inline int mmap_is_legacy(void)#endif return sysctl_legacy_va_layout || (current->personality &ADDR_COMPAT_LAYOUT ) || - current->signal->rlim[RLIMIT_STACK ].rlim_cur ==RLIM_INFINITY ; +rlim_get_cur (RLIMIT_STACK ) ==RLIM_INFINITY ; }#ifndef CONFIG_64BIT
Signature · 1 line
1.6.5.3
PATCH v3 18/27 SPARC: use helpers for rlimits
In reply to Jiri SlabyMake sure compiler won't do weird things with limits. E.g. fetching them twice may return 2 different values after writable limits are implemented.
I.e. either use newly added rlimit helpers or ACCESS_ONCE if not applicable.
--- arch/sparc/kernel/sys_sparc_64.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
arch/sparc/kernel/sys_sparc_64.c +3 -3
@@ -361,6 +361,7 @@ EXPORT_SYMBOL(get_fb_unmapped_area);void arch_pick_mmap_layout (struct mm_struct *mm) {unsigned long random_factor =0UL ; +unsigned long gap;if (current->flags &PF_RANDOMIZE ) { random_factor =get_random_int ();
@@ -375,9 +376,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)* Fall back to the standard layout if the personality * bit is set, or if the expected stack growth is unlimited: */ + gap =rlim_get_cur (RLIMIT_STACK );if (!test_thread_flag (TIF_32BIT ) || (current->personality &ADDR_COMPAT_LAYOUT ) || - current->signal->rlim[RLIMIT_STACK ].rlim_cur =RLIM_INFINITY || + gap =RLIM_INFINITY || sysctl_legacy_va_layout) { mm->mmap_base =TASK_UNMAPPED_BASE + random_factor; mm->get_unmapped_area = arch_get_unmapped_area;
@@ -385,9 +387,7 @@ void arch_pick_mmap_layout(struct mm_struct *mm) }else {/* We know it's 32-bit */ unsigned long task_size =STACK_TOP32 ; -unsigned long gap; - gap = current->signal->rlim[RLIMIT_STACK ].rlim_cur;if (gap <128 *1024 *1024 ) gap =128 *1024 *1024 ;if (gap > (task_size /6 *5 ))
Signature · 1 line
1.6.5.3
PATCH v3 19/27 X86: use helpers for rlimits
In reply to Jiri SlabyMake sure compiler won't do weird things with limits. E.g. fetching them twice may return 2 different values after writable limits are implemented.
I.e. either use newly added rlimit helpers or ACCESS_ONCE if not applicable.
--- arch/x86/ia32/ia32_aout.c | 2 +- arch/x86/mm/mmap.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/ia32/ia32_aout.c +1 -1
@@ -297,7 +297,7 @@ static int load_aout_binary(struct linux_binprm *bprm, struct pt_regs *regs)* size limits imposed on them by creating programs with large * arrays in the data or bss. */ - rlim = current->signal->rlim[RLIMIT_DATA ].rlim_cur; + rlim =rlim_get_cur (RLIMIT_DATA );if (rlim >=RLIM_INFINITY ) rlim = ~0 ;if (ex.a_data + ex.a_bss > rlim)
arch/x86/mm/mmap.c +2 -2
@@ -71,7 +71,7 @@ static int mmap_is_legacy(void)if (current->personality &ADDR_COMPAT_LAYOUT )return 1 ; -if (current->signal->rlim[RLIMIT_STACK ].rlim_cur ==RLIM_INFINITY ) +if (rlim_get_cur (RLIMIT_STACK ) ==RLIM_INFINITY )return 1 ;return sysctl_legacy_va_layout;
@@ -96,7 +96,7 @@ static unsigned long mmap_rnd(void)static unsigned long mmap_base (void ) { -unsigned long gap = current->signal->rlim[RLIMIT_STACK ].rlim_cur; +unsigned long gap =rlim_get_cur (RLIMIT_STACK );if (gap <MIN_GAP ) gap =MIN_GAP ;
Signature · 1 line
1.6.5.3
PATCH v3 20/27 FS: use helpers for rlimits
In reply to Jiri SlabyMake sure compiler won't do weird things with limits. E.g. fetching them twice may return 2 different values after writable limits are implemented.
I.e. either use newly added rlimit helpers or ACCESS_ONCE if not applicable.
--- fs/attr.c | 2 +- fs/binfmt_aout.c | 2 +- fs/binfmt_flat.c | 2 +- fs/exec.c | 8 ++++---- fs/fcntl.c | 2 +- fs/file.c | 2 +- fs/proc/array.c | 4 ++-- fs/select.c | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-)
fs/attr.c +1 -1
@@ -82,7 +82,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)if (inode->i_size < offset) {unsigned long limit; - limit = current->signal->rlim[RLIMIT_FSIZE ].rlim_cur; + limit =rlim_get_cur (RLIMIT_FSIZE );if (limit !=RLIM_INFINITY && offset > limit) goto out_sig;if (offset > inode->i_sb->s_maxbytes)
fs/binfmt_aout.c +1 -1
@@ -246,7 +246,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)* size limits imposed on them by creating programs with large * arrays in the data or bss. */ - rlim = current->signal->rlim[RLIMIT_DATA ].rlim_cur; + rlim =rlim_get_cur (RLIMIT_DATA );if (rlim >=RLIM_INFINITY ) rlim = ~0 ;if (ex.a_data + ex.a_bss > rlim)
fs/binfmt_flat.c +1 -1
@@ -501,7 +501,7 @@ static int load_flat_file(struct linux_binprm * bprm,* size limits imposed on them by creating programs with large * arrays in the data or bss. */ - rlim = current->signal->rlim[RLIMIT_DATA ].rlim_cur; + rlim =rlim_get_cur (RLIMIT_DATA );if (rlim >=RLIM_INFINITY ) rlim = ~0 ;if (data_len + bss_len > rlim) {
fs/exec.c +4 -4
@@ -196,7 +196,7 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,* to work from. */ rlim = current->signal->rlim; -if (size > rlim[RLIMIT_STACK ].rlim_cur /4 ) { +if (size >ACCESS_ONCE (rlim[RLIMIT_STACK ].rlim_cur) /4 ) {put_page (page);return NULL ; }
@@ -575,7 +575,7 @@ int setup_arg_pages(struct linux_binprm *bprm,#ifdef CONFIG_STACK_GROWSUP /* Limit stack size to 1GB */ - stack_base = current->signal->rlim[RLIMIT_STACK ].rlim_max; + stack_base =rlim_get_max (RLIMIT_STACK );if (stack_base > (1 <<30 )) stack_base =1 <<30 ;
@@ -1503,7 +1503,7 @@ static int format_corename(char *corename, long signr)/* core limit size */ case 'c' : rc =snprintf (out_ptr, out_end - out_ptr, -"%lu" , current->signal->rlim[RLIMIT_CORE ].rlim_cur); +"%lu" ,rlim_get_cur (RLIMIT_CORE ));if (rc > out_end - out_ptr) goto out; out_ptr += rc;
@@ -1762,7 +1762,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)int retval =0 ;int flag =0 ;int ispipe =0 ; -unsigned long core_limit = current->signal->rlim[RLIMIT_CORE ].rlim_cur; +unsigned long core_limit =rlim_get_cur (RLIMIT_CORE );char **helper_argv =NULL ;int helper_argc =0 ;int dump_count =0 ;
fs/fcntl.c +1 -1
@@ -344,7 +344,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,switch (cmd) {case F_DUPFD :case F_DUPFD_CLOEXEC : -if (arg >= current->signal->rlim[RLIMIT_NOFILE ].rlim_cur) +if (arg >=rlim_get_cur (RLIMIT_NOFILE ))break ; err =alloc_fd (arg, cmd ==F_DUPFD_CLOEXEC ?O_CLOEXEC :0 );if (err >=0 ) {
fs/file.c +1 -1
@@ -257,7 +257,7 @@ int expand_files(struct files_struct *files, int nr)* N.B. For clone tasks sharing a files structure, this test * will limit the total number of files that can be opened. */ -if (nr >= current->signal->rlim[RLIMIT_NOFILE ].rlim_cur) +if (nr >=rlim_get_cur (RLIMIT_NOFILE ))return -EMFILE ;/* Do we need to expand? */
fs/proc/array.c +2 -2
@@ -266,7 +266,7 @@ static inline void task_sig(struct seq_file *m, struct task_struct *p)collect_sigign_sigcatch (p, &ignored, &caught); num_threads =atomic_read (&p->signal->count); qsize =atomic_read (&__task_cred (p)->user->sigpending); - qlim = p->signal->rlim[RLIMIT_SIGPENDING ].rlim_cur; + qlim =task_rlim_get_cur (p,RLIMIT_SIGPENDING );unlock_task_sighand (p, &flags); }
@@ -491,7 +491,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, cutime = sig->cutime; cstime = sig->cstime; cgtime = sig->cgtime; - rsslim = sig->rlim[RLIMIT_RSS ].rlim_cur; + rsslim =ACCESS_ONCE (sig->rlim[RLIMIT_RSS ].rlim_cur);/* add up live thread stats at the group level */ if (whole) {
fs/select.c +1 -1
@@ -821,7 +821,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,struct poll_list *walk = head;unsigned long todo = nfds; -if (nfds > current->signal->rlim[RLIMIT_NOFILE ].rlim_cur) +if (nfds >rlim_get_cur (RLIMIT_NOFILE ))return -EINVAL ; len = min_t(unsigned int, nfds, N_STACK_PPS);
Signature · 1 line
1.6.5.3
PATCH v3 21/27 MM: use helpers for rlimits
In reply to Jiri SlabyMake sure compiler won't do weird things with limits. E.g. fetching them twice may return 2 different values after writable limits are implemented.
I.e. either use newly added rlimit helpers or ACCESS_ONCE if not applicable.
--- mm/filemap.c | 2 +- mm/mlock.c | 12 ++++++------ mm/mmap.c | 13 +++++++------ mm/mremap.c | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-)
mm/filemap.c +1 -1
@@ -1971,7 +1971,7 @@ EXPORT_SYMBOL(iov_iter_single_seg_count);inline int generic_write_checks (struct file *file,loff_t *pos,size_t *count,int isblk) {struct inode *inode = file->f_mapping->host; -unsigned long limit = current->signal->rlim[RLIMIT_FSIZE ].rlim_cur; +unsigned long limit =rlim_get_cur (RLIMIT_FSIZE );if (unlikely (*pos <0 ))return -EINVAL ;
mm/mlock.c +6 -6
@@ -25,7 +25,7 @@ int can_do_mlock(void) {if (capable (CAP_IPC_LOCK ))return 1 ; -if (current->signal->rlim[RLIMIT_MEMLOCK ].rlim_cur !=0 ) +if (rlim_get_cur (RLIMIT_MEMLOCK ) !=0 )return 1 ;return 0 ; }
@@ -490,7 +490,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len) locked = len >>PAGE_SHIFT ; locked += current->mm->locked_vm; - lock_limit = current->signal->rlim[RLIMIT_MEMLOCK ].rlim_cur; + lock_limit =rlim_get_cur (RLIMIT_MEMLOCK ); lock_limit >>=PAGE_SHIFT ;/* check against resource limits */
@@ -553,7 +553,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)down_write (¤t->mm->mmap_sem); - lock_limit = current->signal->rlim[RLIMIT_MEMLOCK ].rlim_cur; + lock_limit =rlim_get_cur (RLIMIT_MEMLOCK ); lock_limit >>=PAGE_SHIFT ; ret = -ENOMEM ;
@@ -587,7 +587,7 @@ int user_shm_lock(size_t size, struct user_struct *user)int allowed =0 ; locked = (size +PAGE_SIZE -1 ) >>PAGE_SHIFT ; - lock_limit = current->signal->rlim[RLIMIT_MEMLOCK ].rlim_cur; + lock_limit =rlim_get_cur (RLIMIT_MEMLOCK );if (lock_limit ==RLIM_INFINITY ) allowed =1 ; lock_limit >>=PAGE_SHIFT ;
@@ -621,12 +621,12 @@ int account_locked_memory(struct mm_struct *mm, struct rlimit *rlim,down_write (&mm->mmap_sem); - lim = rlim[RLIMIT_AS ].rlim_cur >>PAGE_SHIFT ; + lim =ACCESS_ONCE (rlim[RLIMIT_AS ].rlim_cur) >>PAGE_SHIFT ; vm = mm->total_vm + pgsz;if (lim < vm) goto out; - lim = rlim[RLIMIT_MEMLOCK ].rlim_cur >>PAGE_SHIFT ; + lim =ACCESS_ONCE (rlim[RLIMIT_MEMLOCK ].rlim_cur) >>PAGE_SHIFT ; vm = mm->locked_vm + pgsz;if (lim < vm) goto out;
mm/mmap.c +7 -6
@@ -266,7 +266,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)* segment grow beyond its set limit the in case where the limit is * not page aligned -Ram Gupta */ - rlim = current->signal->rlim[RLIMIT_DATA ].rlim_cur; + rlim =rlim_get_cur (RLIMIT_DATA );if (rlim <RLIM_INFINITY && (brk - mm->start_brk) + (mm->end_data - mm->start_data) > rlim) goto out;
@@ -990,7 +990,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,unsigned long locked, lock_limit; locked = len >>PAGE_SHIFT ; locked += mm->locked_vm; - lock_limit = current->signal->rlim[RLIMIT_MEMLOCK ].rlim_cur; + lock_limit =rlim_get_cur (RLIMIT_MEMLOCK ); lock_limit >>=PAGE_SHIFT ;if (locked > lock_limit && !capable (CAP_IPC_LOCK ))return -EAGAIN ;
@@ -1565,7 +1565,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, unsreturn -ENOMEM ;/* Stack limit test */ -if (size > rlim[RLIMIT_STACK ].rlim_cur) +if (size >ACCESS_ONCE (rlim[RLIMIT_STACK ].rlim_cur))return -ENOMEM ;/* mlock limit tests */
@@ -1573,7 +1573,8 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, unsunsigned long locked;unsigned long limit; locked = mm->locked_vm + grow; - limit = rlim[RLIMIT_MEMLOCK ].rlim_cur >>PAGE_SHIFT ; + limit =ACCESS_ONCE (rlim[RLIMIT_MEMLOCK ].rlim_cur); + limit >>=PAGE_SHIFT ;if (locked > limit && !capable (CAP_IPC_LOCK ))return -ENOMEM ; }
@@ -2026,7 +2027,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)unsigned long locked, lock_limit; locked = len >>PAGE_SHIFT ; locked += mm->locked_vm; - lock_limit = current->signal->rlim[RLIMIT_MEMLOCK ].rlim_cur; + lock_limit =rlim_get_cur (RLIMIT_MEMLOCK ); lock_limit >>=PAGE_SHIFT ;if (locked > lock_limit && !capable (CAP_IPC_LOCK ))return -EAGAIN ;
@@ -2240,7 +2241,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)unsigned long cur = mm->total_vm;/* pages */ unsigned long lim; - lim = current->signal->rlim[RLIMIT_AS ].rlim_cur >>PAGE_SHIFT ; + lim =rlim_get_cur (RLIMIT_AS ) >>PAGE_SHIFT ;if (cur + npages > lim)return 0 ;
mm/mremap.c +1 -1
@@ -358,7 +358,7 @@ unsigned long do_mremap(unsigned long addr,if (vma->vm_flags &VM_LOCKED ) {unsigned long locked, lock_limit; locked = mm->locked_vm <<PAGE_SHIFT ; - lock_limit = current->signal->rlim[RLIMIT_MEMLOCK ].rlim_cur; + lock_limit =rlim_get_cur (RLIMIT_MEMLOCK ); locked += new_len - old_len; ret = -EAGAIN ;if (locked > lock_limit && !capable (CAP_IPC_LOCK ))
Signature · 1 line
1.6.5.3
PATCH v3 22/27 core: use helpers for rlimits
In reply to Jiri SlabyMake sure compiler won't do weird things with limits. E.g. fetching them twice may return 2 different values after writable limits are implemented.
I.e. either use newly added rlimit helpers or ACCESS_ONCE if not applicable.
--- kernel/fork.c | 10 ++++++---- kernel/perf_event.c | 2 +- kernel/posix-cpu-timers.c | 16 +++++++++------- kernel/sched.c | 4 ++-- kernel/sched_rt.c | 5 +++-- kernel/signal.c | 2 +- kernel/sys.c | 3 +-- 7 files changed, 23 insertions(+), 19 deletions(-)
kernel/fork.c +6 -4
@@ -822,6 +822,8 @@ void __cleanup_sighand(struct sighand_struct *sighand)*/ static void posix_cpu_timers_init_group (struct signal_struct *sig) { +unsigned long cpu_limit; +/* Thread group counters. */ thread_group_cputime_init (sig);
@@ -836,9 +838,9 @@ static void posix_cpu_timers_init_group(struct signal_struct *sig) sig->cputime_expires.virt_exp = cputime_zero; sig->cputime_expires.sched_exp =0 ; -if (sig->rlim[RLIMIT_CPU ].rlim_cur !=RLIM_INFINITY ) { - sig->cputime_expires.prof_exp = -secs_to_cputime (sig->rlim[RLIMIT_CPU ].rlim_cur); + cpu_limit =ACCESS_ONCE (sig->rlim[RLIMIT_CPU ].rlim_cur); +if (cpu_limit !=RLIM_INFINITY ) { + sig->cputime_expires.prof_exp =secs_to_cputime (cpu_limit); sig->cputimer.running =1 ; }
@@ -1028,7 +1030,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,#endif retval = -EAGAIN ;if (atomic_read (&p->real_cred->user->processes) >= - p->signal->rlim[RLIMIT_NPROC ].rlim_cur) { +task_rlim_get_cur (p,RLIMIT_NPROC )) {if (!capable (CAP_SYS_ADMIN ) && !capable (CAP_SYS_RESOURCE ) && p->real_cred->user !=INIT_USER ) goto bad_fork_free;
kernel/perf_event.c +1 -1
@@ -2420,7 +2420,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)if (user_locked > user_lock_limit) extra = user_locked - user_lock_limit; - lock_limit = current->signal->rlim[RLIMIT_MEMLOCK ].rlim_cur; + lock_limit =rlim_get_cur (RLIMIT_MEMLOCK ); lock_limit >>=PAGE_SHIFT ; locked = vma->vm_mm->locked_vm + extra;
kernel/posix-cpu-timers.c +9 -7
@@ -640,7 +640,7 @@ static void arm_timer(struct k_itimer *timer, union cpu_time_count now)if (expires_le (sig->it[CPUCLOCK_PROF ].expires, exp->cpu))break ; - i = sig->rlim[RLIMIT_CPU ].rlim_cur; + i =ACCESS_ONCE (sig->rlim[RLIMIT_CPU ].rlim_cur);if (i !=RLIM_INFINITY && i <=cputime_to_secs (exp->cpu))break ;
@@ -1032,9 +1032,10 @@ static void check_thread_timers(struct task_struct *tsk,/* * Check for the special case thread timers. */ - soft = sig->rlim[RLIMIT_RTTIME ].rlim_cur; + soft =ACCESS_ONCE (sig->rlim[RLIMIT_RTTIME ].rlim_cur);if (soft !=RLIM_INFINITY ) { -unsigned long hard = sig->rlim[RLIMIT_RTTIME ].rlim_max; +unsigned long hard =ACCESS_ONCE (sig->rlim[RLIMIT_RTTIME ]. + rlim_max);if (hard !=RLIM_INFINITY && tsk->rt.timeout >DIV_ROUND_UP (hard,USEC_PER_SEC /HZ )) {
@@ -1122,7 +1123,7 @@ static void check_process_timers(struct task_struct *tsk,unsigned long long sum_sched_runtime, sched_expires;struct list_head *timers = sig->cpu_timers;struct task_cputime cputime; -unsigned long cpu_cur_lim = sig->rlim[RLIMIT_CPU ].rlim_cur; +unsigned long cpu_cur_lim =ACCESS_ONCE (sig->rlim[RLIMIT_CPU ].rlim_cur);/* * Don't sample the current process CPU clocks if there are no timers.
@@ -1198,7 +1199,8 @@ static void check_process_timers(struct task_struct *tsk,if (cpu_cur_lim !=RLIM_INFINITY ) {unsigned long psecs =cputime_to_secs (ptime); -unsigned long hard = sig->rlim[RLIMIT_CPU ].rlim_max; +unsigned long hard = +ACCESS_ONCE (sig->rlim[RLIMIT_CPU ].rlim_max);cputime_t x;if (psecs >= hard) {/*
@@ -1385,7 +1387,7 @@ static inline int fastpath_timer_check(struct task_struct *tsk)return 1 ; } -return sig->rlim[RLIMIT_CPU ].rlim_cur !=RLIM_INFINITY ; +return ACCESS_ONCE (sig->rlim[RLIMIT_CPU ].rlim_cur) !=RLIM_INFINITY ; }/*
@@ -1483,7 +1485,7 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,* If the RLIMIT_CPU timer will expire before the * ITIMER_PROF timer, we have nothing else to do. */ -if (tsk->signal->rlim[RLIMIT_CPU ].rlim_cur +if (task_rlim_get_cur (tsk,RLIMIT_CPU ) <cputime_to_secs (*newval))return ; }
kernel/sched.c +2 -2
@@ -6072,7 +6072,7 @@ int can_nice(const struct task_struct *p, const int nice)/* convert nice value [19,-20] to rlimit style value [1,40] */ int nice_rlim =20 - nice; -return (nice_rlim <= p->signal->rlim[RLIMIT_NICE ].rlim_cur || +return (nice_rlim <=task_rlim_get_cur (p,RLIMIT_NICE ) ||capable (CAP_SYS_NICE )); }
@@ -6257,7 +6257,7 @@ recheck:if (!lock_task_sighand (p, &flags))return -ESRCH ; - rlim_rtprio = p->signal->rlim[RLIMIT_RTPRIO ].rlim_cur; + rlim_rtprio =task_rlim_get_cur (p,RLIMIT_RTPRIO );unlock_task_sighand (p, &flags);/* can't set/change the rt policy */
kernel/sched_rt.c +3 -2
@@ -1683,8 +1683,9 @@ static void watchdog(struct rq *rq, struct task_struct *p)if (!p->signal)return ; - soft = p->signal->rlim[RLIMIT_RTTIME ].rlim_cur; - hard = p->signal->rlim[RLIMIT_RTTIME ].rlim_max; +/* max may change after cur was read, this will be fixed next tick */ + soft =task_rlim_get_cur (p,RLIMIT_RTTIME ); + hard =task_rlim_get_max (p,RLIMIT_RTTIME );if (soft !=RLIM_INFINITY ) {unsigned long next;
kernel/signal.c +1 -1
@@ -209,7 +209,7 @@ static struct sigqueue *__sigqueue_alloc(struct task_struct *t, gfp_t flags,atomic_inc (&user->sigpending);if (override_rlimit ||atomic_read (&user->sigpending) <= - t->signal->rlim[RLIMIT_SIGPENDING ].rlim_cur) +task_rlim_get_cur (t,RLIMIT_SIGPENDING )) q =kmem_cache_alloc (sigqueue_cachep, flags);if (unlikely (q ==NULL )) {atomic_dec (&user->sigpending);
kernel/sys.c +1 -2
@@ -572,8 +572,7 @@ static int set_user(struct cred *new)return -EINVAL ; } -if (atomic_read (&new_user->processes) >= - current->signal->rlim[RLIMIT_NPROC ].rlim_cur && +if (atomic_read (&new_user->processes) >=rlim_get_cur (RLIMIT_NPROC ) && new_user !=INIT_USER ) {free_uid (new_user);return -EAGAIN ;
Signature · 1 line
1.6.5.3
PATCH v3 23/27 misc: use helpers for rlimits
In reply to Jiri SlabyMake sure compiler won't do weird things with limits. E.g. fetching them twice may return 2 different values after writable limits are implemented.
I.e. either use newly added rlimit helpers or ACCESS_ONCE if not applicable.
--- drivers/infiniband/core/umem.c | 2 +- drivers/infiniband/hw/ipath/ipath_user_pages.c | 3 +-- ipc/mqueue.c | 2 +- ipc/shm.c | 3 +-- 4 files changed, 4 insertions(+), 6 deletions(-)
drivers/infiniband/core/umem.c +1 -1
@@ -136,7 +136,7 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,down_write (¤t->mm->mmap_sem); locked = npages + current->mm->locked_vm; - lock_limit = current->signal->rlim[RLIMIT_MEMLOCK ].rlim_cur >>PAGE_SHIFT ; + lock_limit =rlim_get_cur (RLIMIT_MEMLOCK ) >>PAGE_SHIFT ;if ((locked > lock_limit) && !capable (CAP_IPC_LOCK )) { ret = -ENOMEM ;
drivers/infiniband/hw/ipath/ipath_user_pages.c +1 -2
@@ -59,8 +59,7 @@ static int __get_user_pages(unsigned long start_page, size_t num_pages,size_t got;int ret; - lock_limit = current->signal->rlim[RLIMIT_MEMLOCK ].rlim_cur >> -PAGE_SHIFT ; + lock_limit =rlim_get_cur (RLIMIT_MEMLOCK ) >>PAGE_SHIFT ;if (num_pages > lock_limit) { ret = -ENOMEM ;
ipc/mqueue.c +1 -1
@@ -153,7 +153,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,spin_lock (&mq_lock);if (u->mq_bytes + mq_bytes < u->mq_bytes || u->mq_bytes + mq_bytes > - p->signal->rlim[RLIMIT_MSGQUEUE ].rlim_cur) { +task_rlim_get_cur (p,RLIMIT_MSGQUEUE )) {spin_unlock (&mq_lock); goto out_inode; }
ipc/shm.c +1 -2
@@ -761,8 +761,7 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf)if (euid != shp->shm_perm.uid && euid != shp->shm_perm.cuid) goto out_unlock; -if (cmd ==SHM_LOCK && - !current->signal->rlim[RLIMIT_MEMLOCK ].rlim_cur) +if (cmd ==SHM_LOCK && !rlim_get_cur (RLIMIT_MEMLOCK )) goto out_unlock; }
Signature · 1 line
1.6.5.3
Re: [PATCH v3 23/27] misc: use helpers for rlimits
Not sure it matters at this part, but for the drivers/infiniband part, you can add:
wrapping all the current->signal->rlim[] stuff in a helper function looks like a nice cleanup independent of the writable limit stuff.
- R.
PATCH v3 24/27 core: implement getprlimit and setprlimit syscalls
In reply to Jiri SlabyThis patch adds the code to support the sys_setprlimit and set_getprlimit syscalls which modify the rlim values of a selected process.
All rlim users now either use newly added accessors or doesn't need them due to
- locking
- a process was just forked and nobody else knows about it yet (and nobody can't thus read/write limits)
Based on Neil's work. Thank him.
--- include/linux/syscalls.h | 4 ++ kernel/sys.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 0 deletions(-)
include/linux/syscalls.h +4 -0
@@ -702,11 +702,15 @@ asmlinkage long sys_newuname(struct new_utsname __user *name);asmlinkage long sys_getrlimit (unsigned int resource,struct rlimit __user *rlim); +asmlinkage long sys_getprlimit (pid_t pid,unsigned int resource, +struct rlimit __user *rlim);#if defined(COMPAT_RLIM_OLD_INFINITY ) || !(defined(CONFIG_IA64 ))asmlinkage long sys_old_getrlimit (unsigned int resource,struct rlimit __user *rlim);#endif asmlinkage long sys_setrlimit (unsigned int resource,struct rlimit __user *rlim); +asmlinkage long sys_setprlimit (pid_t pid,unsigned int resource, +struct rlimit __user *rlim);asmlinkage long sys_getrusage (int who,struct rusage __user *ru);asmlinkage long sys_umask (int mask);
kernel/sys.c +86 -0
98 lines not on this page · raw message
Signature · 1 line
1.6.5.3
PATCH v3 25/27 unistd: add __NR_[get|set]prlimit syscall numbers
In reply to Jiri SlabyFrom: Neil Horman <[email protected]>
Add __NR_[get|set]prlimit syscall numbers to asm-generic. Add them also to asm-x86.
--- arch/x86/include/asm/unistd_32.h | 4 +++- arch/x86/include/asm/unistd_64.h | 4 ++++ arch/x86/kernel/syscall_table_32.S | 2 ++ include/asm-generic/unistd.h | 6 +++++- 4 files changed, 14 insertions(+), 2 deletions(-)
arch/x86/include/asm/unistd_32.h +3 -1
@@ -342,10 +342,12 @@#define __NR_pwritev 334#define __NR_rt_tgsigqueueinfo 335#define __NR_perf_event_open 336 +#define __NR_getprlimit 337 +#define __NR_setprlimit 338#ifdef __KERNEL__ -#define NR_syscalls 337 +#define NR_syscalls 339#define __ARCH_WANT_IPC_PARSE_VERSION#define __ARCH_WANT_OLD_READDIR
arch/x86/include/asm/unistd_64.h +4 -0
@@ -661,6 +661,10 @@ __SYSCALL(__NR_pwritev, sys_pwritev) __SYSCALL(__NR_rt_tgsigqueueinfo, sys_rt_tgsigqueueinfo)#define __NR_perf_event_open 298 __SYSCALL(__NR_perf_event_open, sys_perf_event_open) +#define __NR_getprlimit 299 +__SYSCALL(__NR_getprlimit, sys_getprlimit) +#define __NR_setprlimit 300 +__SYSCALL(__NR_setprlimit, sys_setprlimit)#ifndef __NO_STUBS#define __ARCH_WANT_OLD_READDIR
arch/x86/kernel/syscall_table_32.S +2 -0
@@ -336,3 +336,5 @@ ENTRY(sys_call_table) .long sys_pwritev .long sys_rt_tgsigqueueinfo /* 335 */ .long sys_perf_event_open + .long sys_getprlimit + .long sys_setprlimit
include/asm-generic/unistd.h +5 -1
@@ -622,9 +622,13 @@ __SYSCALL(__NR_move_pages, sys_move_pages) __SYSCALL(__NR_rt_tgsigqueueinfo, sys_rt_tgsigqueueinfo)#define __NR_perf_event_open 241 __SYSCALL(__NR_perf_event_open, sys_perf_event_open) +#define __NR_getprlimit 242 +__SYSCALL(__NR_getprlimit, sys_getprlimit) +#define __NR_setprlimit 243 +__SYSCALL(__NR_setprlimit, sys_setprlimit)#undef __NR_syscalls -#define __NR_syscalls 242 +#define __NR_syscalls 244/* * All syscalls below here should go away really,
Signature · 1 line
1.6.5.3
PATCH v3 26/27 COMPAT: add get/put_compat_rlimit
In reply to Jiri SlabyExtract those functions from compat_sys_[gs]etrlimit for later use with newly added rlimit syscalls.
--- kernel/compat.c | 61 ++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 40 insertions(+), 21 deletions(-)
kernel/compat.c +40 -21
@@ -274,6 +274,39 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,return ret; } +static int get_compat_rlimit (struct rlimit *dst, +const struct compat_rlimit __user *src) +{ +if (!access_ok (VERIFY_READ , src,sizeof (*src)) || +__get_user (dst->rlim_cur, &src->rlim_cur) || +__get_user (dst->rlim_max, &src->rlim_max)) +return -EFAULT ; + +if (dst->rlim_cur ==COMPAT_RLIM_INFINITY ) + dst->rlim_cur =RLIM_INFINITY ; +if (dst->rlim_max ==COMPAT_RLIM_INFINITY ) + dst->rlim_max =RLIM_INFINITY ; +return 0 ; +} + +static int put_compat_rlimit (const struct rlimit *src, +struct compat_rlimit __user *dst) +{ +struct rlimit r = *src; + +if (r.rlim_cur >COMPAT_RLIM_INFINITY ) + r.rlim_cur =COMPAT_RLIM_INFINITY ; +if (r.rlim_max >COMPAT_RLIM_INFINITY ) + r.rlim_max =COMPAT_RLIM_INFINITY ; + +if (!access_ok (VERIFY_WRITE , dst,sizeof (*dst)) || +__put_user (r.rlim_cur, &dst->rlim_cur) || +__put_user (r.rlim_max, &dst->rlim_max)) +return -EFAULT ; + +return 0 ; +} +asmlinkage long compat_sys_setrlimit (unsigned int resource,struct compat_rlimit __user *rlim) {
@@ -284,17 +317,12 @@ asmlinkage long compat_sys_setrlimit(unsigned int resource,if (resource >=RLIM_NLIMITS )return -EINVAL ; -if (!access_ok (VERIFY_READ , rlim,sizeof (*rlim)) || -__get_user (r.rlim_cur, &rlim->rlim_cur) || -__get_user (r.rlim_max, &rlim->rlim_max)) -return -EFAULT ; + ret =get_compat_rlimit (&r, rlim); +if (ret) +return ret; -if (r.rlim_cur ==COMPAT_RLIM_INFINITY ) - r.rlim_cur =RLIM_INFINITY ; -if (r.rlim_max ==COMPAT_RLIM_INFINITY ) - r.rlim_max =RLIM_INFINITY ;set_fs (KERNEL_DS ); - ret =sys_setrlimit (resource, (struct rlimit __user *) &r); + ret =sys_setrlimit (resource, (struct rlimit __force __user *)&r);set_fs (old_fs);return ret; }
@@ -336,19 +364,10 @@ asmlinkage long compat_sys_getrlimit (unsigned int resource,mm_segment_t old_fs =get_fs ();set_fs (KERNEL_DS ); - ret =sys_getrlimit (resource, (struct rlimit __user *) &r); + ret =sys_getrlimit (resource, (struct rlimit __force __user *)&r);set_fs (old_fs); -if (!ret) { -if (r.rlim_cur >COMPAT_RLIM_INFINITY ) - r.rlim_cur =COMPAT_RLIM_INFINITY ; -if (r.rlim_max >COMPAT_RLIM_INFINITY ) - r.rlim_max =COMPAT_RLIM_INFINITY ; - -if (!access_ok (VERIFY_WRITE , rlim,sizeof (*rlim)) || -__put_user (r.rlim_cur, &rlim->rlim_cur) || -__put_user (r.rlim_max, &rlim->rlim_max)) -return -EFAULT ; - } +if (!ret) + ret =put_compat_rlimit (&r, rlim);return ret; }
Signature · 1 line
1.6.5.3
PATCH v3 27/27 x86: add ia32 compat prlimit syscalls
In reply to Jiri SlabyTo support 32/64-bit compatibility (rlimit structure contains 2 longs) for prlimit syscalls, add compat wrappers for them.
--- arch/x86/ia32/ia32entry.S | 2 ++ kernel/compat.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 0 deletions(-)
arch/x86/ia32/ia32entry.S +2 -0
@@ -841,4 +841,6 @@ ia32_sys_call_table: .quad compat_sys_pwritev .quad compat_sys_rt_tgsigqueueinfo /* 335 */ .quad sys_perf_event_open + .quad compat_sys_getprlimit + .quad compat_sys_setprlimit ia32_syscall_end:
kernel/compat.c +32 -0
@@ -371,6 +371,38 @@ asmlinkage long compat_sys_getrlimit (unsigned int resource,return ret; } +asmlinkage long compat_sys_setprlimit (pid_t pid,unsigned int resource, +struct compat_rlimit __user *rlim) +{ +mm_segment_t old_fs =get_fs (); +struct rlimit r; +int ret; + + ret =get_compat_rlimit (&r, rlim); +if (ret) +return ret; + +set_fs (KERNEL_DS ); + ret =sys_setprlimit (pid, resource, (struct rlimit __force __user *)&r); +set_fs (old_fs); +return ret; +} + +asmlinkage long compat_sys_getprlimit (pid_t pid,unsigned int resource, +struct compat_rlimit __user *rlim) +{ +mm_segment_t old_fs =get_fs (); +struct rlimit r; +int ret; + +set_fs (KERNEL_DS ); + ret =sys_getprlimit (pid, resource, (struct rlimit __force __user *)&r); +set_fs (old_fs); +if (!ret) + ret =put_compat_rlimit (&r, rlim); +return ret; +} +int put_compat_rusage (const struct rusage *r,struct compat_rusage __user *ru) { if (!access_ok(VERIFY_WRITE, ru, sizeof(*ru)) ||
Signature · 1 line
1.6.5.3
v3 cover writable limits
In reply to Jiri SlabyHi,
I broke the threading to not mess up with the long thread.
In this version I got rid of the rlim access_only ugliness.
There are two things:
1)
<quote from=Ingo>
A prominent example would be the stack limit - we base address layout decisions on it. Check arch/x86/mm/mmap.c. RLIM_INFINITY has a special meaning plus we also set mmap_base() based on the rlim. </quote>
Should there be some special handling of that? In standard setrlimit there is none.
2)
<quote from=Oleg>
Hmm. you are right. Do you know why acct_file_reopen() does
if (old_acct) do_acct_process();
???
</quote>
As I expressed myself before, I don't know why it is there (it doesn't make sense to me either). But I took a look at when it was added. From the very first merge of acct.c (2.1.68pre1) it was just in (name == NULL) path (turning acct off). Then in 2.1.126 it was switched to account on every accounting file change.
I fear if we changed this, something would break.
thanks,
Signature · 1 line
js
Re: [PATCH v3 00/27] writable limits
Quoted 5 lines · Jiri Slaby
Hi,
I broke the threading to not mess up with the long thread.
In this version I got rid of the rlim
access_onlyugliness.
Thanks Jiri - this series looks very clean already and the helpers make the various usage sites easier to understand as well.
One (very small) naming suggestion, please rename:
rlim_get_cur()
rlim_get_max()
task_rlim_get_cur()
task_rlim_get_max()
To a more natural sounding scheme like:
rlimit()
rlimit_max()
task_rlimit()
task_rlimit_max()
Reasons:
- 'cur' is a misnomer that came a decade+ ago from an ABI and there's no need to continue that bad tradition in helper functions. It can also be confused with 'curr' which we often use for the current task.
- 'rlimit' is general meme, plus there's no need to say it out aloud that we 'get' it - rlimit() is obvious enough.
Beyond solving these issues it makes it shorter and more logical as well.
Thanks,
Ingo