From: Ammar Faizi <ammarfaizi2@openresty.com>
To: "Willy Tarreau" <w@1wt.eu>, "Thomas Weißschuh" <linux@weissschuh.net>
Cc: Ammar Faizi <ammarfaizi2@openresty.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Linux Kselftest Mailing List <linux-kselftest@vger.kernel.org>,
LLVM Mailing List <llvm@lists.linux.dev>,
Yichun Zhang <yichun@openresty.com>,
Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>,
Shuah Khan <shuah@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
gwml@gnuweeb.org
Subject: [PATCH 0/4] nolibc: syscall() and abs() fixes, plus a cleanup
Date: Sun, 26 Jul 2026 17:13:01 +0700 [thread overview]
Message-ID: <20260726101306.3772237-1-ammarfaizi2@openresty.com> (raw)
Hi,
A small set of fixes and a cleanup. Tested on x86-64 and i386.
This contains:
- Evaluate syscall() arguments before they reach the arch macros. The
__nolibc_syscallN() macros drop their arguments into local register
variables, which GCC does not guarantee to survive a function call,
so an argument such as strlen(msg) clobbers the registers that were
already set up and the wrong syscall is made. Reproduced with gcc on
i386 and x86-64 at -O0, -O1, -O2, -O3 and -Os.
- Avoid signed overflow in abs(), labs() and llabs(): negate in the
corresponding unsigned type, so passing the type minimum no longer
invokes undefined behavior. The value is still not representable in
the result type, so the minimum is returned unchanged. Under the:
-fsanitize=undefined -fsanitize-trap=all
flags the selftests are built with, the old code did not merely
return an unspecified answer, it died with SIGILL (thrown by ud2).
- Add an abs() range test walking abs(), labs() and llabs() over the
interesting points of their argument type: the minimum, the minimum
plus one, an ordinary negative value, zero and the maximum.
- Remove the dead __ARCH_WANT_SYS_OLD_SELECT from arch-x86.h and
arch-arm.h. It lost its last user when select() was reimplemented on
top of pselect6 for every architecture.
Patches 1 and 2 are fixes. Patch 3 is the selftest that covers patch 2,
and patch 4 is a pure cleanup.
Signed-off-by: Ammar Faizi <ammarfaizi2@openresty.com>
---
Ammar Faizi (4):
tools/nolibc: evaluate syscall() arguments before the arch macros
tools/nolibc: stdlib: avoid signed overflow in abs() and friends
selftests/nolibc: add abs() range test
tools/nolibc: remove dead __ARCH_WANT_SYS_OLD_SELECT
tools/include/nolibc/arch-arm.h | 3 -
tools/include/nolibc/arch-x86.h | 3 -
tools/include/nolibc/stdlib.h | 12 +++-
tools/include/nolibc/sys/syscall.h | 72 +++++++++++++++++++-
tools/testing/selftests/nolibc/nolibc-test.c | 47 +++++++++++++
5 files changed, 127 insertions(+), 10 deletions(-)
base-commit: 070cf03f5ec454eec9c42827ee9f3c0b3fad09f1
--
Ammar Faizi
next reply other threads:[~2026-07-26 10:13 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-26 10:13 Ammar Faizi [this message]
2026-07-26 10:13 ` [PATCH 1/4] tools/nolibc: evaluate syscall() arguments before the arch macros Ammar Faizi
2026-07-26 20:16 ` Thomas Weißschuh
2026-07-27 1:21 ` Ammar Faizi
2026-07-27 3:42 ` Willy Tarreau
2026-07-28 6:53 ` Ammar Faizi
2026-07-27 3:30 ` Willy Tarreau
2026-07-27 16:18 ` Thomas Weißschuh
2026-07-28 6:51 ` Ammar Faizi
2026-07-26 10:13 ` [PATCH 2/4] tools/nolibc: stdlib: avoid signed overflow in abs() and friends Ammar Faizi
2026-07-26 14:13 ` David Laight
2026-07-26 16:01 ` Willy Tarreau
2026-07-27 7:32 ` David Laight
2026-07-27 16:15 ` Thomas Weißschuh
2026-07-28 8:46 ` David Laight
2026-07-28 16:31 ` Thomas Weißschuh
2026-07-28 16:37 ` Ammar Faizi
2026-07-26 10:13 ` [PATCH 3/4] selftests/nolibc: add abs() range test Ammar Faizi
2026-07-26 20:00 ` Thomas Weißschuh
2026-07-27 1:32 ` Ammar Faizi
2026-07-27 2:01 ` Ammar Faizi
2026-07-27 16:13 ` Thomas Weißschuh
2026-07-28 6:14 ` Ammar Faizi
2026-07-26 10:13 ` [PATCH 4/4] tools/nolibc: remove dead __ARCH_WANT_SYS_OLD_SELECT Ammar Faizi
2026-07-26 20:01 ` Thomas Weißschuh
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=20260726101306.3772237-1-ammarfaizi2@openresty.com \
--to=ammarfaizi2@openresty.com \
--cc=alviro.iskandar@gnuweeb.org \
--cc=gwml@gnuweeb.org \
--cc=justinstitt@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=shuah@kernel.org \
--cc=w@1wt.eu \
--cc=yichun@openresty.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®