diff options
| author | Sean Paul <[email protected]> | 2017-06-27 15:36:28 +0000 |
|---|---|---|
| committer | Sean Paul <[email protected]> | 2017-06-27 15:36:28 +0000 |
| commit | c048c984de38d906bb0df56ec2ae90eafc123d0a (patch) | |
| tree | 4e670e712aeedcaf2e2193b64f9120e03320e01c /fs/exec.c | |
| parent | DRM: Fix an incorrectly formatted table (diff) | |
| parent | Backmerge tag 'v4.12-rc7' into drm-next (diff) | |
| download | kernel-c048c984de38d906bb0df56ec2ae90eafc123d0a.tar.gz kernel-c048c984de38d906bb0df56ec2ae90eafc123d0a.zip | |
Merge remote-tracking branch 'airlied/drm-next' into drm-misc-next-fixes
Backmerge drm-next with rc7
Diffstat (limited to 'fs/exec.c')
| -rw-r--r-- | fs/exec.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/fs/exec.c b/fs/exec.c index 72934df68471..904199086490 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -220,8 +220,26 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos, if (write) { unsigned long size = bprm->vma->vm_end - bprm->vma->vm_start; + unsigned long ptr_size; struct rlimit *rlim; + /* + * Since the stack will hold pointers to the strings, we + * must account for them as well. + * + * The size calculation is the entire vma while each arg page is + * built, so each time we get here it's calculating how far it + * is currently (rather than each call being just the newly + * added size from the arg page). As a result, we need to + * always add the entire size of the pointers, so that on the + * last call to get_arg_page() we'll actually have the entire + * correct size. + */ + ptr_size = (bprm->argc + bprm->envc) * sizeof(void *); + if (ptr_size > ULONG_MAX - size) + goto fail; + size += ptr_size; + acct_arg_size(bprm, size / PAGE_SIZE); /* @@ -239,13 +257,15 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos, * to work from. */ rlim = current->signal->rlim; - if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur) / 4) { - put_page(page); - return NULL; - } + if (size > READ_ONCE(rlim[RLIMIT_STACK].rlim_cur) / 4) + goto fail; } return page; + +fail: + put_page(page); + return NULL; } static void put_arg_page(struct page *page) |
