From: Rasmus Andersson <rasmus@notion.se>
To: Rich Felker <dalias@libc.org>
Cc: musl@lists.openwall.com
Subject: Re: [musl] waitpid (wait4) on Linux 5 returns invalid values
Date: Tue, 19 Jan 2021 14:00:14 -0800 [thread overview]
Message-ID: <CADFzTteA+ZzWfi7yLvm8Rcq_iKK7ya-efbMWT+ymbAEZNNWZ2Q@mail.gmail.com> (raw)
In-Reply-To: <20210119211653.GK23432@brightrain.aerifal.cx>
That was compiled using
https://more.musl.cc/10/x86_64-linux-musl/x86_64-linux-musl-native.tgz
on Alpine Linux in a docker container (alpine:3.12)
Full repro:
$ wget https://more.musl.cc/10/x86_64-linux-musl/x86_64-linux-musl-native.tgz
$ tar -xf x86_64-linux-musl-native.tgz
$ cat << EOF > a.c
#include <sys/wait.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main(int argc, char **argv) {
int wstat = 0;
pid_t child = waitpid(-1, &wstat, WNOHANG);
printf("waitpid returned %d, wstat=%d, errno=%d (%s)\n", child,
wstat, errno, strerror(errno));
return 0;
}
EOF
$ x86_64-linux-musl-native/bin/gcc -static a.c
$ ./a.out
waitpid returned -10, wstat=0, errno=0 (No error information)
On Tue, Jan 19, 2021 at 1:16 PM Rich Felker <dalias@libc.org> wrote:
>
> On Tue, Jan 19, 2021 at 12:35:26PM -0800, Rasmus Andersson wrote:
> > Relevant parts from disassembly: (objdump --disassemble --source
> > --line-numbers a.out)
> >
> > 0000000000401f61 <__syscall_cp_c>:
> > sccp():
> > 401f61: 48 89 f8 mov %rdi,%rax
> > 401f64: 4d 89 c2 mov %r8,%r10
> > 401f67: 48 89 f7 mov %rsi,%rdi
> > 401f6a: 4d 89 c8 mov %r9,%r8
> > 401f6d: 48 89 d6 mov %rdx,%rsi
> > 401f70: 4c 8b 4c 24 08 mov 0x8(%rsp),%r9
> > 401f75: 48 89 ca mov %rcx,%rdx
> > 401f78: 0f 05 syscall
> > 401f7a: c3 retq
> >
> > 0000000000401f7b <__syscall_cp>:
> > __syscall_cp():
> > 401f7b: e9 e1 ff ff ff jmpq 401f61 <__syscall_cp_c>
> >
> > 00000000004004fd <waitpid>:
> > waitpid():
> > ...
> > 40051a: e8 5c 1a 00 00 callq 401f7b <__syscall_cp>
> > 40051f: 48 83 c4 18 add $0x18,%rsp
> > 400523: c3 retq
>
> This disassembly shows a miscompiled (or compiled with wrong patches)
> waitpid. It should be a tail call to __syscall_ret, not a retq.
>
> Rich
next prev parent reply other threads:[~2021-01-19 22:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-19 18:18 Rasmus Andersson
2021-01-19 19:33 ` Markus Wichmann
2021-01-19 20:17 ` Rasmus Andersson
2021-01-19 20:28 ` Rasmus Andersson
2021-01-19 20:35 ` Rasmus Andersson
2021-01-19 20:56 ` Rasmus Andersson
2021-01-19 21:16 ` Rich Felker
2021-01-19 22:00 ` Rasmus Andersson [this message]
2021-01-19 22:02 ` Rasmus Andersson
2021-01-19 23:01 ` Zach van Rijn
2021-01-19 23:07 ` Rasmus Andersson
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=CADFzTteA+ZzWfi7yLvm8Rcq_iKK7ya-efbMWT+ymbAEZNNWZ2Q@mail.gmail.com \
--to=rasmus@notion.se \
--cc=dalias@libc.org \
--cc=musl@lists.openwall.com \
/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).