This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] posix: Remove dynamic memory allocation from execl{e,p}
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: Joseph Myers <joseph at codesourcery dot com>
- Cc: Florian Weimer <fweimer at redhat dot com>, libc-alpha at sourceware dot org
- Date: Fri, 29 Jan 2016 16:05:49 -0200
- Subject: Re: [PATCH] posix: Remove dynamic memory allocation from execl{e,p}
- Authentication-results: sourceware.org; auth=none
- References: <1454075599-2304-1-git-send-email-adhemerval dot zanella at linaro dot org> <56AB6FFF dot 7040308 at redhat dot com> <alpine dot DEB dot 2 dot 10 dot 1601291541490 dot 29026 at digraph dot polyomino dot org dot uk> <56ABA3D5 dot 4000905 at linaro dot org> <alpine dot DEB dot 2 dot 10 dot 1601291741200 dot 29026 at digraph dot polyomino dot org dot uk>
On 29-01-2016 15:45, Joseph Myers wrote:
> On Fri, 29 Jan 2016, Adhemerval Zanella wrote:
>
>> My view is for such function is just try to allocate the buffer on
>> stack and allow it fails through invalid access in case of buffer
>> overflow.
>
> I'd say just trying the allocation is OK in this case (if stack allocation
> is all that's permitted by the function semantics, and bearing in mind
> that current Linux versions determine ARG_MAX dynamically based on the
> stack limit) *if* it's allocated in a way that guarantees failure if it's
> too large (i.e. touching each page in turn) rather than potentially
> overflowing into unrelated memory.
>
That is the idea, the buffer is allocated to exactly fit the required
arguments (different that current algorithm that double each iteration).
For posix_spawn{p} I used a different strategy for the clone(VFORK),
which I think it is slight better but does impose some constraints:
allocate a mmap(STACK) with default architecture stack size and set
is as the stack for children. I think it is better than possible clobber
a stack allocated buffer from parent.