Skip to content

Commit d554ed8

Browse files
Jiri Slabytorvalds
authored andcommitted
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 3e10e71 ("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>
1 parent 221e3eb commit d554ed8

8 files changed

Lines changed: 12 additions & 12 deletions

File tree

‎fs/attr.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
8181
if (inode->i_size < offset) {
8282
unsigned long limit;
8383

84-
limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
84+
limit = rlimit(RLIMIT_FSIZE);
8585
if (limit != RLIM_INFINITY && offset > limit)
8686
goto out_sig;
8787
if (offset > inode->i_sb->s_maxbytes)

‎fs/binfmt_aout.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
247247
* size limits imposed on them by creating programs with large
248248
* arrays in the data or bss.
249249
*/
250-
rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
250+
rlim = rlimit(RLIMIT_DATA);
251251
if (rlim >= RLIM_INFINITY)
252252
rlim = ~0;
253253
if (ex.a_data + ex.a_bss > rlim)

‎fs/binfmt_flat.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ static int load_flat_file(struct linux_binprm * bprm,
501501
* size limits imposed on them by creating programs with large
502502
* arrays in the data or bss.
503503
*/
504-
rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
504+
rlim = rlimit(RLIMIT_DATA);
505505
if (rlim >= RLIM_INFINITY)
506506
rlim = ~0;
507507
if (data_len + bss_len > rlim) {

‎fs/exec.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
195195
* to work from.
196196
*/
197197
rlim = current->signal->rlim;
198-
if (size > rlim[RLIMIT_STACK].rlim_cur / 4) {
198+
if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur) / 4) {
199199
put_page(page);
200200
return NULL;
201201
}
@@ -579,7 +579,7 @@ int setup_arg_pages(struct linux_binprm *bprm,
579579

580580
#ifdef CONFIG_STACK_GROWSUP
581581
/* Limit stack size to 1GB */
582-
stack_base = current->signal->rlim[RLIMIT_STACK].rlim_max;
582+
stack_base = rlimit_max(RLIMIT_STACK);
583583
if (stack_base > (1 << 30))
584584
stack_base = 1 << 30;
585585

@@ -1535,7 +1535,7 @@ static int format_corename(char *corename, long signr)
15351535
/* core limit size */
15361536
case 'c':
15371537
rc = snprintf(out_ptr, out_end - out_ptr,
1538-
"%lu", current->signal->rlim[RLIMIT_CORE].rlim_cur);
1538+
"%lu", rlimit(RLIMIT_CORE));
15391539
if (rc > out_end - out_ptr)
15401540
goto out;
15411541
out_ptr += rc;
@@ -1800,7 +1800,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
18001800
struct coredump_params cprm = {
18011801
.signr = signr,
18021802
.regs = regs,
1803-
.limit = current->signal->rlim[RLIMIT_CORE].rlim_cur,
1803+
.limit = rlimit(RLIMIT_CORE),
18041804
};
18051805

18061806
audit_core_dumps(signr);

‎fs/fcntl.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
344344
switch (cmd) {
345345
case F_DUPFD:
346346
case F_DUPFD_CLOEXEC:
347-
if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
347+
if (arg >= rlimit(RLIMIT_NOFILE))
348348
break;
349349
err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
350350
if (err >= 0) {

‎fs/file.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ int expand_files(struct files_struct *files, int nr)
257257
* N.B. For clone tasks sharing a files structure, this test
258258
* will limit the total number of files that can be opened.
259259
*/
260-
if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
260+
if (nr >= rlimit(RLIMIT_NOFILE))
261261
return -EMFILE;
262262

263263
/* Do we need to expand? */

‎fs/proc/array.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ static inline void task_sig(struct seq_file *m, struct task_struct *p)
273273
rcu_read_lock(); /* FIXME: is this correct? */
274274
qsize = atomic_read(&__task_cred(p)->user->sigpending);
275275
rcu_read_unlock();
276-
qlim = p->signal->rlim[RLIMIT_SIGPENDING].rlim_cur;
276+
qlim = task_rlimit(p, RLIMIT_SIGPENDING);
277277
unlock_task_sighand(p, &flags);
278278
}
279279

@@ -420,7 +420,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
420420
cutime = sig->cutime;
421421
cstime = sig->cstime;
422422
cgtime = sig->cgtime;
423-
rsslim = sig->rlim[RLIMIT_RSS].rlim_cur;
423+
rsslim = ACCESS_ONCE(sig->rlim[RLIMIT_RSS].rlim_cur);
424424

425425
/* add up live thread stats at the group level */
426426
if (whole) {

‎fs/select.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
821821
struct poll_list *walk = head;
822822
unsigned long todo = nfds;
823823

824-
if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
824+
if (nfds > rlimit(RLIMIT_NOFILE))
825825
return -EINVAL;
826826

827827
len = min_t(unsigned int, nfds, N_STACK_PPS);

0 commit comments

Comments
 (0)