Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3760418rdh; Fri, 29 Sep 2023 01:10:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEx85jUPyRqpJaQGV3jKv/5ouu4lw3HayjZexkbMMFOEizyzfNZeUhAlRtSwpksrgN+U+va X-Received: by 2002:a05:6a20:1049:b0:154:b1f7:b396 with SMTP id gt9-20020a056a20104900b00154b1f7b396mr3225364pzc.35.1695975040231; Fri, 29 Sep 2023 01:10:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695975040; cv=none; d=google.com; s=arc-20160816; b=hIyyjKAlCuyTDFwEJgtugqKdv7opsjpBOlvVcqhhLKCdFfgQwRXIvGboDNSyUi4A7A zzKV81OWMlHka5PM9mLqfIkANegOHWprcQlK/H8XCG1DhyS6ZnBXKLfGl33yKHNgO+s+ sVgSj9AM8zPK+OqAaBzaN0e5xDNkPsWjmPR/Cvx8JAjwMDUbbb8jB5eBSs7udlFbIaeB Oaw+fzFmMno0TWp6Su3ipLJtw3KA4uBjWNrGMsVY0/DxgZXrQFtVuWmsln8bitGn5y4p w//7JP/Um2HosX1j7XYSTVi8zIs0yatl15HSiq9qfU6oCbxEMm/3uv8kIBWqOJUEDptB m/dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=ob1Wgpl2Kopv0CybxdHv0OESHQJPe9d8UwyYKPxrm+0=; fh=5qXcnY1uiwscfcQi4KCngyoA20/elmEf3d+xb7m84pY=; b=OMxfvbKcwxdMRvIKiaJP6fjMgrjdkV0prTDO7DQoQt4H/KBlTJxT791I9qGXmPrcHT RdxGTTMA1SPsaVcvNXLfOwU6hP0jupLrDfntUC15HcPzZOBddjP02ERpgHc/K+MZnPnt kwrOemp6K7Pt+mRETHdYefB6ygyZbUGsOtY93Z/KPuQg0XQd1i0goLAAZEc6Hmha2Fv+ 0egK43k3+g+8+wwNWQj3fuUuSEXHQXi4INyIIfyWkfYvJ7ToMPnv8mf6+9eJ+pnZ+4Hc Cr4Wh+9mn1zYrtEW7azXW5ayQcsOAkCV8Du/Sh9gWSFKageu669729/G7+zNJnHzmxrn M61A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id kv8-20020a17090328c800b001b8922e82e3si11431723plb.297.2023.09.29.01.10.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 01:10:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 7D6828451EDB; Fri, 29 Sep 2023 01:10:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232816AbjI2IKU convert rfc822-to-8bit (ORCPT + 99 others); Fri, 29 Sep 2023 04:10:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232663AbjI2IKT (ORCPT ); Fri, 29 Sep 2023 04:10:19 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E7171A5 for ; Fri, 29 Sep 2023 01:10:15 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-136-V-eKdlGtNjCLQJKswWmyoQ-1; Fri, 29 Sep 2023 09:10:02 +0100 X-MC-Unique: V-eKdlGtNjCLQJKswWmyoQ-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 29 Sep 2023 09:10:00 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Fri, 29 Sep 2023 09:10:00 +0100 From: David Laight To: "'joao@overdrivepizza.com'" , "pablo@netfilter.org" , "netfilter-devel@vger.kernel.org" , "coreteam@netfilter.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: "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 2/2] Make num_actions unsigned Thread-Topic: [PATCH v2 2/2] Make num_actions unsigned Thread-Index: AQHZ8ObIeUWAs73e2U+3ivRy5uEH5bAxdYzQ Date: Fri, 29 Sep 2023 08:10:00 +0000 Message-ID: <09695e42dfaf4dfe9457aa814fef297e@AcuMS.aculab.com> References: <20230927020221.85292-1-joao@overdrivepizza.com> <20230927020221.85292-3-joao@overdrivepizza.com> In-Reply-To: <20230927020221.85292-3-joao@overdrivepizza.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT 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 pete.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 (pete.vger.email [0.0.0.0]); Fri, 29 Sep 2023 01:10:37 -0700 (PDT) From: joao@overdrivepizza.com > Sent: 27 September 2023 03:02 > > From: Joao Moreira > > Currently, in nft_flow_rule_create function, num_actions is a signed > integer. Yet, it is processed within a loop which increments its > value. To prevent an overflow from occurring, make it unsigned and > also check if it reaches UINT_MAX when being incremented. > > After checking with maintainers, it was mentioned that front-end will > cap the num_actions value and that it is not possible to reach such > condition for an overflow. Yet, for correctness, it is still better to > fix this. > > This issue was observed by the commit author while reviewing a write-up > regarding a CVE within the same subsystem [1]. > > 1 - https://nickgregory.me/post/2022/03/12/cve-2022-25636/ > > Signed-off-by: Joao Moreira > --- > net/netfilter/nf_tables_offload.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/net/netfilter/nf_tables_offload.c b/net/netfilter/nf_tables_offload.c > index 12ab78fa5d84..d25088791a74 100644 > --- a/net/netfilter/nf_tables_offload.c > +++ b/net/netfilter/nf_tables_offload.c > @@ -90,7 +90,8 @@ struct nft_flow_rule *nft_flow_rule_create(struct net *net, > { > struct nft_offload_ctx *ctx; > struct nft_flow_rule *flow; > - int num_actions = 0, err; > + unsigned int num_actions = 0; > + int err; > struct nft_expr *expr; > > expr = nft_expr_first(rule); > @@ -99,6 +100,9 @@ struct nft_flow_rule *nft_flow_rule_create(struct net *net, > expr->ops->offload_action(expr)) > num_actions++; > > + if (num_actions == UINT_MAX) > + return ERR_PTR(-ENOMEM); > + > expr = nft_expr_next(expr); The code is going to 'crash and burn' well before the counter can possibly overflow. nft_expr_next() is ((void *)expr) + expr->ops->size; It is far more likely that has got setup wrong than the count is too big. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)