From 462a2cb18ca51afec08e3c80acfe79dd69786332 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 26 Oct 2017 01:04:46 -0400 Subject: exec: Make argument size tracking robust to page-granularity accounting From looking at the Linux exec() implementation, it seems a big part of the reason we needed extra headroom was that the arguments/environment are copied page-by-page, so even a small accounting difference could result in an error of an entire page size. Grow the headroom to two entire pages to account for this. --- exec.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'exec.c') diff --git a/exec.c b/exec.c index b982f85..23ea0c7 100644 --- a/exec.c +++ b/exec.c @@ -89,9 +89,14 @@ static size_t bfs_exec_arg_max(const struct bfs_exec *execbuf) { arg_max -= sizeof(char *); bfs_exec_debug(execbuf, "ARG_MAX: %ld remaining after fixed arguments\n", arg_max); - // POSIX recommends subtracting 2048, for some wiggle room - // We subtract 4096 for extra insurance, based on some experimentation - arg_max -= 4096; + // Assume arguments are counted with the granularity of a single page, + // and allow two pages of headroom to account for rounding as well as + // any other data we may not be counting + long page_size = sysconf(_SC_PAGESIZE); + if (page_size < 4096) { + page_size = 4096; + } + arg_max -= 2*page_size; bfs_exec_debug(execbuf, "ARG_MAX: %ld remaining after headroom\n", arg_max); if (arg_max < 0) { -- cgit v1.2.3