Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2540544rwb; Fri, 2 Dec 2022 11:09:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf501CNW8/jcg3C16ivJk+JzncJa3k4k/QDOeAj8Fo0YksZ3KVKEZgwU6hDVvielcxUKQ9m/ X-Received: by 2002:a63:d54a:0:b0:476:c7f2:7b80 with SMTP id v10-20020a63d54a000000b00476c7f27b80mr46275952pgi.230.1670008190312; Fri, 02 Dec 2022 11:09:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670008190; cv=none; d=google.com; s=arc-20160816; b=Rans0Ozh+B36y/+f4mmEkFyID6MbTSBRuGBfHtX/QkgtYaAisEYCInxt1fna1OvZ3q 37ZCuRFls+vV5lzmWW18NW7RjhhKQNrW1/nYjiessF7KkJby18wVDh9aDs7xbwVjTFZl AXpVDIbe1Ce9W+lA1vsVvj9xq9IE+N5zporn8vHfDTkG6rrgFcTWfb6UD/7Vej/xUSe7 H9SoBxATR3aoBT+EOz4xNR+tSAvCvyUt0a5aIrL5QOgWz1GxgdRZsmvw7QIYtR44CE8C 4nzBOfWO/EI7PhKlFzF7u8L/fPcpzfhCOvo4FrF47LcRkquVeaGewKTU7Ztt8aZnB6La Miew== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hPdGcOCEsG7lUmArEzStFj43mzNWvKg2+Ebw16M3TCY=; b=MQ8a2mBe84RH4wBcHknzjWBEXg9AuzywyZxvEtE0j308o3veJnheFPGglY8xToBBk3 7oYp7/zhxI6KA1gR+LA7/y525KOLr9mwhvgjNLXfLUlDXPzaacDVQn55TPmM9q/L7onZ NmMSA7XmCvpAYZSam8U4FhumkLyex35BubrlOZ8Bj2kf4jvy9CCz5y9MVhJitfUI4/ik f9iueaE5xc6EYnj7yI3Q7qhWCOkXCx4Pf6O+IVTVujzeb0C6KcRFWbHPrqixWP/5q901 DDxAWNlEiPlPi0vH4J9hWOaqNoX9SLPSNFSCay/U3Qm6mOPEq7kLslt36gjRILKzi1ZM Nlyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PU3gDK3J; 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 l14-20020a170902f68e00b0017c162fc28fsi9040810plg.195.2022.12.02.11.09.36; Fri, 02 Dec 2022 11:09:50 -0800 (PST) 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=PU3gDK3J; 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 S233794AbiLBS6P (ORCPT + 99 others); Fri, 2 Dec 2022 13:58:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbiLBS6N (ORCPT ); Fri, 2 Dec 2022 13:58:13 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12BFE92A14 for ; Fri, 2 Dec 2022 10:58:13 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id v3so5103412pgh.4 for ; Fri, 02 Dec 2022 10:58:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=hPdGcOCEsG7lUmArEzStFj43mzNWvKg2+Ebw16M3TCY=; b=PU3gDK3JBsY8Izq24LkRkMa24eKn0Mu0dmVHTCV4yTEpqX6bxxHxWKaBIDHx0HnqeJ jhExXB/Ex03vAiF69WJEpsCl4UWQ9Tovfwyo9wxw+NkZDdH0KfetQa679Ugg8duke325 KxFZeqdCU9j9zaf0rQ4JEC0LZDDu0WcfjaHss= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to: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=hPdGcOCEsG7lUmArEzStFj43mzNWvKg2+Ebw16M3TCY=; b=hErljYberRG6lpMZG1tfZOjKZ/DJoZgwAFWcN6hIWcg+p3u8QgNacPkr4DM0durdQT jVi9koOwzC5E4xc8unZQuSigTzjGfhXGxyIEI2g7vzCRosjfGaWbUXxnxWs2q5Cg5MTH esczqWdGfj7MIwy2zJRxPOit/DR/z6RlXadibrTY4sN0jbBx+T75wq0RgNhpeokhOFdA 3F9lu5SHEHkq9gWo9FCNjTt/mmPwRONDEQa4/QfY4IZmOPTM2REApiBkO/7VQfk2Ij0s abl7NWcJIMuXfxbkUR4c+cvwlKNqkcqHEQYeCAyrXIpZWQtv5jDNnhwXilzgdxGSBQFS 7h1w== X-Gm-Message-State: ANoB5pnph4oMkp4SG1z9xrj+9LCEKCfd1f4xbEr+TxD6wUxGH6esuxgU qQLu35p4LYdeBkpWtnE6cUuJIQ== X-Received: by 2002:a62:65c3:0:b0:562:ce80:1417 with SMTP id z186-20020a6265c3000000b00562ce801417mr53353551pfb.19.1670007492560; Fri, 02 Dec 2022 10:58:12 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id d12-20020a170903230c00b0016c9e5f291bsm5948660plh.111.2022.12.02.10.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 10:58:11 -0800 (PST) Date: Fri, 2 Dec 2022 10:58:11 -0800 From: Kees Cook To: David Laight Cc: 'Anders Roxell' , Horia =?utf-8?Q?Geant=C4=83?= , Pankaj Gupta , Gaurav Jain , Herbert Xu , "David S. Miller" , "linux-crypto@vger.kernel.org" , kernel test robot , "linux-kernel@vger.kernel.org" , "linux-hardening@vger.kernel.org" Subject: Re: [PATCH] crypto/caam: Avoid GCC constprop bug warning Message-ID: <202212021057.B1B1BDE380@keescook> References: <20221028210527.never.934-kees@kernel.org> <20221202005814.GD69385@mutt> <4f7ffdd948a84013a0e84876b3e3944b@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4f7ffdd948a84013a0e84876b3e3944b@AcuMS.aculab.com> X-Spam-Status: No, score=-2.1 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 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 Fri, Dec 02, 2022 at 10:01:50AM +0000, David Laight wrote: > From: Anders Roxell > > Sent: 02 December 2022 00:58 > > > > On 2022-10-28 14:05, Kees Cook wrote: > > > GCC 12 appears to perform constant propagation incompletely(?) and can > > > no longer notice that "len" is always 0 when "data" is NULL. Expand the > > > check to avoid warnings about memcpy() having a NULL argument: > > > > > > ... > > > from drivers/crypto/caam/key_gen.c:8: > > > drivers/crypto/caam/desc_constr.h: In function 'append_data.constprop': > > > include/linux/fortify-string.h:48:33: warning: argument 2 null where non-null expected [- > > Wnonnull] > > > 48 | #define __underlying_memcpy __builtin_memcpy > > > | ^ > > > include/linux/fortify-string.h:438:9: note: in expansion of macro '__underlying_memcpy' > > > 438 | __underlying_##op(p, q, __fortify_size); \ > > > | ^~~~~~~~~~~~~ > ... > > Is this really a bug in the fortify-string wrappers? > IIRC the call is memcpy(NULL, ptr, 0) (or maybe memcpy(ptr, NULL, 0). > In either case call can be removed at compile time. > > I'd bet that the constant propagation of 'len' fails because > of all the intermediate variables that get used in order to > avoid multiple evaluation. > > The some 'tricks' that are used in min() (see minmax.h) to > generate a constant output for constant input could be > use to detect a compile-time zero length. > > Something like: > #define memcpy(dst, src, len) \ > (__is_constzero(len) ? (dst) : memcpy_check(dst, src, len)) > > With: > #define __is_constzero(x) sizeof(*(1 ? (void *)(x) : (int *)0) != 1) > Which could go into const.h and used in the definition of __is_constexpr(). While it could be possible to strip the nonnull attribute, I think it's not an unreasonable check to have. This is literally the only case in the entire kernel that is tripped, for example. -- Kees Cook