From: Sven Schnelle <svens@stackframe.org>
To: John David Anglin <dave.anglin@bell.net>
Cc: Helge Deller <deller@gmx.de>,
linux-parisc <linux-parisc@vger.kernel.org>,
deller@kernel.org
Subject: Re: glibc tst-minsigstksz-5 failure
Date: Wed, 08 Dec 2021 21:13:13 +0100 [thread overview]
Message-ID: <87sfv2ua7a.fsf@x1.stackframe.org> (raw)
In-Reply-To: <fb3f869d-d9c8-5997-c641-f0d7dc1aa4e6@bell.net> (John David Anglin's message of "Wed, 8 Dec 2021 09:28:51 -0500")
John David Anglin <dave.anglin@bell.net> writes:
> On 2021-12-08 8:05 a.m., Helge Deller wrote:
>> On 12/8/21 13:51, Helge Deller wrote:
>>> On 12/7/21 22:47, John David Anglin wrote:
>>>> The glibc tst-minsigstksz-5 test fails with a protection id trap.
>>>> tst-minsigstksz (pid 19958): Protection id trap (code 7) at 00000000f5b00497
>>>>
>>>> The problem seems to be that the signal return trampoline is placed
>>>> on the alternate stack but the alternate is not executable. It is
>>>> allocated by malloc.> ...
>>>> Stacks are normally executable on hppa so the trampoline works. But
>>>> user code wouldn't normally make an alternate stack executable.
>>> True, I think most people just forget that such architectures exist.
>>>
>>> Anyway, the glibc testcase is interesting.
>>> The pretty similar sigaltstack testcase from LTP does work:
>>> https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/sigaltstack/sigaltstack01.c
>>>
>>> Both use malloc() to allocate the memory, the only difference is the size allocated.
>>> If you change the glibc testcase to:
>>> -- size_t stack_buffer_size = 64 * 1024 * 1024;
>>> ++ size_t stack_buffer_size = SIGSTKSZ;
>>> it allocates only 8kB instead of 64MB.
>>> It seems glibc uses brk() in both cases, but when allocating 64MB it additionally adds a mmap() with READ/WRITE permissions only:
>>> brk(0x606000) = 0x606000
>>> mmap2(NULL, 67112960, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xf303f000
>>>
>>> This will then break - as you mentioned - the signal handling on parisc.
>>>
>>> I see those options to fix it:/usr/include/hppa-linux-gnu/asm/signal.h:#define MINSIGSTKSZ 2048
> I wonder about defining MINSIGSTKSZ to 2048 as it is smaller than a page.
>
> mprotect requires a page aligned address. Alternate stack isn't going to be page aligned if it is allocated by
> malloc. Malloc alignment isn't sufficient for nominal 64-byte stack alignment specified in runtime.
>>> /usr/include/hppa-linux-gnu/asm/signal.h:#define SIGSTKSZ 8192
>>>
>>> a) Fix the application to map the memory +x
> Doesn't fix problem..
>>> b) Add some code to glibc to map the memory +x when sigaltstack is called.
> See mprotect comment.
>>> c) Add some (parisc-only) code to kernel to set the permission.
> Again, I think region needs to be page aligned.
>> Option d):
>> Enhance the kernel to create a per-process new page and map it +rx into the userspace
>> at process start time. Kernel sets up the page to contain the signal trampoline code.
>>
>> Option e):
>> Finally implement vDSO, which then includes option d)
>>
>> With options d) and e) we could get completely rid of executable stacks.
> I like the later two options.
Note that programs are allowed to unmap the vdso. Valgrind is doing that (guess it
doesn't support hppa anyways). OTOH valgrind uses SA_RESTORER, so it
would still work. While i don't think the possibility of unmapping the
vdso would be a real issue, i thought i mention it.
Regards
Sven
prev parent reply other threads:[~2021-12-08 20:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-07 21:47 glibc tst-minsigstksz-5 failure John David Anglin
2021-12-08 12:51 ` Helge Deller
2021-12-08 13:05 ` Helge Deller
2021-12-08 14:28 ` John David Anglin
2021-12-08 20:13 ` Sven Schnelle [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sfv2ua7a.fsf@x1.stackframe.org \
--to=svens@stackframe.org \
--cc=dave.anglin@bell.net \
--cc=deller@gmx.de \
--cc=deller@kernel.org \
--cc=linux-parisc@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).