Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jiri Slaby and committed by
Linus Torvalds
d554ed89 221e3ebf

+12 -12
+1 -1
fs/attr.c
··· 81 81 if (inode->i_size < offset) { 82 82 unsigned long limit; 83 83 84 - limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur; 84 + limit = rlimit(RLIMIT_FSIZE); 85 85 if (limit != RLIM_INFINITY && offset > limit) 86 86 goto out_sig; 87 87 if (offset > inode->i_sb->s_maxbytes)
+1 -1
fs/binfmt_aout.c
··· 247 247 * size limits imposed on them by creating programs with large 248 248 * arrays in the data or bss. 249 249 */ 250 - rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur; 250 + rlim = rlimit(RLIMIT_DATA); 251 251 if (rlim >= RLIM_INFINITY) 252 252 rlim = ~0; 253 253 if (ex.a_data + ex.a_bss > rlim)
+1 -1
fs/binfmt_flat.c
··· 501 501 * size limits imposed on them by creating programs with large 502 502 * arrays in the data or bss. 503 503 */ 504 - rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur; 504 + rlim = rlimit(RLIMIT_DATA); 505 505 if (rlim >= RLIM_INFINITY) 506 506 rlim = ~0; 507 507 if (data_len + bss_len > rlim) {
+4 -4
fs/exec.c
··· 195 195 * to work from. 196 196 */ 197 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 199 put_page(page); 200 200 return NULL; 201 201 } ··· 579 579 580 580 #ifdef CONFIG_STACK_GROWSUP 581 581 /* Limit stack size to 1GB */ 582 - stack_base = current->signal->rlim[RLIMIT_STACK].rlim_max; 582 + stack_base = rlimit_max(RLIMIT_STACK); 583 583 if (stack_base > (1 << 30)) 584 584 stack_base = 1 << 30; 585 585 ··· 1535 1535 /* core limit size */ 1536 1536 case 'c': 1537 1537 rc = snprintf(out_ptr, out_end - out_ptr, 1538 - "%lu", current->signal->rlim[RLIMIT_CORE].rlim_cur); 1538 + "%lu", rlimit(RLIMIT_CORE)); 1539 1539 if (rc > out_end - out_ptr) 1540 1540 goto out; 1541 1541 out_ptr += rc; ··· 1800 1800 struct coredump_params cprm = { 1801 1801 .signr = signr, 1802 1802 .regs = regs, 1803 - .limit = current->signal->rlim[RLIMIT_CORE].rlim_cur, 1803 + .limit = rlimit(RLIMIT_CORE), 1804 1804 }; 1805 1805 1806 1806 audit_core_dumps(signr);
+1 -1
fs/fcntl.c
··· 344 344 switch (cmd) { 345 345 case F_DUPFD: 346 346 case F_DUPFD_CLOEXEC: 347 - if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur) 347 + if (arg >= rlimit(RLIMIT_NOFILE)) 348 348 break; 349 349 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0); 350 350 if (err >= 0) {
+1 -1
fs/file.c
··· 257 257 * N.B. For clone tasks sharing a files structure, this test 258 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 261 return -EMFILE; 262 262 263 263 /* Do we need to expand? */
+2 -2
fs/proc/array.c
··· 273 273 rcu_read_lock(); /* FIXME: is this correct? */ 274 274 qsize = atomic_read(&__task_cred(p)->user->sigpending); 275 275 rcu_read_unlock(); 276 - qlim = p->signal->rlim[RLIMIT_SIGPENDING].rlim_cur; 276 + qlim = task_rlimit(p, RLIMIT_SIGPENDING); 277 277 unlock_task_sighand(p, &flags); 278 278 } 279 279 ··· 420 420 cutime = sig->cutime; 421 421 cstime = sig->cstime; 422 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 425 /* add up live thread stats at the group level */ 426 426 if (whole) {
+1 -1
fs/select.c
··· 821 821 struct poll_list *walk = head; 822 822 unsigned long todo = nfds; 823 823 824 - if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur) 824 + if (nfds > rlimit(RLIMIT_NOFILE)) 825 825 return -EINVAL; 826 826 827 827 len = min_t(unsigned int, nfds, N_STACK_PPS);