Skip to content

Commit

Permalink
Merge branch 'writable_limits' of git://decibel.fi.muni.cz/~xslaby/linux
Browse files Browse the repository at this point in the history
* 'writable_limits' of git://decibel.fi.muni.cz/~xslaby/linux:
  unistd: add __NR_prlimit64 syscall numbers
  rlimits: implement prlimit64 syscall
  rlimits: switch more rlimit syscalls to do_prlimit
  rlimits: redo do_setrlimit to more generic do_prlimit
  rlimits: add rlimit64 structure
  rlimits: do security check under task_lock
  rlimits: allow setrlimit to non-current tasks
  rlimits: split sys_setrlimit
  rlimits: selinux, do rlimits changes under task_lock
  rlimits: make sure ->rlim_max never grows in sys_setrlimit
  rlimits: add task_struct to update_rlimit_cpu
  rlimits: security, add task_struct to setrlimit

Fix up various system call number conflicts.  We not only added fanotify
system calls in the meantime, but asm-generic/unistd.h added a wait4
along with a range of reserved per-architecture system calls.
  • Loading branch information
torvalds committed Aug 10, 2010
2 parents e8a89ce + f33ebbe commit b34d891
Show file tree
Hide file tree
Showing 15 changed files with 207 additions and 75 deletions.
1 change: 1 addition & 0 deletions arch/x86/ia32/ia32entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -844,4 +844,5 @@ ia32_sys_call_table:
.quad compat_sys_recvmmsg
.quad sys_fanotify_init
.quad sys32_fanotify_mark
.quad sys_prlimit64
ia32_syscall_end:
3 changes: 2 additions & 1 deletion arch/x86/include/asm/unistd_32.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,11 @@
#define __NR_recvmmsg 337
#define __NR_fanotify_init 338
#define __NR_fanotify_mark 339
#define __NR_prlimit64 340

#ifdef __KERNEL__

#define NR_syscalls 340
#define NR_syscalls 341

#define __ARCH_WANT_IPC_PARSE_VERSION
#define __ARCH_WANT_OLD_READDIR
Expand Down
2 changes: 2 additions & 0 deletions arch/x86/include/asm/unistd_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,8 @@ __SYSCALL(__NR_recvmmsg, sys_recvmmsg)
__SYSCALL(__NR_fanotify_init, sys_fanotify_init)
#define __NR_fanotify_mark 301
__SYSCALL(__NR_fanotify_mark, sys_fanotify_mark)
#define __NR_prlimit64 302
__SYSCALL(__NR_prlimit64, sys_prlimit64)

#ifndef __NO_STUBS
#define __ARCH_WANT_OLD_READDIR
Expand Down
1 change: 1 addition & 0 deletions arch/x86/kernel/syscall_table_32.S
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,4 @@ ENTRY(sys_call_table)
.long sys_recvmmsg
.long sys_fanotify_init
.long sys_fanotify_mark
.long sys_prlimit64
4 changes: 3 additions & 1 deletion include/asm-generic/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,11 @@ __SYSCALL(__NR_recvmmsg, sys_recvmmsg)

#define __NR_wait4 260
__SYSCALL(__NR_wait4, sys_wait4)
#define __NR_prlimit64 261
__SYSCALL(__NR_prlimit64, sys_prlimit64)

#undef __NR_syscalls
#define __NR_syscalls 261
#define __NR_syscalls 262

/*
* All syscalls below here should go away really,
Expand Down
2 changes: 1 addition & 1 deletion include/linux/posix-timers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions include/linux/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ struct rlimit {
unsigned long rlim_max;
};

#define RLIM64_INFINITY (~0ULL)

struct rlimit64 {
__u64 rlim_cur;
__u64 rlim_max;
};

#define PRIO_MIN (-20)
#define PRIO_MAX 20

Expand Down Expand Up @@ -73,6 +80,8 @@ struct rlimit {
struct task_struct;

int getrusage(struct task_struct *p, int who, struct rusage __user *ru);
int do_prlimit(struct task_struct *tsk, unsigned int resource,
struct rlimit *new_rlim, struct rlimit *old_rlim);

#endif /* __KERNEL__ */

Expand Down
9 changes: 6 additions & 3 deletions include/linux/security.h
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,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 @@ -1749,7 +1750,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 @@ -2311,7 +2313,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
4 changes: 4 additions & 0 deletions include/linux/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct oldold_utsname;
struct old_utsname;
struct pollfd;
struct rlimit;
struct rlimit64;
struct rusage;
struct sched_param;
struct sel_arg_struct;
Expand Down Expand Up @@ -644,6 +645,9 @@ asmlinkage long sys_old_getrlimit(unsigned int resource, struct rlimit __user *r
#endif
asmlinkage long sys_setrlimit(unsigned int resource,
struct rlimit __user *rlim);
asmlinkage long sys_prlimit64(pid_t pid, unsigned int resource,
const struct rlimit64 __user *new_rlim,
struct rlimit64 __user *old_rlim);
asmlinkage long sys_getrusage(int who, struct rusage __user *ru);
asmlinkage long sys_umask(int mask);

Expand Down
17 changes: 3 additions & 14 deletions kernel/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,6 @@ asmlinkage long compat_sys_setrlimit(unsigned int resource,
struct compat_rlimit __user *rlim)
{
struct rlimit r;
int ret;
mm_segment_t old_fs = get_fs ();

if (resource >= RLIM_NLIMITS)
return -EINVAL;

if (!access_ok(VERIFY_READ, rlim, sizeof(*rlim)) ||
__get_user(r.rlim_cur, &rlim->rlim_cur) ||
Expand All @@ -294,10 +289,7 @@ asmlinkage long compat_sys_setrlimit(unsigned int resource,
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);
set_fs(old_fs);
return ret;
return do_prlimit(current, resource, &r, NULL);
}

#ifdef COMPAT_RLIM_OLD_INFINITY
Expand Down Expand Up @@ -329,16 +321,13 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,

#endif

asmlinkage long compat_sys_getrlimit (unsigned int resource,
asmlinkage long compat_sys_getrlimit(unsigned int resource,
struct compat_rlimit __user *rlim)
{
struct rlimit r;
int ret;
mm_segment_t old_fs = get_fs();

set_fs(KERNEL_DS);
ret = sys_getrlimit(resource, (struct rlimit __user *) &r);
set_fs(old_fs);
ret = do_prlimit(current, resource, NULL, &r);
if (!ret) {
if (r.rlim_cur > COMPAT_RLIM_INFINITY)
r.rlim_cur = COMPAT_RLIM_INFINITY;
Expand Down
8 changes: 4 additions & 4 deletions kernel/posix-cpu-timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
* siglock protection since other code may update expiration cache as
* well.
*/
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);

spin_lock_irq(&current->sighand->siglock);
set_process_cpu_timer(current, CPUCLOCK_PROF, &cputime, NULL);
spin_unlock_irq(&current->sighand->siglock);
spin_lock_irq(&task->sighand->siglock);
set_process_cpu_timer(task, CPUCLOCK_PROF, &cputime, NULL);
spin_unlock_irq(&task->sighand->siglock);
}

static int check_clock(const clockid_t which_clock)
Expand Down
Loading

0 comments on commit b34d891

Please sign in to comment.