Commit d554ed895dc8f293cc712c71f14b101ace82579a
Committed by
Linus Torvalds
1 parent
221e3ebf6d
Exists in
master
and in
4 other branches
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>
Showing 8 changed files with 12 additions and 12 deletions Side-by-side Diff
fs/attr.c
... | ... | @@ -81,7 +81,7 @@ |
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) |
fs/binfmt_aout.c
... | ... | @@ -247,7 +247,7 @@ |
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) |
fs/binfmt_flat.c
... | ... | @@ -501,7 +501,7 @@ |
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) { |
fs/exec.c
... | ... | @@ -195,7 +195,7 @@ |
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,7 +579,7 @@ |
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,7 +1535,7 @@ |
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,7 +1800,7 @@ |
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); |
fs/fcntl.c
... | ... | @@ -344,7 +344,7 @@ |
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) { |
fs/file.c
... | ... | @@ -257,7 +257,7 @@ |
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? */ |
fs/proc/array.c
... | ... | @@ -273,7 +273,7 @@ |
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,7 +420,7 @@ |
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) { |
fs/select.c