From nobody Sat May 4 02:03:21 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 974A5C76196 for ; Tue, 28 Mar 2023 14:51:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233514AbjC1Ovi (ORCPT ); Tue, 28 Mar 2023 10:51:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233277AbjC1OvX (ORCPT ); Tue, 28 Mar 2023 10:51:23 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8D9FD307; Tue, 28 Mar 2023 07:51:01 -0700 (PDT) From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1680015059; bh=OC20lNQ2kW08aHm+ntfqMtfDoB6968+zaZ8h6wCeC0I=; h=From:Date:Subject:To:Cc:From; b=Ok2+HEIic10pECRlUIIVtxnPuTAa0eI732lvD25KYFwTpa3fN1bYQWfTcxbZGuQeN QgytGstYMtSgu/Sv0dUu28MzGJsh4qrLLT3WzFqgqMn0KOirFlwHF/Vh+7/CRv9BVl xShadoIGUho+cxix6dlxYmXayVseA401bFZfGvqs= Date: Tue, 28 Mar 2023 14:50:35 +0000 Subject: [PATCH] tools/nolibc: tests: use volatile to force stack smashing MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230328-nolibc-smash-stack-volatile-v1-1-2b4aa7563a77@weissschuh.net> X-B4-Tracking: v=1; b=H4sIALr+ImQC/x2NMQ7CMAwAv1J5xlJIhha+ghic4BKL4KC4rZCq/ p2I8W6428G4CRtchx0ab2JStcP5NEDKpE9GeXQG73xwwU+otUhMaG+yjLZQeuFWCy1SGB1PI1/ 8GGYm6IVIxhgbacq9oWspXX4az/L9L2/34/gBVdYBkIIAAAA= To: Willy Tarreau , Shuah Khan Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Alexey Dobriyan , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1680015056; l=1274; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=OC20lNQ2kW08aHm+ntfqMtfDoB6968+zaZ8h6wCeC0I=; b=foXYvQN71ivsHirrXL4/rtYWQt3bVjFIRd7+bVLXr3yfBSrVRpsXh4/ottXX9+xvJjweLVKdJ vb/glnJG7LMDyPiGskvss1mIdS6AKkwJ25++TRBYX7F/HJ+xdn04CcT X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use a volatile pointer to write outside the buffer so the compiler can't optimize it away. Reported-by: Alexey Dobriyan Link: https://lore.kernel.org/lkml/c0584807-511c-4496-b062-1263ea38f349@p18= 3/ Signed-off-by: Thomas Wei=C3=9Fschuh --- This is based on the "dev" branch of the rcu tree. --- tools/testing/selftests/nolibc/nolibc-test.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 21bacc928bf7..47013b78972e 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -667,17 +667,13 @@ int run_stdlib(int min, int max) return ret; } =20 -#if defined(__clang__) -__attribute__((optnone)) -#elif defined(__GNUC__) -__attribute__((optimize("O0"))) -#endif static int smash_stack(void) { char buf[100]; + volatile char *ptr =3D buf; =20 for (size_t i =3D 0; i < 200; i++) - buf[i] =3D 'P'; + ptr[i] =3D 'P'; =20 return 1; } --- base-commit: 6e7cac3d5b8c77ddedfaa7efad23aa542cde53b2 change-id: 20230328-nolibc-smash-stack-volatile-0e87e9273fea Best regards, --=20 Thomas Wei=C3=9Fschuh