From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C08F229B766 for ; Sun, 26 Jul 2026 10:13:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785060797; cv=none; b=mtJ+VXWuDkX+3OdCImJ+7BWTPfUN/zJ6G0ajx73YbI/hYrBiW+6A14JhipXXyMOo1xlVl9XBxgdoB9bdx7DSBmwIjMUMGedA78umWqTTyOVqSc6lAxWjjXoDEGy7ELCySOs464gNavuHVk6LavLhoWh49JAQPFCZrWhEgii0cP8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785060797; c=relaxed/simple; bh=hMbwhWX1Er1b+7H8vHCWQZO1kW/LGuAOr5+dXSIawrE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=fNU73U/6LizbMiliNqbzdaFv1hhqEhL53dpn6VNkBtu4WqL2iOyUhyM4rnOceLA3hmvnsZ9qESFIO9UEdwq6rWws7F8R2dsbCUxDIZGnMpmG7W0JVgjT52JCexxu7GMO2uLAjOM5i6a+TMKct8yc3SaiVKChRKR/CiIWtn7T5hA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=openresty.com; spf=pass smtp.mailfrom=openresty.com; dkim=pass (2048-bit key) header.d=openresty.com header.i=@openresty.com header.b=OL+JDjSg; arc=none smtp.client-ip=209.85.215.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=openresty.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=openresty.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=openresty.com header.i=@openresty.com header.b="OL+JDjSg" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-c999f162c9aso1287044a12.3 for ; Sun, 26 Jul 2026 03:13:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openresty.com; s=google; t=1785060795; x=1785665595; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=wcAzVpejed4McahzXYzgR83QcZ2K+/EUa6LpMYvOA98=; b=OL+JDjSg26XttoCCOfD8lvpEDrXaZw42Pk/KlVdalHZw1gKNORe/4PrQXvJLBl4bzH 9/LexX73DOcy1UTUc+b6EddzUdjZXlOc83Tykns/27nuasSN8IgCVn5xVzXoqVYVIVyf G6BQ2I+HRyXGpkPHaZ7oBtTC/ZW/ansxzsLhtDnQYdGFiLGgpcj1Q8WSGZFhasONeFxl V3W0tov6fC35YKb4hnPpaQNmydUY5gOF3Zb5B4s1nVXQJxe4ST4bFJuZ8JriEHn3xooA DEMbM08HILIth5jRKLs6ULDavLXfPt+VG+B4zDXtPBN7D3T6Nv3WpotkJR5OwrfFWZGD iVMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785060795; x=1785665595; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=wcAzVpejed4McahzXYzgR83QcZ2K+/EUa6LpMYvOA98=; b=N5NVOv/RIPUb1LuTSOT9j7AS/M2u07GMO06psXuyhYv3RPARRK4hkrsdfdNblyDZ6F XquySgUMsYbeCGIzRkG0O94ah1+Gdc3VSPYHclRqBT+lQYt4Qz8emH9z6J7DpXFSqERS QfK9AywaAz1mb1PYq2B7AlspRJkb3V8gXYsVUcmlvsWkggDp3S5mDuFtv8fqOfB9oZta I/J/lrGZI2rb8I1wbEyGwfvqlsh+fhYZy4DqLV6SH4Ai9Xco6yXkqP7hXT00HlFQXEZu IfNm4XSmdXfQDwFf1T1ELvsoWOwWL+EI2Z1fgaueeJq/U9IPfPCwizODCbim5DJuxehW 5MUw== X-Forwarded-Encrypted: i=1; AHgh+RrMWG/IFvaCtGJEZHHju8fFTOAhT4rV7fJ8+aPHbJoSv7G+2BF/sLNvRd10vPSw5egCYYb/XkrhQokbH3E=@vger.kernel.org X-Gm-Message-State: AOJu0Yzac8O23mxaOrsDqDPJAf41V452MEmEhqvb93SQgMDq2g27dk+4 BA82+i9DNLGz0BKAvhrkntA8O6A7uyPQAQSSxyvDi6PZMxWiO4dK7V24vLSMBAZtP5c= X-Gm-Gg: AR+sD122Dc+/YCApvyN0krJcpuJKqShdUyA1wUvVwduE46smY/2K4AyUC0waMvRffXm ELttH46j+/NuP4WccFNhP1ERRD53kSbzyFJrnpmbVIG9gWEVm8nTrh+jhK6K5rq5JdlTaTnV7Be +USzpzrylo2e+y5O1GbEpM6+OupzCzK87d05N9m8cVTB5l+P5g9RLSKHIlM2++SnrhTR/bG3LXH TIymH3qB03R1NmDzwhHYpiM3WNhR/s8Z0wArUlP+Q218G8Gk+HmsvbRmGQOS6cakMI1OufIEg1O MMx+TGOHk56PKuCtNTSbQ4J4WxDvlUsD1Nu2ULfaqgGssNBbw1480CKmeQ7CUGbJkxCjwrYeZSk r5ST80Za7BtaLUo1pM3GffaTA8rp3u9LGuZaR2d+dcJR5JPaLL3aEdUESMO7h1jmCkxR5otgVAN KGX7YSO6n+jKO7AQ== X-Received: by 2002:a05:6a21:394c:b0:3bf:d1f9:b1df with SMTP id adf61e73a8af0-3c67e0c9effmr4541605637.54.1785060795098; Sun, 26 Jul 2026 03:13:15 -0700 (PDT) Received: from integral2.. ([2402:8780:1329:2779:9db7:a8ec:2e1c:53e1]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-314bc59e9fesm17243981eec.27.2026.07.26.03.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jul 2026 03:13:14 -0700 (PDT) From: Ammar Faizi To: Willy Tarreau , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= 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@gnuweeb.org Subject: [PATCH 0/4] nolibc: syscall() and abs() fixes, plus a cleanup Date: Sun, 26 Jul 2026 17:13:01 +0700 Message-Id: <20260726101306.3772237-1-ammarfaizi2@openresty.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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