diff options
author | Jiri Slaby <jslaby@suse.cz> | 2010-03-05 16:42:42 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-03-06 14:26:29 -0500 |
commit | d554ed895dc8f293cc712c71f14b101ace82579a (patch) | |
tree | fd29ba33d640e156e2ca4267ffbdb9dc566fd3d6 | |
parent | 221e3ebf6d5f2625373573155924e39f196c5d3d (diff) |
fs: use rlimit helpers
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 rlimit helpers added in commit 3e10e716abf3 ("resource:
add helpers for fetching rlimits") or ACCESS_ONCE if not applicable.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | fs/attr.c | 2 | ||||
-rw-r--r-- | fs/binfmt_aout.c | 2 | ||||
-rw-r--r-- | fs/binfmt_flat.c | 2 | ||||
-rw-r--r-- | fs/exec.c | 8 | ||||
-rw-r--r-- | fs/fcntl.c | 2 | ||||
-rw-r--r-- | fs/file.c | 2 | ||||
-rw-r--r-- | fs/proc/array.c | 4 | ||||
-rw-r--r-- | fs/select.c | 2 |
8 files changed, 12 insertions, 12 deletions
@@ -81,7 +81,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset) | |||
81 | if (inode->i_size < offset) { | 81 | if (inode->i_size < offset) { |
82 | unsigned long limit; | 82 | unsigned long limit; |
83 | 83 | ||
84 | limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur; | 84 | limit = rlimit(RLIMIT_FSIZE); |
85 | if (limit != RLIM_INFINITY && offset > limit) | 85 | if (limit != RLIM_INFINITY && offset > limit) |
86 | goto out_sig; | 86 | goto out_sig; |
87 | if (offset > inode->i_sb->s_maxbytes) | 87 | if (offset > inode->i_sb->s_maxbytes) |
diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c index fdd397099172..61dd00a6c7b4 100644 --- a/fs/binfmt_aout.c +++ b/fs/binfmt_aout.c | |||
@@ -247,7 +247,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs) | |||
247 | * size limits imposed on them by creating programs with large | 247 | * size limits imposed on them by creating programs with large |
248 | * arrays in the data or bss. | 248 | * arrays in the data or bss. |
249 | */ | 249 | */ |
250 | rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur; | 250 | rlim = rlimit(RLIMIT_DATA); |
251 | if (rlim >= RLIM_INFINITY) | 251 | if (rlim >= RLIM_INFINITY) |
252 | rlim = ~0; | 252 | rlim = ~0; |
253 | if (ex.a_data + ex.a_bss > rlim) | 253 | if (ex.a_data + ex.a_bss > rlim) |
diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c index 42c6b4a54445..e0e769bdca59 100644 --- a/fs/binfmt_flat.c +++ b/fs/binfmt_flat.c | |||
@@ -501,7 +501,7 @@ static int load_flat_file(struct linux_binprm * bprm, | |||
501 | * size limits imposed on them by creating programs with large | 501 | * size limits imposed on them by creating programs with large |
502 | * arrays in the data or bss. | 502 | * arrays in the data or bss. |
503 | */ | 503 | */ |
504 | rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur; | 504 | rlim = rlimit(RLIMIT_DATA); |
505 | if (rlim >= RLIM_INFINITY) | 505 | if (rlim >= RLIM_INFINITY) |
506 | rlim = ~0; | 506 | rlim = ~0; |
507 | if (data_len + bss_len > rlim) { | 507 | if (data_len + bss_len > rlim) { |
@@ -195,7 +195,7 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos, | |||
195 | * to work from. | 195 | * to work from. |
196 | */ | 196 | */ |
197 | rlim = current->signal->rlim; | 197 | rlim = current->signal->rlim; |
198 | if (size > rlim[RLIMIT_STACK].rlim_cur / 4) { | 198 | if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur) / 4) { |
199 | put_page(page); | 199 | put_page(page); |
200 | return NULL; | 200 | return NULL; |
201 | } | 201 | } |
@@ -579,7 +579,7 @@ int setup_arg_pages(struct linux_binprm *bprm, | |||
579 | 579 | ||
580 | #ifdef CONFIG_STACK_GROWSUP | 580 | #ifdef CONFIG_STACK_GROWSUP |
581 | /* Limit stack size to 1GB */ | 581 | /* Limit stack size to 1GB */ |
582 | stack_base = current->signal->rlim[RLIMIT_STACK].rlim_max; | 582 | stack_base = rlimit_max(RLIMIT_STACK); |
583 | if (stack_base > (1 << 30)) | 583 | if (stack_base > (1 << 30)) |
584 | stack_base = 1 << 30; | 584 | stack_base = 1 << 30; |
585 | 585 | ||
@@ -1535,7 +1535,7 @@ static int format_corename(char *corename, long signr) | |||
1535 | /* core limit size */ | 1535 | /* core limit size */ |
1536 | case 'c': | 1536 | case 'c': |
1537 | rc = snprintf(out_ptr, out_end - out_ptr, | 1537 | rc = snprintf(out_ptr, out_end - out_ptr, |
1538 | "%lu", current->signal->rlim[RLIMIT_CORE].rlim_cur); | 1538 | "%lu", rlimit(RLIMIT_CORE)); |
1539 | if (rc > out_end - out_ptr) | 1539 | if (rc > out_end - out_ptr) |
1540 | goto out; | 1540 | goto out; |
1541 | out_ptr += rc; | 1541 | out_ptr += rc; |
@@ -1800,7 +1800,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs) | |||
1800 | struct coredump_params cprm = { | 1800 | struct coredump_params cprm = { |
1801 | .signr = signr, | 1801 | .signr = signr, |
1802 | .regs = regs, | 1802 | .regs = regs, |
1803 | .limit = current->signal->rlim[RLIMIT_CORE].rlim_cur, | 1803 | .limit = rlimit(RLIMIT_CORE), |
1804 | }; | 1804 | }; |
1805 | 1805 | ||
1806 | audit_core_dumps(signr); | 1806 | audit_core_dumps(signr); |
diff --git a/fs/fcntl.c b/fs/fcntl.c index 97e01dc0d95f..452d02f9075e 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c | |||
@@ -344,7 +344,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg, | |||
344 | switch (cmd) { | 344 | switch (cmd) { |
345 | case F_DUPFD: | 345 | case F_DUPFD: |
346 | case F_DUPFD_CLOEXEC: | 346 | case F_DUPFD_CLOEXEC: |
347 | if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur) | 347 | if (arg >= rlimit(RLIMIT_NOFILE)) |
348 | break; | 348 | break; |
349 | err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0); | 349 | err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0); |
350 | if (err >= 0) { | 350 | if (err >= 0) { |
@@ -257,7 +257,7 @@ int expand_files(struct files_struct *files, int nr) | |||
257 | * N.B. For clone tasks sharing a files structure, this test | 257 | * N.B. For clone tasks sharing a files structure, this test |
258 | * will limit the total number of files that can be opened. | 258 | * will limit the total number of files that can be opened. |
259 | */ | 259 | */ |
260 | if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur) | 260 | if (nr >= rlimit(RLIMIT_NOFILE)) |
261 | return -EMFILE; | 261 | return -EMFILE; |
262 | 262 | ||
263 | /* Do we need to expand? */ | 263 | /* Do we need to expand? */ |
diff --git a/fs/proc/array.c b/fs/proc/array.c index 18e20feee251..aa8637b81028 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c | |||
@@ -273,7 +273,7 @@ static inline void task_sig(struct seq_file *m, struct task_struct *p) | |||
273 | rcu_read_lock(); /* FIXME: is this correct? */ | 273 | rcu_read_lock(); /* FIXME: is this correct? */ |
274 | qsize = atomic_read(&__task_cred(p)->user->sigpending); | 274 | qsize = atomic_read(&__task_cred(p)->user->sigpending); |
275 | rcu_read_unlock(); | 275 | rcu_read_unlock(); |
276 | qlim = p->signal->rlim[RLIMIT_SIGPENDING].rlim_cur; | 276 | qlim = task_rlimit(p, RLIMIT_SIGPENDING); |
277 | unlock_task_sighand(p, &flags); | 277 | unlock_task_sighand(p, &flags); |
278 | } | 278 | } |
279 | 279 | ||
@@ -420,7 +420,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, | |||
420 | cutime = sig->cutime; | 420 | cutime = sig->cutime; |
421 | cstime = sig->cstime; | 421 | cstime = sig->cstime; |
422 | cgtime = sig->cgtime; | 422 | cgtime = sig->cgtime; |
423 | rsslim = sig->rlim[RLIMIT_RSS].rlim_cur; | 423 | rsslim = ACCESS_ONCE(sig->rlim[RLIMIT_RSS].rlim_cur); |
424 | 424 | ||
425 | /* add up live thread stats at the group level */ | 425 | /* add up live thread stats at the group level */ |
426 | if (whole) { | 426 | if (whole) { |
diff --git a/fs/select.c b/fs/select.c index fd38ce2e32e3..73715e90030f 100644 --- a/fs/select.c +++ b/fs/select.c | |||
@@ -821,7 +821,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds, | |||
821 | struct poll_list *walk = head; | 821 | struct poll_list *walk = head; |
822 | unsigned long todo = nfds; | 822 | unsigned long todo = nfds; |
823 | 823 | ||
824 | if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur) | 824 | if (nfds > rlimit(RLIMIT_NOFILE)) |
825 | return -EINVAL; | 825 | return -EINVAL; |
826 | 826 | ||
827 | len = min_t(unsigned int, nfds, N_STACK_PPS); | 827 | len = min_t(unsigned int, nfds, N_STACK_PPS); |