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: 881736 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: 881737 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: 881734 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];