Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp319147rwd; Mon, 12 Jun 2023 14:09:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7bdZ2wnwed7SJBgacxmScmIQ4bbbCC6PxVSMSq8ADhMl4OAUwVJFTfzebtwnv/320V4GE0 X-Received: by 2002:a17:907:96ab:b0:96f:f98c:ac71 with SMTP id hd43-20020a17090796ab00b0096ff98cac71mr9460495ejc.67.1686604156741; Mon, 12 Jun 2023 14:09:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686604156; cv=none; d=google.com; s=arc-20160816; b=UUi1dTrTzmZIQd19ckk7vpFnDm1aQV2qbINuYIUmB4XfsIeN6M2xS+Y210xKFg0Ben pjYxeFrkoCHFdGYLrpqIViPZFQOnT7gkvO8Ydhq3F2rADbddolur4I3Tkp3Q0gyNH4qt lUO5kA/E3LXlRBHyAmR9fF6CB/UKgqYIW2Wn69AfOHRrasEe2WTubkMOddM41355YoRD KbWy24yAE092tXNtsCqoeh/2++e0J3E8pJ2gXuXtCJRgmdcOVotEAQ71ke6hJVl8B9BK Me3bUUR2MwzAq+g5VtB9nxqaWLcPxq1J+o+3AuLdScbIfamfNyfnnv3+jzajUp2x6ghd cFgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5Rg/PfxzArA5bo4KUvvS36kuhNsUQ9UFFVzIapUsmHI=; b=Dck3fMWrRbvoKFeQOj2iGmwtTynd2B5ogz6ckwLFtqrYnI+x5ooelmV7GNlwu9OPDD zHr+2NzN4/HecNBeofRgPPlPi/ALic7uGga8YifviNmNjQOSM2DUCVJq93NLemvlDwYW zeUOe35ACQCnpOqm+nYxvH4OS8cpoqfR2Jb9mqcGhPKr1QCaxkuLzFPE+y/MDQoUii6J F1fRTpTetja6s56wNupU9lV5shhDgy069xc0jE3CrRgJJKQtUmTxRbpIen+cjYEdgr28 w1j52xVIp0VTkrxOLBg1abvVG3U68CwwSkREs7XMZsy8QeWd20goDM9NZ22ve9jtf/Pc R7SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=p0Ohgdl5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m26-20020a17090607da00b009771db0ed07si4163558ejc.418.2023.06.12.14.08.49; Mon, 12 Jun 2023 14:09:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=p0Ohgdl5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238630AbjFLUvs (ORCPT + 99 others); Mon, 12 Jun 2023 16:51:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238233AbjFLUt2 (ORCPT ); Mon, 12 Jun 2023 16:49:28 -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 358B31BFB for ; Mon, 12 Jun 2023 13:47:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1125062F2D for ; Mon, 12 Jun 2023 20:45:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AFE2C43445; Mon, 12 Jun 2023 20:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686602717; bh=m6VW9L1DfLWVSVi0RNl6hit3N3enOx/+urG9Qu9XTN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p0Ohgdl5koVAi4NEWD3gyKQla9v1Znt/dlMhMqbKNxXuOrDZyMlTGgp2OhL4j31H7 DdLqVvl+gc1fSiIiLDYbCL95Clf3cwRZHI40wnNnURs3TQQjPOA366vHS51bY1+V09 u3CbgcCz1kVQfKkkSkOaHn9vku+k2BWUT1ZQl16sEZXSzoUaJEAyymSmvdOhMhJfo6 HJ6dtFzW3PKq3wMkZsPUy37BJXepc8L+fkb7B90ABwOwKgSpEYvdPfTZ0IWUfzGvN9 G1Vv332VaM6wGTw+jY4jgG+571m9h+7N6yT5CFPzLVDDSd1NH0ZHgsSkmNVk3SjhTH xXSq+V8IpCQkg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id E6798CE3A6F; Mon, 12 Jun 2023 13:45:15 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: gwml@vger.gnuweeb.org, kernel-team@meta.com, w@lwt.eu, =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Willy Tarreau , "Paul E . McKenney" Subject: [PATCH v2 nolibc 27/53] tools/nolibc: ensure stack protector guard is never zero Date: Mon, 12 Jun 2023 13:44:48 -0700 Message-Id: <20230612204514.292087-27-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> References: <8b757cc0-3719-4e63-a755-9710384137bc@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Weißschuh 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 --- 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 77e5251c4490..b0156fc077a0 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.40.1