From patchwork Sat Apr 19 10:46: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: 882802 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-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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ßschuh --- 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/compiler.h index e6d6dc116e43aa69b37eca02ed1590fc09486bdb..369cfb5a0e78f4ae1e1a2cac4077024b4e8ba225 100644 --- a/tools/include/nolibc/compiler.h +++ b/tools/include/nolibc/compiler.h @@ -18,6 +18,9 @@ # define __nolibc_has_feature(feature) 0 #endif +#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() From patchwork Sat Apr 19 10:46: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: 882801 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-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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ß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 Sat Apr 19 10:46:23 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: 882804 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-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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ß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];