Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp5213369pxb; Tue, 28 Sep 2021 13:07:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwf3BA9OtkCzYP0/bHl8psK/O5zFWhsbjO3S8yoAvdYqGv4subBxAiXXdcPcpoDb1ZC1VSQ X-Received: by 2002:a17:90a:9d89:: with SMTP id k9mr1965297pjp.0.1632859623474; Tue, 28 Sep 2021 13:07:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632859623; cv=none; d=google.com; s=arc-20160816; b=Wy6B2J93j37nuJinlCd3+F1wEbV6UTRSCivDpAGJ9wxDLE1CsrPXP5CUHvh5f3zlHh lo8sc4PmJHw9/rZgAZ2ts4vpSlVP5qY+vvSIm9IW/QCJXcLOT8M7+BiUy7Wp7QGBXZ67 833vTxX00rgjAWC7/A0EFinoiZBR4sTmeMZ9vcGTC8o/HN1alGYg8SNrDdFi5wetB9wW Edm0y/TYcJPshdrFtlEB1t4I4Cefb2BA+/GZHr5e0uE4n0Kt+rgteKJLKqDgfcIlDDwe /IgM1Z+9fFhCm2o2kjM5XUjIYZzi54fQSvZHG8AI+dIFk6/VUv/Vuj5fsGBIJzTBlW55 Oy+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=UKdQCGuGylveHSkWSJx0DgOlT9FbL51+76K0JcHew8E=; b=Y3fgTtgjZpj4ys5FbExehhdwDIBMuZD1TPwdUuytrnbac/Um2DdRf9DoEBeOWUnPSt 4p4+h6y2Avz+4/UuQ35exCa/N0rzBPuCEAiioV5WzISqtjHxGMWksMeuv2kPzh9plfyD I6KQn8d4KXit7dmz+xWDSAeBTYiN4xK0hhmfnTYt1vKpcmlEEbtO3qFE2WL/ZH+u1mqE kDgtL0QnjMJ8Wq6HEY9yuaaG3Z/TtOZHB2SSwIQHb0NHT8p0+h/o7g1hjYWgOh5WqE8w 6tpbDy+5QJGHmWZGsuER1FZQM3sNBuz8++WezjDjYY5Fr44+tfkNNtA7mum8jYE737xJ 4AuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ux5mxk8+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z9si3913419pjc.163.2021.09.28.13.06.49; Tue, 28 Sep 2021 13:07:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ux5mxk8+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242626AbhI1UE0 (ORCPT + 99 others); Tue, 28 Sep 2021 16:04:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:36626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242534AbhI1UEZ (ORCPT ); Tue, 28 Sep 2021 16:04:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 74A6D610E6; Tue, 28 Sep 2021 20:02:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632859365; bh=JUbEawgwP2c3g8ePRDbJDUMS5ioHTfLNboJDo0lgTFU=; h=Date:From:To:Cc:Subject:From; b=Ux5mxk8+u9s/JuBAUe8lOapvH73pC8IDGMANlVx6y8oPhvgbvBvHWer4TncIe4O5P zRAc9E+j11GMc534Us0lyChK0krofQdH61wQYT+tlB96ajEswJlW5LiB//1WTO2L5f OMdrtwjp0duaQIPR+qZIqgAi6Qa8l2np6wXwolZtpIwLuqrEayWPXVgfeSukyRPcND nY0jFdRZ4a8XxMmYjRaDR7p3FjeSk8z6pkePYifJt/My7UG/ldZJhgQVzS3VbSERG8 OBVMvKrRhltAQVgX/vRxXj76KXsBAURq7425SEWqtcbmF2tEpoF58LKK2rfiAYS5sI 9KKrJqsNYsFsw== Date: Tue, 28 Sep 2021 15:06:47 -0500 From: "Gustavo A. R. Silva" To: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , Roopa Prabhu , Nikolay Aleksandrov , "David S. Miller" , Jakub Kicinski Cc: netfilter-devel@vger.kernel.org, coreteam@netfilter.org, bridge@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][net-next] netfilter: ebtables: use array_size() helper in copy_{from,to}_user() Message-ID: <20210928200647.GA266402@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use array_size() helper instead of the open-coded version in copy_{from,to}_user(). These sorts of multiplication factors need to be wrapped in array_size(). Link: https://github.com/KSPP/linux/issues/160 Signed-off-by: Gustavo A. R. Silva --- net/bridge/netfilter/ebtables.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c index 83d1798dfbb4..32fa05ec4a6d 100644 --- a/net/bridge/netfilter/ebtables.c +++ b/net/bridge/netfilter/ebtables.c @@ -1071,7 +1071,7 @@ static int do_replace_finish(struct net *net, struct ebt_replace *repl, */ if (repl->num_counters && copy_to_user(repl->counters, counterstmp, - repl->num_counters * sizeof(struct ebt_counter))) { + array_size(repl->num_counters, sizeof(struct ebt_counter)))) { /* Silent error, can't fail, new table is already in place */ net_warn_ratelimited("ebtables: counters copy to user failed while replacing table\n"); } @@ -1399,7 +1399,8 @@ static int do_update_counters(struct net *net, const char *name, goto unlock_mutex; } - if (copy_from_user(tmp, counters, num_counters * sizeof(*counters))) { + if (copy_from_user(tmp, counters, + array_size(num_counters, sizeof(*counters)))) { ret = -EFAULT; goto unlock_mutex; } @@ -1532,7 +1533,7 @@ static int copy_counters_to_user(struct ebt_table *t, write_unlock_bh(&t->lock); if (copy_to_user(user, counterstmp, - nentries * sizeof(struct ebt_counter))) + array_size(nentries, sizeof(struct ebt_counter)))) ret = -EFAULT; vfree(counterstmp); return ret; -- 2.27.0