From mboxrd@z Thu Jan 1 00:00:00 1970 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 8D938EB64DD for ; Sun, 2 Jul 2023 20:07:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232790AbjGBUHp (ORCPT ); Sun, 2 Jul 2023 16:07:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233099AbjGBUH3 (ORCPT ); Sun, 2 Jul 2023 16:07:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 897CA5599; Sun, 2 Jul 2023 13:05:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 60DFA60C71; Sun, 2 Jul 2023 19:57:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DA99C433C8; Sun, 2 Jul 2023 19:57:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688327869; bh=PR80scmzQp4U0vGt2Ne4nKASw/hrc6FoWE374ZYdT9I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rnZ07aok0Gva4BWuX5Me7LDMdbNj2yAz2mJhj/3j1L+hKpSna7xlK3qbur448eqUW ps+STaK0/Rh5M5+GNnHZ77gsF0i76CxPO0xDVQaUduQAP5mjo9gDcU5RngbY2vv6ko FJustEeN4p5s8G54pbImfbehmcKFWW2F9WoYZvH8RfPGm4sn4AVVTCS/Vz775ununu 6FZC0m0pvLHVWD50y/8mpebBxVYNjsCqLb11H9TggWxQ8kkrmxnGophLzz1499PSXl fk1VPERcGSbmMfl4qQF+AsTxLb7G+woFl/Am8jC3pnBn9nm+T2II+Uq1M8YnhUjjYw ceS+AJ2JVQp8Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" , Sasha Levin Subject: [PATCH AUTOSEL 6.4 4/4] tools/nolibc: ensure stack protector guard is never zero Date: Sun, 2 Jul 2023 15:57:42 -0400 Message-Id: <20230702195743.1793074-4-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230702195743.1793074-1-sashal@kernel.org> References: <20230702195743.1793074-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.4.1 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Thomas Weißschuh [ Upstream commit 88fc7eb54ecc6db8b773341ce39ad201066fa7da ] The all-zero pattern is one of the more probable out-of-bound writes so add a special case to not accidentally accept it. Also it enables the reliable detection of stack protector initialization during testing. Signed-off-by: Thomas Weißschuh Signed-off-by: Willy Tarreau Signed-off-by: Paul E. McKenney Signed-off-by: Sasha Levin --- tools/include/nolibc/stackprotector.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/include/nolibc/stackprotector.h b/tools/include/nolibc/stackprotector.h index d119cbbbc256f..9890e86c26172 100644 --- a/tools/include/nolibc/stackprotector.h +++ b/tools/include/nolibc/stackprotector.h @@ -45,8 +45,9 @@ __attribute__((weak,no_stack_protector,section(".text.nolibc_stack_chk"))) void __stack_chk_init(void) { my_syscall3(__NR_getrandom, &__stack_chk_guard, sizeof(__stack_chk_guard), 0); - /* a bit more randomness in case getrandom() fails */ - __stack_chk_guard ^= (uintptr_t) &__stack_chk_guard; + /* a bit more randomness in case getrandom() fails, ensure the guard is never 0 */ + if (__stack_chk_guard != (uintptr_t) &__stack_chk_guard) + __stack_chk_guard ^= (uintptr_t) &__stack_chk_guard; } #endif // defined(NOLIBC_STACKPROTECTOR) -- 2.39.2