Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp957196rwd; Wed, 31 May 2023 07:40:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7IDfEvy4ZUS8Sijet/nKDJTL58Y3Xofq64qRGQAhz5P6wneTx9+ekOTM4WMCWN0qhHqvA1 X-Received: by 2002:a17:90a:8f03:b0:256:8065:6a4c with SMTP id g3-20020a17090a8f0300b0025680656a4cmr6184811pjo.23.1685544047957; Wed, 31 May 2023 07:40:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685544047; cv=none; d=google.com; s=arc-20160816; b=Gs45ywULv4kD6KJue+iZi5KQS89oQFRpDhc4Hn8OvtIr1io16mpV3LJHlj9ZoiH+Ia mVjP5waMbrIIBoN7hBI0Pce9YLtBG1lx2oQGxph2DEY8i/gEmsLjRNUoGSBP85qd1Vqc pZ5eG38a7FKkMRWLwQVQ2dG1+7CItH74tnHsBCDgGckcEZLxrwjrjd5URq0pT/ST3ztr ZP9PmIQFlUuUzSwwd+0GM+jAWb203TXB5cMNZQBenHPY06nzUeuoUaiZmDYYWge0shc/ lvsC5PgWmmKdz688PSuUI0oh9nmKiRHJlb2N5R4MQIRq5YzM+2x0zWAW+pOFhA7rXH/A XFvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=77naLT0xOXwfjxLzY4CMGyObUA5/rNUe3mwgbrj0dIE=; b=dqpbUAt9Wz7wzMd6oCIsB+QHdSe9wlpJD1qB0s2V0aTZIjv48Ud1hr5iOuFCcMr88l h5HfjtT8ei9Hz/pYLb5RA5qSN9UKAkVVHliPW09SKCg1DSIFvhzlsNqCDVhdP1fUVAZ4 tbpqei0gifpBhmORj0QfHmoDVX96C1d3VCV4L+n00nbeyZiCHykW0kM/zNFufkm5p0wC W0P0322Gm7Br6ltm19UPMncxGn2b+K25PQOKtK0EFnf0eBFJB71mjaJ8Hacp2SC19Ovm +FFnkpjDQdBcobLcH/vdXhgFIpA3LeB2r8W3WZL/bXmFS6izEyRHP6mJvhZXxP6ywDEU feeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DAWDh6MT; 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 a24-20020a17090ad81800b00250ab2f31besi1088704pjv.71.2023.05.31.07.40.30; Wed, 31 May 2023 07:40:47 -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=DAWDh6MT; 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 S236739AbjEaOdt (ORCPT + 99 others); Wed, 31 May 2023 10:33:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231215AbjEaOdr (ORCPT ); Wed, 31 May 2023 10:33:47 -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 9487995; Wed, 31 May 2023 07:33:46 -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 2863263CCF; Wed, 31 May 2023 14:33:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0A6CC433D2; Wed, 31 May 2023 14:33:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685543625; bh=L/dTiuT+ktTPMYaEXn8ndEBWIS2gWoNfI9OE21M1RCg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DAWDh6MT2/MOtKpYopxqF6yhYjN3Qup3Cr0wyjAksB7/WUJjjrXFFe6DjOfpMfBM4 QZowXDJ9uBub7Qjj5Vt1XAJTM/HlFOmmg4X09fqxPu164R8LFPiGxGF1yOhpELJ1P9 SPBfjOB3mU8YdPM0ZSV0XgBA2bNFvS9E2sjK5KI5GSl5GToBpbbt6q1+bT+xJX1Htr ZkXqctLQYhkudRx5Inv6rqeTVwzKiI6w3ReyywcO/G2KiKFB5hSZ3IjNKosI0kAeoN 43otBMx5iqyOI883q+oSEOCBdmreGVQmmSR7FOm0SMAsitUknO+pk8V8xrmBnxnO0v PPH+G4yJm2wCg== Date: Wed, 31 May 2023 07:33:42 -0700 From: Nathan Chancellor To: Kees Cook Cc: Heiko Carstens , Thorsten Leemhuis , Joan Bruguera =?iso-8859-1?Q?Mic=F3?= , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Masahiro Yamada , Linux Kernel Functional Testing , "Gustavo A. R. Silva" , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] s390/purgatory: Do not use fortified string functions Message-ID: <20230531143342.GA2250333@dev-arch.thelio-3990X> References: <20230531003414.never.050-kees@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230531003414.never.050-kees@kernel.org> X-Spam-Status: No, score=-4.6 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 On Tue, May 30, 2023 at 05:34:15PM -0700, Kees Cook wrote: > With the addition of -fstrict-flex-arrays=3, struct sha256_state's > trailing array is no longer ignored by CONFIG_FORTIFY_SOURCE: > > struct sha256_state { > u32 state[SHA256_DIGEST_SIZE / 4]; > u64 count; > u8 buf[SHA256_BLOCK_SIZE]; > }; > > This means that the memcpy() calls with "buf" as a destination in > sha256.c's code will attempt to perform run-time bounds checking, which > could lead to calling missing functions, specifically a potential > WARN_ONCE, which isn't callable from purgatory. > > Reported-by: Thorsten Leemhuis > Closes: https://lore.kernel.org/lkml/175578ec-9dec-7a9c-8d3a-43f24ff86b92@leemhuis.info/ > Bisected-by: "Joan Bruguera Mic?" > Fixes: df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3") > Cc: Heiko Carstens > Cc: Vasily Gorbik > Cc: Alexander Gordeev > Cc: Christian Borntraeger > Cc: Sven Schnelle > Cc: Masahiro Yamada > Cc: Linux Kernel Functional Testing > Cc: Nathan Chancellor > Cc: "Gustavo A. R. Silva" > Cc: linux-s390@vger.kernel.org > Signed-off-by: Kees Cook Reading https://lore.kernel.org/202305301658.BF6ECF65C@keescook/ was some good additional context. Reviewed-by: Nathan Chancellor > --- > arch/s390/purgatory/Makefile | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/s390/purgatory/Makefile b/arch/s390/purgatory/Makefile > index 32573b4f9bd2..cf14740abd1c 100644 > --- a/arch/s390/purgatory/Makefile > +++ b/arch/s390/purgatory/Makefile > @@ -10,7 +10,7 @@ PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y)) > $(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE > $(call if_changed_rule,cc_o_c) > > -CFLAGS_sha256.o := -D__DISABLE_EXPORTS > +CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY > > $(obj)/mem.o: $(srctree)/arch/s390/lib/mem.S FORCE > $(call if_changed_rule,as_o_S) > -- > 2.34.1 >