Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1721810rwb; Fri, 13 Jan 2023 17:01:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXsYjwfXeIUXfrAqFEyskjtSVJHuvah6BUrQhAXO6YPEZeutWBrlTF/7o78VCpCO9GaYYkEv X-Received: by 2002:a17:907:76e1:b0:7c0:e7a8:bc41 with SMTP id kg1-20020a17090776e100b007c0e7a8bc41mr4886146ejc.74.1673658082849; Fri, 13 Jan 2023 17:01:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673658082; cv=none; d=google.com; s=arc-20160816; b=tU5ODZjp+pbSE2ejZ9YHa0/NToD4g6Q4zuMiZjnuuSLg1R9yqzqhvBalHIQS08HTLB yqjmxaxh52Eh0rijY/gJ3I5Q/2cBsCSE9MTeLLZUFnUm/M5rPVlpPDQiA52LcAcyIhcl jp2X6Qob9WL07cyqCpkmpUmhDyyjD96PZGTE/ghegXCtbcd9WsGF5sLjRhGbL1ZVmQKC ZkoA4J5nqoWuvvKw3SAKWLbAj7HUFakHmbNBaFGNab82U5hPG2n2oE/7b8ltps948oet mTu4GbOjroiTQzRetzG/w21Z4TYOWrv/iUWsE3OEolnOJrWd57aAeJHJWzckYbwAiaIU MBUw== 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=cS7wan9cbZoOd7zB1+M5b4d8bFVgzEAWJ4LPm7C+GjA=; b=MkeV9zmEKtcjn+t0hooeFvTY79/DP9tPRgPVxIAimwf9/QXFxxAYki4bCeReXUQ/5p rT3G9q1g/r3MkcLzH0FWXEH52U/sUiUU9dH71420s48gxdYX3ZngPkANpqsiohd4as2q QXmXcNR9kstFw0Jd1zP2B0WE85I/umeQ2t/Zq/BC54Is+kVB2NUTb7LCtCpHJ6LOckNd fNqZXaWKxbywIJTNPz+Mar+IAgggVQDG8S2tNvT7F6YqocjLY7PhXu7HHNL7cO9RaOEN aEGjGrvMZBDPz8W8eIIcpVVEhzwM8lYoDuihCYK4HinKym91uez7G1YZ2SqhNX6I2nLL MCCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NhAuNx2h; 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=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw18-20020a170906479200b008641d4f0500si8351633ejc.301.2023.01.13.17.01.05; Fri, 13 Jan 2023 17:01:22 -0800 (PST) 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=@chromium.org header.s=google header.b=NhAuNx2h; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230273AbjANAsT (ORCPT + 53 others); Fri, 13 Jan 2023 19:48:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230093AbjANAsR (ORCPT ); Fri, 13 Jan 2023 19:48:17 -0500 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA839736E1 for ; Fri, 13 Jan 2023 16:48:15 -0800 (PST) Received: by mail-pg1-x52e.google.com with SMTP id h192so16060470pgc.7 for ; Fri, 13 Jan 2023 16:48:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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=cS7wan9cbZoOd7zB1+M5b4d8bFVgzEAWJ4LPm7C+GjA=; b=NhAuNx2hRH7I5HTrgseohkAywJmS6quhZeL4g2mSVQXB/BJMuYcGSOacHlw//Sebdm wMKr2/d4K9SOFwphx4WezYolD/TGjIJSK5/7Z/TDsPu9pUrgOhHPlHFvxterdyKE2R+7 9++jA/1wSe2cDgCWQEFAizv82BljibbafIdy8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=cS7wan9cbZoOd7zB1+M5b4d8bFVgzEAWJ4LPm7C+GjA=; b=rzeolFvzDwu4sAMHv2uenOkOt0Taz6YJsXEM+Q4D9/omtG8Vak7Gf3xuLMpedA8+83 QOvG+ZmaZmcc0o3YcCbLxwKYqAKvHKN2HbtawrWoB74Iay5HGYT697bY5O/PveSiLdM6 GPLClftg2PYLS7rSDKA3EIU63dJElzDBFFH9LRw3+toCC3wuRWck7zSlX4814iVm2r6f cz6NvBkR8rEXd/2SVaKxDPibpAcEMdBlVYptxK0XEamrfn0Mgm72uflhoRP8wLcgSAkP j0HjrV7375MXA8+7aYU9Qds2N8WBlM2CzAch2gldxRUDXBLuH7N2JhVkAFfUsqGmBhkp 3+dQ== X-Gm-Message-State: AFqh2krHut1NsLolsLVVCkb4dIw8FpM/J+CCQaxrb+zWOpbQVh+w4H/H d2pAiHPhYvyoa6KTSsH7fXVDuw== X-Received: by 2002:a62:30c2:0:b0:580:ccae:291c with SMTP id w185-20020a6230c2000000b00580ccae291cmr67924066pfw.24.1673657295096; Fri, 13 Jan 2023 16:48:15 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x9-20020aa79569000000b00581f8965116sm14170634pfq.202.2023.01.13.16.48.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 16:48:14 -0800 (PST) Date: Fri, 13 Jan 2023 16:48:13 -0800 From: Kees Cook To: Nick Terrell Cc: "Gustavo A . R . Silva" , Linux Kernel Mailing List , "linux-hardening@vger.kernel.org" Subject: Re: [PATCH v2] lib: zstd: Fix -Wstringop-overflow warning Message-ID: <202301131643.6D23A4AEA1@keescook> References: <20230104212048.gonna.331-kees@kernel.org> <93130521-AF03-4941-8FF1-C97C76027A02@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <93130521-AF03-4941-8FF1-C97C76027A02@fb.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-kernel@vger.kernel.org On Tue, Jan 10, 2023 at 11:10:08PM +0000, Nick Terrell wrote: > > > > On Jan 4, 2023, at 1:20 PM, Kees Cook wrote: > > > > !-------------------------------------------------------------------| > > This Message Is From an External Sender > > > > |-------------------------------------------------------------------! > > > > Fix the following -Wstringop-overflow warning when building with GCC 11+: > > > > lib/zstd/decompress/huf_decompress.c: In function ‘HUF_readDTableX2_wksp’: > > lib/zstd/decompress/huf_decompress.c:700:5: warning: ‘HUF_fillDTableX2.constprop’ accessing 624 bytes in a region of size 52 [-Wstringop-overflow=] > > 700 | HUF_fillDTableX2(dt, maxTableLog, > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > 701 | wksp->sortedSymbol, sizeOfSort, > > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > 702 | wksp->rankStart0, wksp->rankVal, maxW, > > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > 703 | tableLog+1, > > | ~~~~~~~~~~~ > > 704 | wksp->calleeWksp, sizeof(wksp->calleeWksp) / sizeof(U32)); > > | > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > lib/zstd/decompress/huf_decompress.c:700:5: note: referencing argument 6 of type ‘U32 (*)[13]’ {aka ‘unsigned int (*)[13]’} > > lib/zstd/decompress/huf_decompress.c:571:13: note: in a call to function ‘HUF_fillDTableX2.constprop’ > > 571 | static void HUF_fillDTableX2(HUF_DEltX2* DTable, const U32 targetLog, > > | ^~~~~~~~~~~~~~~~ > > > > by using pointer notation instead of array notation. > > > > This is one of the last remaining warnings to be fixed before globally > > enabling -Wstringop-overflow. > > The patch looks correct to me, thanks for reviving it. But, I was attempting to reproduce the issue, > so I could better understand what's going on, and I wasn't able to reproduce it myself. > > To attempt to reproduce, I applied this patch > > --- > diff --git a/lib/zstd/Makefile b/lib/zstd/Makefile > index 20f08c644b71..190d3d5ab4be 100644 > --- a/lib/zstd/Makefile > +++ b/lib/zstd/Makefile > @@ -12,6 +12,8 @@ obj-$(CONFIG_ZSTD_COMPRESS) += zstd_compress.o > obj-$(CONFIG_ZSTD_DECOMPRESS) += zstd_decompress.o > obj-$(CONFIG_ZSTD_COMMON) += zstd_common.o > > +ccflags-y := -Wstringop-overflow=4 -Werror > + > zstd_compress-y := \ > zstd_compress_module.o \ > compress/fse_compress.o \ > --- > > Then compiled on x86-64 with gcc 12.2.0 on tag v6.2-rc3. I saw no errors. > I also tried with just `-Wstringop-overflow`, and on upstream zstd. I tried to > make a minimal reproducer on godbolt, so I could see if it was the gcc version, > but wasn't able to make it fail with any of them https://gcc.godbolt.org/z/Exzq9arMr. > > Could you please tell me how to reproduce this warning? I saw it like so with next-20230113 on x86_64: $ gcc --version gcc (Ubuntu 12.2.0-3ubuntu1) 12.2.0 ... $ make KCFLAGS=-Wstringop-overflow allmodconfig lib/zstd/decompress/huf_decompress.o -- Kees Cook