This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 2/2][BZ #12416] Use stack boundaries from /proc/PID/mapsto make stack executable
- From: KOSAKI Motohiro <kosaki dot motohiro at gmail dot com>
- To: Siddhesh Poyarekar <siddhesh at redhat dot com>
- Cc: Roland McGrath <roland at hack dot frob dot com>, libc-alpha at sourceware dot org
- Date: Mon, 11 Jun 2012 18:43:17 -0400
- Subject: Re: [PATCH 2/2][BZ #12416] Use stack boundaries from /proc/PID/mapsto make stack executable
- References: <20120419120021.4780e8c8@spoyarek> <20120425203424.A744A2C0CA@topped-with-meat.com><20120426123653.765f1462@spoyarek> <20120504231020.AF7C92C093@topped-with-meat.com><20120507084337.6d1ea127@spoyarek> <20120507200221.963992C099@topped-with-meat.com><20120508161750.063e9791@spoyarek> <20120514234622.30D472C09E@topped-with-meat.com><20120515081610.1b4aee17@spoyarek> <20120515163033.CD04B2C08B@topped-with-meat.com><20120516123338.55cd9a34@spoyarek> <CAHGf_=p3QUrym2+LBSsB+n0faog=kSK1bTu-AAnCCGYxbDEUkw@mail.gmail.com><20120612030815.5ce0d91f@spoyarek>
On Mon, Jun 11, 2012 at 5:38 PM, Siddhesh Poyarekar <siddhesh@redhat.com> wrote:
> On 12 June 2012 02:44, KOSAKI wrote:
>> I received a complains against this change from ruby folks. Because
>> of, ruby interpreter show special error message when stack overflow is
>> detected. and they assume "stackaddr - stacksize" point to stack edge.
>>
>> But this patch only changed stackaddr. thus the assuption broke.
>> Is there any chance to change stacksize too?
>
> Can you or the ruby devs please give a more detailed explanation of the
> problem they're seeing? The patch does in fact change the stack size if
> the distance of the stack bottom from the vma immediately below the
> stack top is less than the stack rlimit. From nptl/pthread_getattr_np.c:
>
> ? ? ? ? ? ? ? ? ? ? ?iattr->stacksize = rl.rlim_cur;
> ? ? ? ? ? ? ? ? ? ? ?iattr->stackaddr = stack_end;
>
> ? ? ? ? ? ? ? ? ? ? ?/* The limit might be too high. ?*/
> ? ? ? ? ? ? ? ? ? ? ?if ((size_t) iattr->stacksize
> ? ? ? ? ? ? ? ? ? ? ? ? ?> (size_t) iattr->stackaddr - last_to)
> ? ? ? ? ? ? ? ? ? ? ? ?iattr->stacksize = (size_t) iattr->stackaddr -
> ? ? ? ? ? ? ? ? ? ? ?last_to;
>
> See how stacksize is derived from stackaddr, which in this case is the
> stack bottom. In fact, the stackaddr you get from
> pthread_attr_getstack() is again derived from the stack bottom and
> stack size to get the stack top, so doing stackaddr - stacksize with
> that value will lead you nowhere.
sorry, my explanation was not clear. "stackaddr - stacksize" meant to
call pthread_attr_getstack().
rl.rlim_cur represent kernel vma based size. then, if you ignore some
regions (e.g argv, environ and auxv area), I think the right stack size
is following.
ignore_size = to - stack_end;
iattr->stacksize = rl.rlim_cur - ignore_size;
otherwise, a result of pthread_attr_getstack() may violate following sentence.
http://pubs.opengroup.org/onlinepubs/007904975/functions/pthread_attr_setstack.html
>All pages within the stack described by stackaddr and stacksize shall be
> both readable and writable by the thread.
If my parsing is correct, following adjustment only works when previous vma is
enough near.
> ? ? ? ? ? ? ? ? ? ? ?/* The limit might be too high. ?*/
> ? ? ? ? ? ? ? ? ? ? ?if ((size_t) iattr->stacksize
> ? ? ? ? ? ? ? ? ? ? ? ? ?> (size_t) iattr->stackaddr - last_to)
> ? ? ? ? ? ? ? ? ? ? ? ?iattr->stacksize = (size_t) iattr->stackaddr -
> ? ? ? ? ? ? ? ? ? ? ?last_to;
Am I missing something?
> pthread_attr_getstackaddr does return the bottom of stack but that
> function is deprecated and that usage should be replaced with
> pthread_attr_getstack.
>
> A reproducer would help to understand what they're seeing.
Please give me some time. I need to build libc development sandbox.