From patchwork Wed Apr 16 18:40:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 14054415 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 A3087223704; Wed, 16 Apr 2025 18:40:45 +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=1744828848; cv=none; b=t2abLh5O8DwhbNNJ/Pdzr02y5EloUQ7C4RU7B/oaqZzelPnHh+1lpbr6CY/NEX5UnLu9UvMoCczaCjcCTS5I35+AThAke+caCPaxzrB1lmofIP88vuoCptBkIxH1UOSX3hXjiDOWZ9rKPSiGBJRxbrFVV2Zu+lFrZ1/2Jn+AO4M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744828848; c=relaxed/simple; bh=Fu/a9dHUfU/79QPTkLGEpbkvpxkUIMfawpy6A0iNqxY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ri0vuGsKPorUovgKXPhuPk5u3gfcQL+ANfzdeAeZXsEaoWW1ESBJxvD8uxMrM0AA/zuc2P9Y/Crz5YhGy51IPENKbxfoxwucdG3rH3OxYA7eMe53Fo06FLLHiKmKcw+EEphnAYejPhh56sbZHQl9ysZLVufRtVnn87VyOUcl0gU= 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=ifJSGP5X; 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="ifJSGP5X" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1744828842; bh=Fu/a9dHUfU/79QPTkLGEpbkvpxkUIMfawpy6A0iNqxY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ifJSGP5X5Xbm/AliTmtM6wjYYntUKSAsiTdMiSNv+lZVOZWii9TLOGiNbcBJA+Yfr 8zFxAu/hEMTSxj0H5nqKcdCVvumfgE23L2bu9Yydzu0K6EIQTiNnQDvogivL3z4+s3 i5QoUL2YF4tkB4DlpPSyJnyJDrOdgSaMjkKdNLGI= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 16 Apr 2025 20:40:16 +0200 Subject: [PATCH 1/6] tools/nolibc: add __nolibc_has_feature() Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250416-nolibc-ubsan-v1-1-c4704bb23da7@weissschuh.net> References: <20250416-nolibc-ubsan-v1-0-c4704bb23da7@weissschuh.net> In-Reply-To: <20250416-nolibc-ubsan-v1-0-c4704bb23da7@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=1744828842; l=938; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=Fu/a9dHUfU/79QPTkLGEpbkvpxkUIMfawpy6A0iNqxY=; b=6mD9EMxPbYU6B9IHPYXEzi0/duHTLc5UtlrDufYHs+4MgVdRWdOxGC9PGbscrA4KssHl6gUML pCdzAEiW9X+DevEZ+8lBNl6Zpp0LoiY5POuuuT7NFDaAJbkju4bM1zb 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ßschuh --- tools/include/nolibc/compiler.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compiler.h index fa1f547e7f13d151ea98b9c585b36659d2d27324..e6d6dc116e43aa69b37eca02ed1590fc09486bdb 100644 --- a/tools/include/nolibc/compiler.h +++ b/tools/include/nolibc/compiler.h @@ -12,6 +12,12 @@ # define __nolibc_has_attribute(attr) 0 #endif +#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() From patchwork Wed Apr 16 18:40:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 14054413 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 5428A217730; Wed, 16 Apr 2025 18:40:45 +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=1744828848; cv=none; b=TH09djL1if72jmSH7aWhYw3bsUt0F4vavYxRa15EuQXT6NNjlE1AE6IBqa3adZu3oXZxMj2RG6iLfXTVUXQPTA+3jlpErI/VyMx1OWPOvtM2x2S6dRqOp7xvjCspcayx/SQXr98+sJGzmJNB6xsPJCfUHwpA6POnwKBMvBqjf2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744828848; c=relaxed/simple; bh=K8/JOiUEC1Un4wIBEvmCV0tkDDsaFdfktVZkJJkwMeM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iqmVl7A532dRkQLqLR1qegOs5wwEVQY2qQPOLtPWL5GysVNsbGQJkRlJpc5uheaOUK4p6TO8logQWovMsqgfXKoTzncx7lkimpp8TPHWyszlauNAixQniqIPqekbiwKo/tDta6Q48XNemnIjI4rEJDBgHbdIUZ5FM+vzb0vprek= 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=rfqPuIb0; 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="rfqPuIb0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1744828842; bh=K8/JOiUEC1Un4wIBEvmCV0tkDDsaFdfktVZkJJkwMeM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rfqPuIb0D4yU+wUtObsycCZDc9iIX797EolB6/TGWPNIJI1X9uMkDbzO+mu9Sf+7o 2CkfkcBtTxFnIS6TVCJQKG8Rr+6xqTXGZceZ7+H4Xv7p14/mLFb0/DOFYUL4yypSvb b9Nvkf/jt8/6QAWBP1wcWJ1UJePIZcHSqtoGA+AE= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 16 Apr 2025 20:40:17 +0200 Subject: [PATCH 2/6] tools/nolibc: disable function sanitizer for _start_c() Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250416-nolibc-ubsan-v1-2-c4704bb23da7@weissschuh.net> References: <20250416-nolibc-ubsan-v1-0-c4704bb23da7@weissschuh.net> In-Reply-To: <20250416-nolibc-ubsan-v1-0-c4704bb23da7@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=1744828842; l=1091; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=K8/JOiUEC1Un4wIBEvmCV0tkDDsaFdfktVZkJJkwMeM=; b=QQ2N2cTjuYwo64KAWqUYjrhMZS4I5cCA2+yNoDM31oFpHsCL0OJGFdaU5QFFiCCHVG1zoPv6m +M3tYhlBO0kDo77cnZ+czLaxufKfkTB+30XbNpVAlXReYzNZdUJrPW0 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ßschuh --- 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..961cfe777c3564e705dfdd581de828b374d05b0b 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 +#include "compiler.h" + char **environ __attribute__((weak)); const unsigned long *_auxv __attribute__((weak)); @@ -25,6 +27,9 @@ extern void (*const __fini_array_end[])(void) __attribute__((weak)); 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; From patchwork Wed Apr 16 18:40:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 14054414 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 A30E922423B; Wed, 16 Apr 2025 18:40:45 +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=1744828848; cv=none; b=Ddhd3mqxpHpXzJtD6JXiMn7gUup7TKJFyMCJb6g0qDrjEsBlaquruUC7bXGvu3hWD0+CJCyoL5MH/OuNI8jlm01TTomf1C9uhr7X+bNMCeTywrTw1N7mzGmHduGtkee6jRO6VUMPkUWA3VCXgK6IPkcdaWMYbHb9w1jZgPRSYqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744828848; c=relaxed/simple; bh=umVrEBGRj3bl+YVGjKRcJZOWpy3k480FdxVtwmyb2hw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tZdQGxqe1l0Spx3xxWDS8mD2tVTFggD/Dymhye37Hp0wQ7jM3F7zx31hpYjBY6fcyAXAfxCNKcB6Tg0TK3TeNnAuIoV9MMLvd8MTfEwD3qk/yNPk9TTNi7QAtpFrdCk8Ig0KDfnXL8zrJJlpsMlXVwVWFxEr1hzAdilfYlnZqqI= 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=RCSFiGSb; 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="RCSFiGSb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1744828843; bh=umVrEBGRj3bl+YVGjKRcJZOWpy3k480FdxVtwmyb2hw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RCSFiGSbJNYSLG3TxRHz6zwC1nVYkgdEcPDMdyvypV5waQC/RdDCNIqYZbBDOw6+i igglaxpIetgvkR2q2s/sLhXSwKegoNSLn4s2QOILM7DJUy+ky8SFXJ0dZRZBDWDrXM ChpeAm/9F8ru+DQVYZd/x2G2h9yGaFiAs+XYOz5w= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 16 Apr 2025 20:40:18 +0200 Subject: [PATCH 3/6] tools/nolibc: properly align dirent buffer Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250416-nolibc-ubsan-v1-3-c4704bb23da7@weissschuh.net> References: <20250416-nolibc-ubsan-v1-0-c4704bb23da7@weissschuh.net> In-Reply-To: <20250416-nolibc-ubsan-v1-0-c4704bb23da7@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=1744828842; l=934; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=umVrEBGRj3bl+YVGjKRcJZOWpy3k480FdxVtwmyb2hw=; b=ud/DqkVbfaY7SS7KVrfrdctaxRwKYJTWo+NBW9KWzJwf8p8VnzvEnICYp6FmU2c6+Tx80xco0 oiUqr3VM+IjBauXHGu7hTqGat9mJ4WIiDuNP4ThCC9R2PZp8hw6DVCT 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ßschuh --- tools/include/nolibc/dirent.h | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/include/nolibc/dirent.h b/tools/include/nolibc/dirent.h index c5c30d0dd6806b1bec2fa8120a3df29aaa201393..cd0ddff86c360b14913a809c8696d89d8a356e9e 100644 --- a/tools/include/nolibc/dirent.h +++ b/tools/include/nolibc/dirent.h @@ -58,6 +58,7 @@ int closedir(DIR *dirp) static __attribute__((unused)) int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) { + __attribute__((aligned(__alignof__(struct linux_dirent64)))) char buf[sizeof(struct linux_dirent64) + NAME_MAX + 1]; struct linux_dirent64 *ldir = (void *)buf; intptr_t i = (intptr_t)dirp; From patchwork Wed Apr 16 18:40:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 14054412 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 7035F22423A; Wed, 16 Apr 2025 18:40:45 +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=1744828848; cv=none; b=lHtuRt5Y59HbNySAzi8NWldvt28VrDMW+Yyn7+pk4Ebfmkddqa9e947PjFA1bsWqEJYgKW7tfOqGXcWNn5oDwprSYG+IO/7avZGYmo846M3AQblAcqQiWJh7wsg4zEu2FplEkLFfuPYuu7O+5/QALPwjH40vD1qaZivVfaaEnqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744828848; c=relaxed/simple; bh=jCc+HBe7/ZchbeIAcJPoVoIp6kCZq4gasvGUQMeonFo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hE/nzmGfMqD/wktJCFnUUqHcEuRPrw0g2VEwZw11bM1QQz7p3RVjmMJ5qQvlImS5LM2mf8iu7YpoUwBrFgUi9bH+753otHRaA06p5VVyKkD7+iQgMMkTLyeg9zAfukBVjW815Vrryu0PeVFv1AT92z43yywo0/fXxd8zcpniUSY= 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=qLb/MG4x; 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="qLb/MG4x" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1744828843; bh=jCc+HBe7/ZchbeIAcJPoVoIp6kCZq4gasvGUQMeonFo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qLb/MG4xSlWLpaqStOv5OH1xID7I12d9e2QQ1wBstfkJu9NUd+56WJPpuzk889cSG cO8gWaaIO/PIDOenTdmWi5DRujl8uG7Zw5x9+Z7UjDaTptu1VaReaF82oubRReEoJW QP5zrUs9/JHcR6DXPNjg9M2nfaTeaO+q3PofTu4Y= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 16 Apr 2025 20:40:19 +0200 Subject: [PATCH 4/6] tools/nolibc: fix integer overflow in i{64,}toa_r() and Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250416-nolibc-ubsan-v1-4-c4704bb23da7@weissschuh.net> References: <20250416-nolibc-ubsan-v1-0-c4704bb23da7@weissschuh.net> In-Reply-To: <20250416-nolibc-ubsan-v1-0-c4704bb23da7@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=1744828842; l=1658; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=jCc+HBe7/ZchbeIAcJPoVoIp6kCZq4gasvGUQMeonFo=; b=vd5RjBCHBQeCQH/O11mY77OCtqzNfHeAo+Netyu+qcXMeWelNtMNavSp6J9ZEe1X/k36LJHkF udmCZVxDT3fA640MqAYh/Qw3C19TXVTH4TDLCh2P4VkBRm8jLjDmGMW 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ßschuh --- tools/include/nolibc/stdlib.h | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h index 86ad378ab1ea220559d5ab1adc4bb9972977ba9e..5e4b97810d49ac1b1bd79d6f779f6a748f188a39 100644 --- a/tools/include/nolibc/stdlib.h +++ b/tools/include/nolibc/stdlib.h @@ -271,16 +271,12 @@ int utoa_r(unsigned long in, char *buffer) static __attribute__((unused)) int itoa_r(long in, char *buffer) { - char *ptr = buffer; - int len = 0; - if (in < 0) { - in = -in; - *(ptr++) = '-'; - len++; + *(buffer++) = '-'; + return 1 + utoa_r(-(unsigned long)in, buffer); } - len += utoa_r(in, ptr); - return len; + + return utoa_r(in, buffer); } /* for historical compatibility, same as above but returns the pointer to the @@ -407,16 +403,12 @@ int u64toa_r(uint64_t in, char *buffer) static __attribute__((unused)) int i64toa_r(int64_t in, char *buffer) { - char *ptr = buffer; - int len = 0; - if (in < 0) { - in = -in; - *(ptr++) = '-'; - len++; + *(buffer++) = '-'; + return 1 + u64toa_r(-(unsigned long long)in, buffer); } - len += u64toa_r(in, ptr); - return len; + + return u64toa_r(in, buffer); } /* converts int64_t to a string using the static itoa_buffer and returns From patchwork Wed Apr 16 18:40:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 14054418 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 CDE8D225390; Wed, 16 Apr 2025 18:40:49 +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=1744828851; cv=none; b=LfE3LYhqW53P8oTxCMHbvoyaj3x2kV/u/EhHJ60++kCUOF7pho0d6J+UDIsykP+dmQs0jbqGGXPAD4paRIVRnP/NsF5Qgsj8usHN8OjYreYi7QLGd3A3YaqJkln30DJzeFR0O8NZ0Bdd08HwrnIIt6xpQdog1Bvp0MF2macdvxc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744828851; c=relaxed/simple; bh=KobCUeJS2OEM5lPwozYg0JTzSnTraZcO9O3oDYtCUhI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rffQKCYIt0y2sKoXPnHSjokIa078ROFEanYbH+/D32pGzYfs6HH/ES1pYYYg6edAjO/MXDaOmxCkWK/IFupnLFXh72ipoXQHHeeKoiqXIXYokpDV5ulkCDxAWbrSYn8d2Cb7hEIpYj+jtEYR7DEgzzP+NEmRL14E+RWRN6KD+rM= 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=XdpK9U5P; 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="XdpK9U5P" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1744828843; bh=KobCUeJS2OEM5lPwozYg0JTzSnTraZcO9O3oDYtCUhI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XdpK9U5P/DoOz7iaC1i6PtAhGT07PUK4qtI+rnvfxe+RP2Ti1m8EJWm2S6IL4R/rv 6CoVMxVbtb+/0qiMTe30YouLExrIJlISdhHc046L6Q/D1B6RJmcvYBQ9UcBE6VRqK/ fW0sLBJ1Dnl17EgwsO4IKaMLXajTsTA152/LzGRw= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 16 Apr 2025 20:40:20 +0200 Subject: [PATCH 5/6] selftests/nolibc: disable ubsan for smash_stack() Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250416-nolibc-ubsan-v1-5-c4704bb23da7@weissschuh.net> References: <20250416-nolibc-ubsan-v1-0-c4704bb23da7@weissschuh.net> In-Reply-To: <20250416-nolibc-ubsan-v1-0-c4704bb23da7@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=1744828842; l=736; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=KobCUeJS2OEM5lPwozYg0JTzSnTraZcO9O3oDYtCUhI=; b=reVymp1nD/vf4WDhSrb9jjJ6nwGeZjOTVhrYc5BmNmfdR8Kml/RkBLstMrV73wLStCnTVzYyO igXxdOR10+jCotGITqCISVDqJYvtQwCe3li2TJSqXGdpHRz7/yTKxcF 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ßschuh --- 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/selftests/nolibc/nolibc-test.c index 7a60b6ac1457e8d862ab1a6a26c9e46abec92111..b176a706609b7641dd1d743c8a02b6b6e7a4c746 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; } +__attribute__((no_sanitize("undefined"))) static int smash_stack(void) { char buf[100]; From patchwork Wed Apr 16 18:40:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 14054417 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 CDE2722538F; Wed, 16 Apr 2025 18:40:49 +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=1744828851; cv=none; b=PiuQgxbQAf7tVxEMOIFQNMWuQ+MslzknIMss9s/bwlBS8+FIEH1tKHKKytALA4rknowQHZag1r8v3unZ1fANJKx91bOfVihglhiBnIrQqdJ9l+49q4bxq/tEP83vaYbgvwKzy3aRnsCfVYJp/nudEmGKqVld79WvBODxwXTjc1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744828851; c=relaxed/simple; bh=Z1bcOwaEL8wb4h1D5AwFZlAHw44W8YDLCsN003ABHao=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Y2rLRGc7h+Fsxi371rScBBBM0Uj7LGfZ7JvM9R1/u06hEpqZvFk63BLaXjuNmwrN3sPS5WFsO9i8qR1MX4VHJOVpVSC6AevGxzRnbT/2o3U/aZTtjxQVGlP5d6Ngch0pYyiyZ4bqNL50lNq1SBMse1swV+LrhQVoiT40XjY0uok= 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=FKGY49PY; 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="FKGY49PY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1744828843; bh=Z1bcOwaEL8wb4h1D5AwFZlAHw44W8YDLCsN003ABHao=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FKGY49PY+aJD3Zk9hYaJNGqTL2b9kWh9V1zAiApB9zkBxrWyO3gG6xRhOW6I/XLqK /iXWjsAJd5Q2zeMam5O8wgV935eLlRa3tIYVbcezzjGX/SHGTIpzWR4WYa9LieOXEd /FyhLfrguBiArRLUK2mIiCozc8sr8E2Ug24bshww= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 16 Apr 2025 20:40:21 +0200 Subject: [PATCH 6/6] selftests/nolibc: enable UBSAN if available Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250416-nolibc-ubsan-v1-6-c4704bb23da7@weissschuh.net> References: <20250416-nolibc-ubsan-v1-0-c4704bb23da7@weissschuh.net> In-Reply-To: <20250416-nolibc-ubsan-v1-0-c4704bb23da7@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=1744828842; l=1309; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=Z1bcOwaEL8wb4h1D5AwFZlAHw44W8YDLCsN003ABHao=; b=5uH7BCyiQnYSwYc4OPAZ5rlK+ma+NvCLUa/EsmPXvEDEVpsBANvQVnSAT2W8GTzRrxn7DeLBf 3v9YgXN0OrpBa5Jz7H7j0pHw/+rzfFAa2mVIp4bg9e5dOmFRf4pAdX/ 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ßschuh 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/selftests/nolibc/Makefile index aa05c1faac20d3054b231090b939d050b0231d40..94f3e8be7a68f63ecd639c4f283b3cd10764ce74 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -189,9 +189,10 @@ ifeq ($(origin XARCH),command line) CFLAGS_XARCH = $(CFLAGS_$(XARCH)) endif CFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all)) +CFLAGS_SANITIZER ?= $(call cc-option,-fsanitize=undefined -fsanitize-trap=all) CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra \ $(call cc-option,-fno-stack-protector) $(call cc-option,-Wmissing-prototypes) \ - $(CFLAGS_XARCH) $(CFLAGS_STACKPROTECTOR) $(CFLAGS_EXTRA) + $(CFLAGS_XARCH) $(CFLAGS_STACKPROTECTOR) $(CFLAGS_SANITIZER) $(CFLAGS_EXTRA) LDFLAGS := LIBGCC := -lgcc