Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2418869rdh; Wed, 27 Sep 2023 01:53:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6UP65sugDhrmITxHDUiQkopbUrQM4n1fuTOuZkoDwiAj81fwwUYfOzPPjaAKPdPN3i46n X-Received: by 2002:a05:6a00:993:b0:68f:bb16:d16a with SMTP id u19-20020a056a00099300b0068fbb16d16amr2323050pfg.5.1695804784259; Wed, 27 Sep 2023 01:53:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695804784; cv=none; d=google.com; s=arc-20160816; b=F2yxNNQYfC+9vxGZIhNRymrQLlsflhazK/dH3ziKMgKLzpx04FLQwFhAVVu+p68rVa Ls/eg1Vrqd0/IqKLPadiBLm0mk2Pq4bDZwOQF/xpg4EnLOEEvlTQDae95FGASEKvCKQk JDBPxiGTO7QD4Q1gHGj+1PAIbsGLSWNydH3CeocBFEp+iQKIJRsS34ShE/JBixFxOy2d HFZePRgJpA2V9CE/T8LGsaI3zRdCtk7WRsRH/TApVHosY7b5uvA0b6eQMCCtsLIi2xrq /O6GIeNJDGwMefU1gEIWCxTcrpAj4rgbpgXNQ1X+49C5lYXQm2IiQhqWaB5rktw1vRGF S5Fw== 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; bh=fjQX04A/DtvowmqHJm+Ej0NEAtFm1t5V2PaKRSysvbw=; fh=0s5vfmZDbl1esSnUK0ZxnNhgSQTQAi6eA0fFHaF7pEg=; b=CO6hPeqCVAqJGmUNmdg44hXhf9FzzLtu634dXSX7Jl3aTRmBH0850YwK4ANjNCuMiy Yh5JWAZaa3GrNbVtnaEOCdH4Qg6dUMxzde6q62ojOTPdzegSQfktMqC6nSnK9b8Koxms tI6DjoXU4p7uBiY64n/d25NapNLEd+Rfz1qeaXhWc9UC1YycQvvngl/SliCrZHhSf/jT C/6UsulQT1sH8q2kIT+sDVwTP8Ih5EYwh3goA3VjJI2Gpzetuzwgf21rUXfKTQn7wXzj yBhFv4qLkC1XzlFsJy1KMP7DIE3gwOyDk5r9cVBcqEpoO8moKvqn0T0c/yzp6MSScWkn p4iA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id z13-20020a6553cd000000b00574166b7d34si14815267pgr.881.2023.09.27.01.53.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 01:53:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id F35E6804B2A5; Wed, 27 Sep 2023 01:36:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230464AbjI0IgN (ORCPT + 99 others); Wed, 27 Sep 2023 04:36:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230406AbjI0Ifp (ORCPT ); Wed, 27 Sep 2023 04:35:45 -0400 Received: from ganesha.gnumonks.org (ganesha.gnumonks.org [IPv6:2001:780:45:1d:225:90ff:fe52:c662]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 569DC10DB; Wed, 27 Sep 2023 01:35:16 -0700 (PDT) Received: from [78.30.34.192] (port=49434 helo=gnumonks.org) by ganesha.gnumonks.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qlQ0k-00BBzy-EC; Wed, 27 Sep 2023 10:35:12 +0200 Date: Wed, 27 Sep 2023 10:35:09 +0200 From: Pablo Neira Ayuso To: joao@overdrivepizza.com Cc: netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kadlec@netfilter.org, fw@strlen.de, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, rkannoth@marvell.com, wojciech.drewek@intel.com, steen.hegenlund@microhip.com, keescook@chromium.org, Joao Moreira Subject: Re: [PATCH v2 0/2] Prevent potential write out of bounds Message-ID: References: <20230927020221.85292-1-joao@overdrivepizza.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Score: -1.9 (-) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Wed, 27 Sep 2023 01:36:58 -0700 (PDT) On Wed, Sep 27, 2023 at 10:25:03AM +0200, Pablo Neira Ayuso wrote: > On Tue, Sep 26, 2023 at 07:02:19PM -0700, joao@overdrivepizza.com wrote: > > From: Joao Moreira > > > > The function flow_rule_alloc in net/core/flow_offload.c [2] gets an > > unsigned int num_actions (line 10) and later traverses the actions in > > the rule (line 24) setting hw.stats to FLOW_ACTION_HW_STATS_DONT_CARE. > > > > Within the same file, the loop in the line 24 compares a signed int > > (i) to an unsigned int (num_actions), and then uses i as an array > > index. If an integer overflow happens, then the array within the loop > > is wrongly indexed, causing a write out of bounds. > > > > After checking with maintainers, it seems that the front-end caps the > > maximum value of num_action, thus it is not possible to reach the given > > write out of bounds, yet, still, to prevent disasters it is better to > > fix the signedness here. > > > > Similarly, also it is also good to ensure that an overflow won't happen > > in net/netfilter/nf_tables_offload.c's function nft_flow_rule_create by > > making the variable unsigned and ensuring that it returns an error if > > its value reaches UINT_MAX. > > > > This issue was observed by the commit author while reviewing a write-up > > regarding a CVE within the same subsystem [1]. > > I keep spinning around this, this is not really an issue. > > No frontend uses this amount of actions. > > Probably cap this to uint16_t because 2^16 actions is more than > sufficient by now. Actually, even 2^8 actions is more than enough by now.