Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp122282rwd; Tue, 30 May 2023 17:23:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7I8L3cIEYTjYRaq0/sLod9vLlwlLLh6H1yj7E4Ve7ZwYwU4/2t8JWtvKS2INBfq/tPlkOG X-Received: by 2002:a05:6a00:24c9:b0:64f:ef47:d0ca with SMTP id d9-20020a056a0024c900b0064fef47d0camr3946764pfv.1.1685492590697; Tue, 30 May 2023 17:23:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685492590; cv=none; d=google.com; s=arc-20160816; b=n6QvqEnH/RQaWrOl0Cs07GpmZ+Zb7xVt0knF+tGey0ze6yLpGJY5l4DfWT569tErqu 2AZBm/P3QM5CRpBnAwP87y0YdN/AtA+s5Lsm4XSiIv1g1whd5SkFqu/YgOsUxELUhzYa LyZXZcw2XrpDFgka66iUivV0x3RJU2sKRNepwUQJT9VNKguPzt60Pqw03qRL0/FmMlWw 4eg+h26bFoLRvUrxP9gDcdNW5ZHtV3mV6a2URzSRjUnD7F66serOwjDMfVpZu7yiruzH TBAJuPcBJNTF/LZgjjhHvhUdZ6bBHe5mjhcEqs58rmpLNeuaEK0oOqTYdx6NBnWdkBNC lKeQ== 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=MiX5kKBgyHn7Q2uueehDrf1adzHRm5bDWm/e4F6Anxg=; b=BDDeonkuVJeujLYcLoGUECas4hZNLZlxe0Kh5XVVZbr0r13En/JfYSbYbdQdKpikdS r6hG3X1G8iIGHw+zV01kcgcTWUjGwhyfHvdl5IAxrREv5012vIjoTAScvitzzA8vFeFB 1ur5Zex7ne6YTOxBDcss383lh+wQO7zlqWxzw6uY3t4/nEAkx36T3uniYf3P5lrmEOKw eHn0mtq19sXpdGJEX4OKU5lsrIIVnd/Vw4MfoffPlheuTLcyAAZi5UgRsQo17FsFLfKl ScDV/6QMdiR7aNFfGTDaT9irUPnRCtF6fTnIx7chG8DfR+/v+1H7wC92n3BlMPZw3VaS J4WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=F0S0BOKG; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k10-20020a637b4a000000b0053481e4c743si12577995pgn.171.2023.05.30.17.22.57; Tue, 30 May 2023 17:23:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=@chromium.org header.s=google header.b=F0S0BOKG; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233466AbjEaASH (ORCPT + 99 others); Tue, 30 May 2023 20:18:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231238AbjEaASG (ORCPT ); Tue, 30 May 2023 20:18:06 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 635CEFC for ; Tue, 30 May 2023 17:18:02 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-53f832298acso2003060a12.0 for ; Tue, 30 May 2023 17:18:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1685492282; x=1688084282; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=MiX5kKBgyHn7Q2uueehDrf1adzHRm5bDWm/e4F6Anxg=; b=F0S0BOKGLFqXikNeyUoqjigXLViNvD0x3BGX6c3oA6Jv13keqly43YCI3oi8/N1IyE G5hxcXETvy5iQwDC9scKKXtObF+mxkE0Fo/3h3ORwU3DmuZ5F6vJzMMU1NIkSOTRDsps FgyyKY33oFnU/okha3b4dWQBtFZzMhzX0/U4g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685492282; x=1688084282; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MiX5kKBgyHn7Q2uueehDrf1adzHRm5bDWm/e4F6Anxg=; b=YCLiTNqibbCao++3T1JC0pOn6hmcrRgAtyWTIMhOhKG2ie3aub9MZh8mNR010WurAO UZcmnHNd6vNiX53XTrLS03t/0E0kXG5/1iebWXv6QhN1Mv83ByVKHjgG8YBpvBI66i34 aA3j7G7IZ/mG8Dwdo/3f5s+3EC22aBrH+Hsf3gT8i/bLzTWeXdj99kJTrYBLd9xmyKy4 lp9NHIBjAggg45js3QB94JWaQeiyQC96ejSmLWnFEI2S9HSpBKQw+iemo/mjeD3H4aT9 5Kw81PxyekVs0a13QNdNamtR+Iee2onmZwlQjHG+4ZwQHHe1h2Wy1i41zX4y92f7Fu+o dE5g== X-Gm-Message-State: AC+VfDxUfFHHWkTbv/Y0lFq+Eg6jArYrSeoazUvbZicd8HlloocmEhYs dw60hl5FQHJAexotDtSY32IIhA== X-Received: by 2002:a17:903:32d2:b0:1b0:3841:bcda with SMTP id i18-20020a17090332d200b001b03841bcdamr4612548plr.0.1685492281828; Tue, 30 May 2023 17:18:01 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id l6-20020a170903120600b001b016313b1esm8794203plh.82.2023.05.30.17.18.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 17:18:01 -0700 (PDT) Date: Tue, 30 May 2023 17:18:00 -0700 From: Kees Cook To: Joan Bruguera =?iso-8859-1?Q?Mic=F3?= Cc: Thorsten Leemhuis , Herbert Xu , "David S. Miller" , linux-crypto@vger.kernel.org, LKML , Linux Next Mailing List Subject: Re: build error while building arch/x86/purgatory/sha256.o: invalid 'asm': operand is not a condition code [...] Message-ID: <202305301658.BF6ECF65C@keescook> References: <175578ec-9dec-7a9c-8d3a-43f24ff86b92@leemhuis.info> <20230528164031.266590-1-joanbrugueram@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230528164031.266590-1-joanbrugueram@gmail.com> X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-crypto@vger.kernel.org On Sun, May 28, 2023 at 04:40:31PM +0000, Joan Bruguera Mic? wrote: > I can also reproduce the problem with Arch's linux-next-git, see config: > https://aur.archlinux.org/cgit/aur.git/tree/config?h=linux-next-git&id=f9a384e1c582321651fb613782ebc5a581146af0 > > I've bisected it to df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3"), > which explains why it only happens on GCC13. Okay, this was a wild ride. Bottom line, -fstrict-flex-arrays=3 means that CONFIG_FORTIFY_SOURCE wrappers will be included in new places now that trailing arrays aren't ignored any more. The trailing array in question was for struct sha256_state: struct sha256_state { u32 state[SHA256_DIGEST_SIZE / 4]; u64 count; u8 buf[SHA256_BLOCK_SIZE]; }; And this "buf" is a memcpy() destination, it was being runtime bounds checked, which means FORTIFY might emit wrappers, which will call the WARN wrappers, which will hit this asm, which isn't supported in purgatory. > > The problematic expansion that causes the error seems to be this fragment > from `_BUG_FLAGS` in `arch/x86/include/asm/bug.h`: > asm(".long %c0 - .\n": : "i" (__FILE__)); > > Along with the fact that this file is built with `-mcmodel=large` > (see `PURGATORY_CFLAGS` in `arch/x86/purgatory/Makefile`). So, we can either disable fortify (which seems a big hammer) or disable the warning. Disabling the warning kind of hides the problem, though that seems to be the intention of purgatory.c's empty warn() implementation. :P I think it's best to disable fortify, though, as we're in a DISABLE_EXPORTS state, and probably others are going to need it too, as most other have already done so: arch/arm64/kernel/pi/Makefile: -D__DISABLE_EXPORTS -ffreestanding -D__NO_FORTIFY \ arch/riscv/kernel/pi/Makefile:CFLAGS_cmdline_early.o += -D__NO_FORTIFY arch/riscv/kernel/pi/Makefile:CFLAGS_lib-fdt_ro.o += -D__NO_FORTIFY drivers/firmware/efi/libstub/Makefile: -D__NO_FORTIFY \ These should probably gain -D__NO_FORTIFY: arch/riscv/purgatory/Makefile:CFLAGS_sha256.o := -D__DISABLE_EXPORTS arch/riscv/purgatory/Makefile:CFLAGS_string.o := -D__DISABLE_EXPORTS arch/riscv/purgatory/Makefile:CFLAGS_ctype.o := -D__DISABLE_EXPORTS arch/s390/purgatory/Makefile:CFLAGS_sha256.o := -D__DISABLE_EXPORTS arch/x86/purgatory/Makefile:CFLAGS_sha256.o := -D__DISABLE_EXPORTS I'll send patches. -Kees -- Kees Cook