From: Peter Korsgaard <peter@korsgaard.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH] package/libseccomp: circumvent uClibc-ng bug on x86_64
Date: Wed, 30 Oct 2019 10:17:52 +0100 [thread overview]
Message-ID: <874kzq4mnz.fsf@dell.be.48ers.dk> (raw)
In-Reply-To: <20191019011525.10572-1-unixmania@gmail.com> (unixmania's message of "Fri, 18 Oct 2019 22:15:25 -0300")
>>>>> "unixmania" == unixmania <unixmania@gmail.com> writes:
> From: Carlos Santos <unixmania@gmail.com>
> On uClibc up to v1.0.31, syscall() for x86_64 is defined in
> libc/sysdeps/linux/x86_64/syscall.S as
> syscall:
> movq %rdi, %rax /* Syscall number -> rax. */
> movq %rsi, %rdi /* shift arg1 - arg5. */
> movq %rdx, %rsi
> movq %rcx, %rdx
> movq %r8, %r10
> movq %r9, %r8
> movq 8(%rsp),%r9 /* arg6 is on the stack. */
> syscall /* Do the system call. */
> cmpq $-4095, %rax /* Check %rax for error. */
> jae __syscall_error /* Branch forward if it failed. */
> ret /* Return to caller. */
> And __syscall_error is defined in
> libc/sysdeps/linux/x86_64/__syscall_error.c as
> int __syscall_error(void) attribute_hidden;
> int __syscall_error(void)
> {
> register int err_no __asm__ ("%rcx");
> __asm__ ("mov %rax, %rcx\n\t"
> "neg %rcx");
> __set_errno(err_no);
> return -1;
> }
> Notice that __syscall_error returns -1 as a 32-bit int in %rax, a 64-bit
> register i.e. 0x00000000ffffffff (decimal 4294967295). When this value
> is compared to -1 in _sys_chk_seccomp_flag_kernel() the result is false,
> leading the function to always return 0.
> Prevent the error by coercing the return value of syscall() to int in a
> temporary variable before comparing it to -1. We could use just an (int)
> cast but the variable makes the code more readable and the machine code
> generated by the compiler is the same in both cases.
> All other syscall() invocations were inspected and they either already
> coerce the result to int or do not compare it to -1.
> The same problem probably occurs on other 64-bit systems but so far only
> x86_64 was tested.
> A bug report is being submitted to uClibc.
> Upstream status: https://github.com/seccomp/libseccomp/pull/175
> Signed-off-by: Carlos Santos <unixmania@gmail.com>
Committed to 2019.02.x and 2019.08.x, thanks.
--
Bye, Peter Korsgaard
next prev parent reply other threads:[~2019-10-30 9:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-19 1:15 [Buildroot] [PATCH] package/libseccomp: circumvent uClibc-ng bug on x86_64 unixmania at gmail.com
2019-10-30 9:17 ` Peter Korsgaard [this message]
-- strict thread matches above, loose matches on Subject: below --
2019-10-19 1:15 unixmania at gmail.com
2019-10-19 12:17 ` Thomas Petazzoni
2019-10-19 13:01 ` Carlos Santos
2019-10-19 13:23 ` Thomas Petazzoni
2019-10-19 13:53 ` Carlos Santos
2019-10-19 19:34 ` Arnout Vandecappelle
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=874kzq4mnz.fsf@dell.be.48ers.dk \
--to=peter@korsgaard.com \
--cc=buildroot@busybox.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox