All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] nolibc: syscall() and abs() fixes, plus a cleanup
@ 2026-07-26 10:13 Ammar Faizi
  2026-07-26 10:13 ` [PATCH 1/4] tools/nolibc: evaluate syscall() arguments before the arch macros Ammar Faizi
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Ammar Faizi @ 2026-07-26 10:13 UTC (permalink / raw)
  To: Willy Tarreau, Thomas Weißschuh
  Cc: Ammar Faizi, Linux Kernel Mailing List,
	Linux Kselftest Mailing List, LLVM Mailing List, Yichun Zhang,
	Alviro Iskandar Setiawan, Shuah Khan, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, gwml

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


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-07-26 20:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-26 10:13 [PATCH 0/4] nolibc: syscall() and abs() fixes, plus a cleanup Ammar Faizi
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-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-26 10:13 ` [PATCH 3/4] selftests/nolibc: add abs() range test Ammar Faizi
2026-07-26 20:00   ` Thomas Weißschuh
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.