Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2041426rdb; Mon, 9 Oct 2023 10:30:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFOHlNOt2/rQr8OJr/A5GtW4TBMA6magQZzbPLKBRmh40jXE6wJVc8PqPQuQCoUXM8eTOJ3 X-Received: by 2002:a05:6a00:2e81:b0:68f:fa05:b77a with SMTP id fd1-20020a056a002e8100b0068ffa05b77amr16271658pfb.31.1696872605128; Mon, 09 Oct 2023 10:30:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696872605; cv=none; d=google.com; s=arc-20160816; b=gw1lCUUJatKIl3G86/OcXghteP66zNn62iV2q/95gUfTfENOXq46XNCH9lDROLwq1L zV4QEA9sUwVKDmfRqXqh43lxdUVrbKe21T4LZNW55MwgdE+1OVsL0wbisuqMxtUYi5R2 fBhbNsj1UOh0WrMydy39ADK4qHng5g8HQ/1XglhlvliWFejXdEk10Q4JVpgW8SZCuT9c PiTw1s5PiY4t3sPuMTSA4WcCAkYJo6yAtlRprVWosyP1nrtIh3TxvvYV3prJD+0+FkJ4 qQBEoInC4V9r+1YeqrmSkZupxHNKFLWvyqyAGvjnIAubA4+aZJevwS3oVWOfk1MmJa+E 9DDw== 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=xmOFJ7BPS0CGwUS7ZxzIQam3KgDjrxQW8SgccLQm/wg=; fh=XeOGM4DNWV0+GwLeRS6SilX4OB8NwMvnvp5opNMYr5w=; b=vGlxRs08sQ4bwR5CdE8z4277DaudyrxqKZ2eg4aF9pAtaH34OyK0/FugPJvL3Qd527 btwSjRebJnLlLQDKoR4A7Bs+MyCTY7LEqVX6k0LdiwzSo/mx5BLJcQ5Rz3BU63w7KJAf FV6pHP4i4lM8+jVVp01TYQo7Wx8YmV6BQUopxJnQ0jHXkzND9vSy5jokQvqWz9u2MpQ/ RBJFxF/p6XnNLEbxkbdECc0lvJnQsaFUtsjEVaM9SMZXsoVSz/bGBUaCKG4QehmTG5TV 4SknX1+yQw2BTbAJbkPwMUB5A/R404LOcdIAn2ESViXVahQyytd6l3nynUHI9kTS4wc1 41RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=W+LO7eJ8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id e11-20020a65688b000000b00584b9d0ff81si9709965pgt.635.2023.10.09.10.30.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 10:30:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=W+LO7eJ8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id B778E81C0CB8; Mon, 9 Oct 2023 10:29:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377887AbjJIR3c (ORCPT + 99 others); Mon, 9 Oct 2023 13:29:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377524AbjJIR3a (ORCPT ); Mon, 9 Oct 2023 13:29:30 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A79F3B6 for ; Mon, 9 Oct 2023 10:29:27 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-692779f583fso3210880b3a.0 for ; Mon, 09 Oct 2023 10:29:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696872567; x=1697477367; darn=vger.kernel.org; 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=xmOFJ7BPS0CGwUS7ZxzIQam3KgDjrxQW8SgccLQm/wg=; b=W+LO7eJ8NduQhx2ab6yej00MuKZEMBVFNWOA1bgBDXr4JtClsqXJMmUfcmdhqSN53M uoeDjownN2FPtlyFRi0yd+dRy7P+BoAxwB1Ppps/92TJi4sLYl3MOa2CTpAmjnFZhGqV ai9SGZJl5n9BpTmZd5B0cyLb8P/6YSsvIy4fw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696872567; x=1697477367; 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=xmOFJ7BPS0CGwUS7ZxzIQam3KgDjrxQW8SgccLQm/wg=; b=H73vnZZ6cq14wu3X7mRzgPvoOXHztfgae3/XFkCvUTq+bjahi4JBKQXwimuJidQCLU I1ZQ/bEUFPLyqXwoENJrO3HFXCqAZCXjwDskwzPG3hy4h6HDOvGiRIs32VJXZ8FUeo/3 gqnVGl3U0lfiXrdJuwZhvAOWXQozVrABC4CeQwtWgdkHuVdUc3QaymCsRAJSELcpFd0y 8z17ARJ0pA2kVuJi0AgoguU2v/NAAwfen94O1ffI32wiF/0VbVZJ7RiklCuVA88FG9bZ TVthVtOJDoPzw10MwcN/aZeLBSykq6wjIiMjDKqZxAdM6oOZTAL2Vy8y1Q3DQF8hS4jF 5lcw== X-Gm-Message-State: AOJu0YyCEPjaINLYJRZTk1njphTfmZRxoBAN2eHP5Q8IkGu3XU65sn0/ ZNAZjiFdh5p1kgnMg6R90lUdBw== X-Received: by 2002:a05:6a20:7f9a:b0:140:a25:1c1d with SMTP id d26-20020a056a207f9a00b001400a251c1dmr17552800pzj.51.1696872567107; Mon, 09 Oct 2023 10:29:27 -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 i73-20020a636d4c000000b0057c29fec795sm6126977pgc.37.2023.10.09.10.29.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 10:29:26 -0700 (PDT) Date: Mon, 9 Oct 2023 10:29:25 -0700 From: Kees Cook To: Eric Biggers Cc: Nick Terrell , syzbot , clm@fb.com, dsterba@suse.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, linux-hardening@vger.kernel.org Subject: Re: [syzbot] [zstd] UBSAN: array-index-out-of-bounds in FSE_decompress_wksp_body_bmi2 Message-ID: <202310091025.4939AEBC9@keescook> References: <00000000000049964e06041f2cbf@google.com> <20231007210556.GA174883@sol.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231007210556.GA174883@sol.localdomain> X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 09 Oct 2023 10:29:57 -0700 (PDT) X-Spam-Level: ** On Sat, Oct 07, 2023 at 02:05:56PM -0700, Eric Biggers wrote: > Hi Nick, > > On Wed, Aug 30, 2023 at 12:49:53AM -0700, syzbot wrote: > > UBSAN: array-index-out-of-bounds in lib/zstd/common/fse_decompress.c:345:30 > > index 33 is out of range for type 'FSE_DTable[1]' (aka 'unsigned int[1]') > > Zstandard needs to be converted to use C99 flex-arrays instead of length-1 > arrays. https://github.com/facebook/zstd/pull/3785 would fix this in upstream > Zstandard, though it doesn't work well with the fact that upstream Zstandard > supports C90. Not sure how you want to handle this. For the kernel, we just need: diff --git a/lib/zstd/common/fse_decompress.c b/lib/zstd/common/fse_decompress.c index a0d06095be83..b11e87fff261 100644 --- a/lib/zstd/common/fse_decompress.c +++ b/lib/zstd/common/fse_decompress.c @@ -312,7 +312,7 @@ size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size typedef struct { short ncount[FSE_MAX_SYMBOL_VALUE + 1]; - FSE_DTable dtable[1]; /* Dynamically sized */ + FSE_DTable dtable[]; /* Dynamically sized */ } FSE_DecompressWksp; And if upstream wants to stay C89 compat, perhaps: #if __STDC_VERSION__ >= 199901L # define __FLEX_ARRAY_DIM /*C99*/ #else # define __FLEX_ARRAY_DIM 0 #endif and then use __FLEX_ARRAY_DIM as needed (and keep the other "-1" changes in the github commit): typedef struct { short ncount[FSE_MAX_SYMBOL_VALUE + 1]; - FSE_DTable dtable[1]; /* Dynamically sized */ + FSE_DTable dtable[__FLEX_ARRAY_DIM]; /* Dynamically sized */ } FSE_DecompressWksp; -- Kees Cook