Skip to content

nolibc: syscall() and abs() fixes, plus a cleanup

Ammar Faizi linux-kselftest lkml llvm 1 version Applied

Status from this message: Thanks, applied.

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 20 repliesApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/4tools/nolibc: evaluate syscall() arguments before the arch macrostools/include/nolibc/sys/syscall.h+71 -17 replies
2/4tools/nolibc: stdlib: avoid signed overflow in abs() and friendstools/include/nolibc/stdlib.h+9 -37 replies
3/4selftests/nolibc: add abs() range testtools/testing/selftests/nolibc/nolibc-test.c+47 -05 replies
4/4tools/nolibc: remove dead __ARCH_WANT_SYS_OLD_SELECTtools/include/nolibc/arch-arm.h tools/include/nolibc/arch-x86.h+0 -61 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/4] nolibc: syscall() and abs() fixes, plus a cleanup

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.

---

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

Signature · 1 line
Ammar Faizi