From: felix.winkelmann@bevuta.com
To: musl@lists.openwall.com
Cc: peter@more-magic.net
Subject: possible bug in setjmp implementation for ppc64
Date: Mon, 31 Jul 2017 22:06:51 +0200 [thread overview]
Message-ID: <1501520360.0.593167188853569@go.bunnymail.go> (raw)
Hi!
I think I may have come across a bug in musl on PPC64(le), and the folks
on the #musl IRC channel directed me here. I'm not totally sure whether
the problem is caused by a my misunderstanding of C library functions or whether
it is a plain bug in the musl implementation of setjmp(3).
In out project[1] we use setjmp to establish a global trampoline
and allocate small objects on the stack using alloca (see [2] for
more information about the compiliation strategy used). I was able to reduce
the code that crashes to the following:
---
#include <stdio.h>
#include <alloca.h>
#include <setjmp.h>
#include <string.h>
#include <stdlib.h>
jmp_buf jb;
int foo = 99;
int c = 0;
void bar()
{
c++;
longjmp(jb, 1);
}
int main()
{
setjmp(jb);
char *p = alloca(256);
memset(p, 0, 256);
printf("%d\n", foo);
if(c < 10) bar();
exit(0);
}
---
When executing the longjmp, the code that restores $r2 (TOC) after the call
to setjmp reads invalid data, because the memset apparently clobbered
the stack frame - i.e. the pointer returned be alloca points into a part
of the stack frame that is still in use.
I tried this on arm, x86_64 and ppc64 with glibc and it seems to work fine,
but crashes when linked with musl (running Alpine Linux on a VM)
If you need more information, please feel free to ask. You can also keep
me CC'd, since I'd be interested in knowing more about the details.
felix
[1] http://www.call-cc.org
[2] http://home.pipeline.com/~hbaker1/CheneyMTA.html
next reply other threads:[~2017-07-31 20:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-31 20:06 felix.winkelmann [this message]
2017-07-31 20:30 ` Rich Felker
2017-08-01 5:10 ` Bobby Bingham
2017-08-01 5:28 ` Alexander Monakov
2017-08-01 22:45 ` Rich Felker
2017-08-01 23:07 ` Rich Felker
2017-08-02 0:28 ` Bobby Bingham
2017-08-02 3:55 ` Rich Felker
2017-08-02 4:31 ` Bobby Bingham
2017-08-02 4:58 ` Rich Felker
2017-08-02 13:38 ` Bobby Bingham
2017-08-02 14:46 ` Rich Felker
2017-08-03 0:19 ` Bobby Bingham
2017-08-01 15:33 ` David Edelsohn
2017-08-02 23:00 ` Alexander Monakov
2017-08-02 23:02 ` Rich Felker
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=1501520360.0.593167188853569@go.bunnymail.go \
--to=felix.winkelmann@bevuta.com \
--cc=musl@lists.openwall.com \
--cc=peter@more-magic.net \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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).