From nobody Sun Dec 14 12:18:02 2025 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D74223594F; Sat, 19 Apr 2025 10:46:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745059592; cv=none; b=PMxweFThwn95/3V7zfJpeYiaxVRFaEi0bBQgRsiM65AnLuZ7Qx/9sSz4InTLbwCZ12oTKB9GI+i1Gsh10rMxFCr+qlLsCK5IT/91ZOGg04B25Pv44P91jvfLthmwBuhUvMp0d5VoXfYHm+24X02GTwxYWhIG/2fEmRExwcXUYnc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745059592; c=relaxed/simple; bh=Fu/a9dHUfU/79QPTkLGEpbkvpxkUIMfawpy6A0iNqxY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Qf4ClpY11q6/lzfF8G/Nr6TGxlWrgPPC2kJ2BaetNrV4F9kzMF2nMKmk2bXIRSweEXU4Zb9fA+QuBqt6jZjRLcus2ucTcLCtoe7RWfRbcZEvu0eQJw04UuBBQEv7cqceVXU7HDz/MSZ+mWLJzNcK11sJGggfmTZLcrW4Wunsbu4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=B8D/hyRD; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="B8D/hyRD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1745059587; bh=Fu/a9dHUfU/79QPTkLGEpbkvpxkUIMfawpy6A0iNqxY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=B8D/hyRDOsOkP8ijENRJPFIbKNtaeiGbYOXpqY9mnBRDDgv6xDydXpFUXAjp1e3Ef 7M+/+X+BQurglBVGw44X0NEuWlkyE1RPLmEgJUwst8MwKguKWrmS0wcARtuLILIhBB BE0TJwq9RgkURvOTEfQXGS9IHX7BXkPhRBfR/bHM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 19 Apr 2025 12:46:18 +0200 Subject: [PATCH v2 1/7] tools/nolibc: add __nolibc_has_feature() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250419-nolibc-ubsan-v2-1-060b8a016917@weissschuh.net> References: <20250419-nolibc-ubsan-v2-0-060b8a016917@weissschuh.net> In-Reply-To: <20250419-nolibc-ubsan-v2-0-060b8a016917@weissschuh.net> To: Willy Tarreau , "Paul E. McKenney" , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1745059587; l=938; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=Fu/a9dHUfU/79QPTkLGEpbkvpxkUIMfawpy6A0iNqxY=; b=jZKxSVvJvzKwJPUpol2ww+N3g5hZzIzBox9BWKkrgbb2LCaxNULTCMMJrruB0yyZpsnwSRP1n nT9I9XG7QeYAtUbtRGHDttt+RIp1NFFaCuXiP5oX0qpnZE1pLZPkMOm X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Certain compiler features are signaled via the __has_feature() preprocessor builtin. Add a nolibc wrapper for it, similar to __nolibc_has_attribute(). Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/include/nolibc/compiler.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compile= r.h index fa1f547e7f13d151ea98b9c585b36659d2d27324..e6d6dc116e43aa69b37eca02ed1= 590fc09486bdb 100644 --- a/tools/include/nolibc/compiler.h +++ b/tools/include/nolibc/compiler.h @@ -12,6 +12,12 @@ # define __nolibc_has_attribute(attr) 0 #endif =20 +#if defined(__has_feature) +# define __nolibc_has_feature(feature) __has_feature(feature) +#else +# define __nolibc_has_feature(feature) 0 +#endif + #if __nolibc_has_attribute(naked) # define __nolibc_entrypoint __attribute__((naked)) # define __nolibc_entrypoint_epilogue() --=20 2.49.0 From nobody Sun Dec 14 12:18:02 2025 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 837721D86C3; Sat, 19 Apr 2025 10:46:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745059595; cv=none; b=ZvaX9gSfoTTkyw89tL32t6AUaqIGN5fEZepenN3LnyH6p287MzIAzmZ3ObNf5pq3NkgNROBO8DMdSnCkr7U9GwhrB7B3c3l1g0AeRyw8jKvDob8rQhTNkbL2C2JZ8F8siG0QC+jqR+N8uiCfaY4eDjN9T/io2MCAuK5QUUUaAVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745059595; c=relaxed/simple; bh=mzpKJohIpWJ0LYXtnz0PZYrkK4CRrKFVrVj+0vemp9Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Bsj0uvfFTRS5BpFtN/6Ccwroc38VDs98K/HIE7n22N6xXjHfLOS0xWcBf8qoVEAgIDEqCulH6XJlUJmPpmO5brj4EuxduDB+CbeOGptMhORT8byYe5Bi/R4fG5iHCqORZPz8dbX8MgBli1EOAJDRg76MRtMiUb2bBrz3JGtI2BY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=rot+lAyI; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="rot+lAyI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1745059587; bh=mzpKJohIpWJ0LYXtnz0PZYrkK4CRrKFVrVj+0vemp9Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rot+lAyIJ5Civijd5Lwq6WaRNXnCOIJ1iEB/R9HMWveoGgZSntm96AlWXBZYx5dz6 McFNr0ZPtFLeOYNCMIvwOBVanVl4PNc0qDGQgNqKMPh11KOO19yRwwT/nNSBurZsf2 RbCmU4RdyzOmlJQlSHG3/2BAUMlW+uFAo8k94/U8= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 19 Apr 2025 12:46:19 +0200 Subject: [PATCH v2 2/7] tools/nolibc: add __nolibc_aligned() and __nolibc_aligned_as() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250419-nolibc-ubsan-v2-2-060b8a016917@weissschuh.net> References: <20250419-nolibc-ubsan-v2-0-060b8a016917@weissschuh.net> In-Reply-To: <20250419-nolibc-ubsan-v2-0-060b8a016917@weissschuh.net> To: Willy Tarreau , "Paul E. McKenney" , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1745059587; l=965; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=mzpKJohIpWJ0LYXtnz0PZYrkK4CRrKFVrVj+0vemp9Y=; b=FoQtquPSOfm1I5LSk3s3uZi8s/EmZNA2cyf3eEwqL1Um5Ctp8jDeAPMJQkoaeiSzeaiqDxbcY 7bbFozcTM3QDHphUhxX7EbyWGscLpqVReL2tDGTf+QCRA0wR70Sq+ei X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Provide a convenience macro around __attribute__((aligned)). Signed-off-by: Thomas Wei=C3=9Fschuh --- Willy, I used the name __nolibc_align*ed* because it matches what the underlying attribute and the kernel macros are using. --- tools/include/nolibc/compiler.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compile= r.h index e6d6dc116e43aa69b37eca02ed1590fc09486bdb..369cfb5a0e78f4ae1e1a2cac407= 7024b4e8ba225 100644 --- a/tools/include/nolibc/compiler.h +++ b/tools/include/nolibc/compiler.h @@ -18,6 +18,9 @@ # define __nolibc_has_feature(feature) 0 #endif =20 +#define __nolibc_aligned(alignment) __attribute__((aligned(alignment))) +#define __nolibc_aligned_as(type) __nolibc_aligned(__alignof__(type)) + #if __nolibc_has_attribute(naked) # define __nolibc_entrypoint __attribute__((naked)) # define __nolibc_entrypoint_epilogue() --=20 2.49.0 From nobody Sun Dec 14 12:18:02 2025 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D38F11D8DE1; Sat, 19 Apr 2025 10:46:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745059595; cv=none; b=SjHQzYDffo76iBTvXCHnPaSLksjpcojh48JJsSI5h8L9vXuKAQwRx2hIfwUsznykSCbG+4Q1ZLVv1r93g/0cc/WOQKNa/fYUPlOK1kNBHXkZmkinwGsKCumF00JOqW9pD9zH4IcO9UFODlSfQGEvbkgn3ZRcVVHaiEb6BlD3TMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745059595; c=relaxed/simple; bh=K8/JOiUEC1Un4wIBEvmCV0tkDDsaFdfktVZkJJkwMeM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XwHxO26rSwqnPWlAMuACuZ0Hw+CjoW+cUkFtEkWNt2ccD0CmQssyF0r/km1UlIdrXWsSinaYo9VCYoOaQ2bS2XfyTdjzI/ucPkCCtHvGkVQSmlUa5SuMC5NbFSB93TqZ23QsjzcKgOf09tbWur51WZkd3wYrFF5peJ7X4mfwb8s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=M0G2VliO; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="M0G2VliO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1745059587; bh=K8/JOiUEC1Un4wIBEvmCV0tkDDsaFdfktVZkJJkwMeM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=M0G2VliO1G7GeNPK9FzVnk6DnOsWOcthInLImQkj/hBvPDy0OY767ou7JLfc3t8Ss 86Fijh4GjW3d7EFnQ5ngqH91X8XpLSteIH6Xfo306ZsUOlNaIbEdQ/VlCNPth/tEoJ FNcrK7KZil9me2ThcbUUV01gR/+lx3SXgm2rKpPw= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 19 Apr 2025 12:46:20 +0200 Subject: [PATCH v2 3/7] tools/nolibc: disable function sanitizer for _start_c() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250419-nolibc-ubsan-v2-3-060b8a016917@weissschuh.net> References: <20250419-nolibc-ubsan-v2-0-060b8a016917@weissschuh.net> In-Reply-To: <20250419-nolibc-ubsan-v2-0-060b8a016917@weissschuh.net> To: Willy Tarreau , "Paul E. McKenney" , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1745059587; l=1091; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=K8/JOiUEC1Un4wIBEvmCV0tkDDsaFdfktVZkJJkwMeM=; b=VZ9JP9/c/ljkA0CaiVksEheXdLEhdr81iwVlG69UOtGZ6pKU9/O3KzljWksjah1CYN3sJUStO EGEDh/QXBIwCxR0xuFZbcFd+eKESjRzEelzWbsXyB97/kvHNWZjD/Xx X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Both constructors and main() may be executed with different function signatures than they are actually using. This is intentional but trips up UBSAN. Disable the function sanitizer of UBSAN in _start_c(). Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/include/nolibc/crt.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h index c4b10103bbec50f1a3a0a4562e34fdbd1b43ce6f..961cfe777c3564e705dfdd581de= 828b374d05b0b 100644 --- a/tools/include/nolibc/crt.h +++ b/tools/include/nolibc/crt.h @@ -7,6 +7,8 @@ #ifndef _NOLIBC_CRT_H #define _NOLIBC_CRT_H =20 +#include "compiler.h" + char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); =20 @@ -25,6 +27,9 @@ extern void (*const __fini_array_end[])(void) __attribute= __((weak)); =20 void _start_c(long *sp); __attribute__((weak,used)) +#if __nolibc_has_feature(undefined_behavior_sanitizer) + __attribute__((no_sanitize("function"))) +#endif void _start_c(long *sp) { long argc; --=20 2.49.0 From nobody Sun Dec 14 12:18:02 2025 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0176C43AB7; Sat, 19 Apr 2025 10:46:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745059591; cv=none; b=hQan3nmk5C9OCCT63YUu7nV/WIOcjPXV77dE3XFL88bRZOfxgfnb7zKcmdcLJQ0+TNuS/h463mJmy1YTev8IXlLeBdxmvLb/iZ4yazdr1sHVBOLo25XML7vEKphlQUgYMjKWNYQ55CWOCY3rD3jsve7Q7p/UbTJbzXbA5Y7m9Z8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745059591; c=relaxed/simple; bh=2U/dcRwTExJtAZorNzJrHaFvZx2GCTS0zbAPO75QNGQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=k/XVKNdLyV8JoUq+TNhthfukEQ38QrPlo4Yp26JuHGkZYPay+X+PAj0omvy6kczT0OkQU3v4XZhmiBLwGNYaXupXpaA9Ox5jSs5HtboA3dMcWhXf9yqrOjD1kT5XQ5UjSbJt8xbAzoDcWGb+EWWTHyw/0aq6VR5g7Iun0/utQxE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=aGLfPhYR; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="aGLfPhYR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1745059587; bh=2U/dcRwTExJtAZorNzJrHaFvZx2GCTS0zbAPO75QNGQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=aGLfPhYRPFnc3C4nO72wONVUzSo3D5O/Qp20l2WjHs9okOO1VrPZ5NZkUHjlZgxaE +be7vAHwXNgegfqabI/ND5KnHk83wh7h6nLsHU4e+YHf7KIQdLhRevYhDcXy7Yub/k WhLgUBmLy0jlxCh2p79FBd+zUL8gAJCIkyAy33iI= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 19 Apr 2025 12:46:21 +0200 Subject: [PATCH v2 4/7] tools/nolibc: properly align dirent buffer Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250419-nolibc-ubsan-v2-4-060b8a016917@weissschuh.net> References: <20250419-nolibc-ubsan-v2-0-060b8a016917@weissschuh.net> In-Reply-To: <20250419-nolibc-ubsan-v2-0-060b8a016917@weissschuh.net> To: Willy Tarreau , "Paul E. McKenney" , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1745059587; l=1186; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=2U/dcRwTExJtAZorNzJrHaFvZx2GCTS0zbAPO75QNGQ=; b=LLSwzT4aqCw37xqmYBxyy4xERUH85Gl5SniRsgsU0Mlm2FsCKfHCT/jBMJLPPhj6oJ1toBgGK FSxV8IStHgHBO+UQTItXv0/rB/8zXuHrhD6NBDKE/If2zPasikIBfnb X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= As byte buffer is overlaid with a 'struct dirent64'. it has to satisfy the structs alignment requirements. Fixes: 665fa8dea90d ("tools/nolibc: add support for directory access") Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by: Willy Tarreau --- tools/include/nolibc/dirent.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/include/nolibc/dirent.h b/tools/include/nolibc/dirent.h index c5c30d0dd6806b1bec2fa8120a3df29aaa201393..946a697e98e4c7bb0970b163ffd= fe0e069b1d160 100644 --- a/tools/include/nolibc/dirent.h +++ b/tools/include/nolibc/dirent.h @@ -7,6 +7,7 @@ #ifndef _NOLIBC_DIRENT_H #define _NOLIBC_DIRENT_H =20 +#include "compiler.h" #include "stdint.h" #include "types.h" =20 @@ -58,7 +59,7 @@ int closedir(DIR *dirp) static __attribute__((unused)) int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) { - char buf[sizeof(struct linux_dirent64) + NAME_MAX + 1]; + char buf[sizeof(struct linux_dirent64) + NAME_MAX + 1] __nolibc_aligned_a= s(struct linux_dirent64); struct linux_dirent64 *ldir =3D (void *)buf; intptr_t i =3D (intptr_t)dirp; int fd, ret; --=20 2.49.0 From nobody Sun Dec 14 12:18:02 2025 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C88454654; Sat, 19 Apr 2025 10:46:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745059593; cv=none; b=SoC6bNh4Q4RRakqiYzM07v3obv5HeQJlGigi25B1aUtCtIun9KAn6kgry2hqDHWdkoigDzSjiJBnxI0qR3useNYOV/dbRT5/45zRbLssTM8pnEFoM9qfYR9fPf2QHchwC1lXPcxVyymfs7uQTzuCzr1TPl8WhHaPIPF6813rz9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745059593; c=relaxed/simple; bh=rIGG2avDYewQyNpFGCRyAH1BFtTaIBDk0rn7Rm/dLos=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dFJro3lnFGcMZwDRDJbsCeO7v/BKeFSxAB0D09xd03AMfZUq78zxwuXEdR1U7BbpjLdkX3+0l4lJjjuYrjGntVfZR+sCRjezk6ncdS7WaJM2vi/P5iptyLcOlEnGuzZJjnlsesj/mzu+lO946oERjMqFUZnO7BSe9eUGGXicxcQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=A8w+UOkN; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="A8w+UOkN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1745059588; bh=rIGG2avDYewQyNpFGCRyAH1BFtTaIBDk0rn7Rm/dLos=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=A8w+UOkNu7gCcfcEt4vSylXiYQmDdHbl7m4dGjBGqEavophuUD4cPc18j271eyf1A mUn4iVviH6miaJSLM76MRB/HhE0G7qD7cAApfdzUmDQNSXdcQRVNuWZdTDnFimYToE SF+od9yPZfD1nDjshEpyIQ0YZ0guYIc9mGoV3c6k= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 19 Apr 2025 12:46:22 +0200 Subject: [PATCH v2 5/7] tools/nolibc: fix integer overflow in i{64,}toa_r() and Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250419-nolibc-ubsan-v2-5-060b8a016917@weissschuh.net> References: <20250419-nolibc-ubsan-v2-0-060b8a016917@weissschuh.net> In-Reply-To: <20250419-nolibc-ubsan-v2-0-060b8a016917@weissschuh.net> To: Willy Tarreau , "Paul E. McKenney" , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1745059587; l=995; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=rIGG2avDYewQyNpFGCRyAH1BFtTaIBDk0rn7Rm/dLos=; b=NWlPgVZMFUZIo1HfbezTXZNzFRbXco3HXj7B2A3pv9V2VslYbDVKSwJ5sON3S0Rs03zCveuL1 rAwvEJezQpHB0jCh4Hbb0sJlRtbWmbogo4Ommpj0oDYf36PNZXrxie4 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= In twos complement the most negative number can not be negated. Fixes: b1c21e7d99cd ("tools/nolibc/stdlib: add i64toa() and u64toa()") Fixes: 66c397c4d2e1 ("tools/nolibc/stdlib: replace the ltoa() function with= more efficient ones") Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/include/nolibc/stdlib.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h index 86ad378ab1ea220559d5ab1adc4bb9972977ba9e..32b3038002c16864cf66a71ae9f= a3825f995b09c 100644 --- a/tools/include/nolibc/stdlib.h +++ b/tools/include/nolibc/stdlib.h @@ -275,7 +275,7 @@ int itoa_r(long in, char *buffer) int len =3D 0; =20 if (in < 0) { - in =3D -in; + in =3D -(unsigned long)in; *(ptr++) =3D '-'; len++; } @@ -411,7 +411,7 @@ int i64toa_r(int64_t in, char *buffer) int len =3D 0; =20 if (in < 0) { - in =3D -in; + in =3D -(uint64_t)in; *(ptr++) =3D '-'; len++; } --=20 2.49.0 From nobody Sun Dec 14 12:18:02 2025 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73CAF6F305; Sat, 19 Apr 2025 10:46:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745059592; cv=none; b=Tym0/fno7q1P3e+J9kF6kARRo0bSGEsmbH+HQHfBztE5pwy80+xR+CiMNPLb9SNFRC+oWctyfY7hdCoI1fVeZ8phRHxn+Mrv9ETZfV/zOK9O3lHQWLQXPmc5AmWPE+4ymFSnhWLomnyNz54FfEcaz1vATVi+b9lVSIJnj+R8Iac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745059592; c=relaxed/simple; bh=KobCUeJS2OEM5lPwozYg0JTzSnTraZcO9O3oDYtCUhI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aR/CeOgzVQ+xQamhZChn8Ysf237C00e+MFOH9oHDkPqTtaC846TTplRMsQzSMf+tLWu2jk6OLgFe3oWmnhFKaMT6V6OJ3j+wHbGnpDr1I3ZT5hDpaOUqo2nb0/XNNjqZDAESuvDPbFtP/7SVcZDxTBA2QbdlpCVnZj6V1qdt6uY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=rBTkcQHb; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="rBTkcQHb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1745059588; bh=KobCUeJS2OEM5lPwozYg0JTzSnTraZcO9O3oDYtCUhI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rBTkcQHb8lkVzHhG9XDJRHGDK4+0Q7wUdSUzRvO+/WWD2Pk/XtnkYWDri6SoSlyIt /uV8K4IMyrLTxvwSt6ZMLdan7sFebHwnLdxbuWiEm2XrDfmqcBokuG1MspyL77oNGm MeSrGa/09fX8ei82TJURoX7wzLn9UAgTv8s4PV/4= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 19 Apr 2025 12:46:23 +0200 Subject: [PATCH v2 6/7] selftests/nolibc: disable ubsan for smash_stack() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250419-nolibc-ubsan-v2-6-060b8a016917@weissschuh.net> References: <20250419-nolibc-ubsan-v2-0-060b8a016917@weissschuh.net> In-Reply-To: <20250419-nolibc-ubsan-v2-0-060b8a016917@weissschuh.net> To: Willy Tarreau , "Paul E. McKenney" , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1745059587; l=736; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=KobCUeJS2OEM5lPwozYg0JTzSnTraZcO9O3oDYtCUhI=; b=aTcG+XP2wsZflP4N2plzIKE1ncwCU+vNw2Ru1zEyu3v9UOkFjJ3uWddAb+bhWm5LKc2+40T4N X5Hz/NPuZT/AOChjxHY7B4WDDPLDKT2MAWzkHqsy86AR9FZGeYB1hX9 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= smash_stack() intentionally crashes. Prevent UBSAN from tripping over it. Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/testing/selftests/nolibc/nolibc-test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 7a60b6ac1457e8d862ab1a6a26c9e46abec92111..b176a706609b7641dd1d743c8a0= 2b6b6e7a4c746 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1438,6 +1438,7 @@ static int run_vfprintf(int min, int max) return ret; } =20 +__attribute__((no_sanitize("undefined"))) static int smash_stack(void) { char buf[100]; --=20 2.49.0 From nobody Sun Dec 14 12:18:02 2025 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E1BF1D7999; Sat, 19 Apr 2025 10:46:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745059595; cv=none; b=cU3jozcOfWUYUUs30pGGxcRJDG1JrQpKp0erm85Q1KeHqHh7yH7DM5ojKHlgFCOGOukbQOK+TGrCfB17SfKAA1jBrOTRMfAx3+VLzjRX5tuFCZukk2cUoR1Lf/gbi/7dgwV2i7TFlhi7fJN1h0IZbgGHhAg0aH9ceKbP4QN74dA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745059595; c=relaxed/simple; bh=PDaLLP/sYgP08Fp3qi+j7XEW/p3gaSCx0iAVLrHvJUk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KClBwbeVscr+oHIwDP4FTEuTMdLk2OO3StzzFpQ35ihlfyXP7kfYvAwQoWCBv3oyryjcoUKSvKjCH3/DacDZL9a+6j58WRhMuwEez/rfZFLIcHOxVSMvLh/oUFGK07RvMCD5OGpz5Ug+EEkLgMrHEr0GC85sB9Pqq15jehUzuhA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=d+mdfVrh; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="d+mdfVrh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1745059588; bh=PDaLLP/sYgP08Fp3qi+j7XEW/p3gaSCx0iAVLrHvJUk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=d+mdfVrhTzKYz2vjWCrw75JXcNny08XnWlGveh3FzK+WWeXWKOfS8wh/JCwvLa6vi N/mNlNr2dI6/vuZPdA/wasNk+h6CJRSR/cKDz3cHTjTf8BeZyQVTJKe1u0VGm8OHzq MeSC5YumUusdKoJSKkPWof8Eg3g3WeKwn8fagaOY= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 19 Apr 2025 12:46:24 +0200 Subject: [PATCH v2 7/7] selftests/nolibc: enable UBSAN if available Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250419-nolibc-ubsan-v2-7-060b8a016917@weissschuh.net> References: <20250419-nolibc-ubsan-v2-0-060b8a016917@weissschuh.net> In-Reply-To: <20250419-nolibc-ubsan-v2-0-060b8a016917@weissschuh.net> To: Willy Tarreau , "Paul E. McKenney" , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1745059587; l=1345; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=PDaLLP/sYgP08Fp3qi+j7XEW/p3gaSCx0iAVLrHvJUk=; b=VrOAFef5uSOfNGE+TQ9t/522pEObkrLOAr8L8V7NEGY3EslnUabvmn4udQSryDa21is4soX+2 JEj9D26uYkHCKvVTw7G1+KA+XAPbwy0T0jb/WF0Rs554ZqJtU51pZ6d X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= UBSAN detects undefined behaviour at runtime. To avoid introduction of new UB, enable UBSAN for nolibc-test. By signalling detected errors through traps no runtime dependency is necessary. Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by: Willy Tarreau --- tools/testing/selftests/nolibc/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selfte= sts/nolibc/Makefile index aa05c1faac20d3054b231090b939d050b0231d40..94f3e8be7a68f63ecd639c4f283= b3cd10764ce74 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -189,9 +189,10 @@ ifeq ($(origin XARCH),command line) CFLAGS_XARCH =3D $(CFLAGS_$(XARCH)) endif CFLAGS_STACKPROTECTOR ?=3D $(call cc-option,-mstack-protector-guard=3Dglob= al $(call cc-option,-fstack-protector-all)) +CFLAGS_SANITIZER ?=3D $(call cc-option,-fsanitize=3Dundefined -fsanitize-t= rap=3Dall) CFLAGS ?=3D -Os -fno-ident -fno-asynchronous-unwind-tables -std=3Dc89 -W = -Wall -Wextra \ $(call cc-option,-fno-stack-protector) $(call cc-option,-Wmissing-protot= ypes) \ - $(CFLAGS_XARCH) $(CFLAGS_STACKPROTECTOR) $(CFLAGS_EXTRA) + $(CFLAGS_XARCH) $(CFLAGS_STACKPROTECTOR) $(CFLAGS_SANITIZER) $(CFLAGS_EX= TRA) LDFLAGS :=3D =20 LIBGCC :=3D -lgcc --=20 2.49.0