Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2278327rdh; Tue, 26 Sep 2023 19:39:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwGa1X/58iADk9iWHkPtLIFAflp8ql4ymBlMdkSiRpqkbDQQe9SgxNsbPka+ey9qh8RxIR X-Received: by 2002:a67:f9d4:0:b0:44e:9313:b045 with SMTP id c20-20020a67f9d4000000b0044e9313b045mr842836vsq.7.1695782389562; Tue, 26 Sep 2023 19:39:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695782389; cv=none; d=google.com; s=arc-20160816; b=lVA/tnWbJtlL9tBC+NuNSl7ghgiQUSkYlOvr2aQSD5CLC9+0LpMpyg1G5AiB4DO7fB lrVIVapOJR71j+kI0+iTJPefhJibl0pAjWcLhdBBS4aBZH8ongwr5CkKn0sNwHGjhGlU UVyy5cXxJv6AIr2bCVevsV3x4BHyCwjgnhUwfP+/HfhMPQiCZ+elJDrE5VcOMXp3MbyD Jeuuq5nN9ehKNQu9pNFgKmwQITu9EOmZ2p294L9YaQzaSAKXvUID6Jen7ySXpQqwAZJ9 e8uUklxM80cNAvVEenues0ohfnFkdSwTzViv4Z23UnDl0KFBTS3aDECKsgzSRB9MImc4 DxTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=BECYdLMr1wBb4zAkdQz8RuMU4pvnMnldMiTtVFXggh8=; fh=BI+T4F8SA0SHDb6m7HWfv63JWeI34VTzFV+4LHBcWNU=; b=f/03vsQxRUK8IX7KAsXrosV+Bf1kfxpOQPq2At48MGJrh5sdUgWI2754sVSaRAHkMI sJqFZkil+k6yZoPHz9ei4OqVyhIQ2eXLqW9P1+Xv7GHRnHgGbBwM2q8rRtuVGUq/BoFg +S/TQHOTtYRdelL3NzZ1LgSvfpqUwGLB35WyjBGv0wHMDv699O0SlFp+ps6khcavc68G Ey3QbGWcDRFmJX+F1Ve+Eru7veghw6Jq0iib1LllDP/RSu0Z8mhzMAJ5YEiS2GlPbup3 ZPn9G3IjyhZjq8qICSA1XS3HlUpk2H9YusyN8JjtcJ3Htosj0I7hUCMvoGIfHA8/Ty6z sxfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id h11-20020a65480b000000b00564a1716ebbsi14254744pgs.697.2023.09.26.19.39.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 19:39:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 258E581B1782; Tue, 26 Sep 2023 19:39:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231822AbjI0Cjk (ORCPT + 99 others); Tue, 26 Sep 2023 22:39:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229993AbjI0Chj (ORCPT ); Tue, 26 Sep 2023 22:37:39 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 759641C26A; Tue, 26 Sep 2023 19:02:54 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6600,9927,10845"; a="385565329" X-IronPort-AV: E=Sophos;i="6.03,179,1694761200"; d="scan'208";a="385565329" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2023 19:02:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10845"; a="725628814" X-IronPort-AV: E=Sophos;i="6.03,179,1694761200"; d="scan'208";a="725628814" Received: from pinksteam.jf.intel.com ([10.165.239.231]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2023 19:02:37 -0700 From: joao@overdrivepizza.com To: pablo@netfilter.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, joao@overdrivepizza.com 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: [PATCH v2 0/2] Prevent potential write out of bounds Date: Tue, 26 Sep 2023 19:02:19 -0700 Message-ID: <20230927020221.85292-1-joao@overdrivepizza.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 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 agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 26 Sep 2023 19:39:45 -0700 (PDT) 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]. 1 - https://nickgregory.me/post/2022/03/12/cve-2022-25636/ Tks, Joao Moreira (2): Make loop indexes unsigned Make num_actions unsigned net/core/flow_offload.c | 4 ++-- net/netfilter/nf_tables_offload.c | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) -- 2.42.0