{"id":811736,"url":"http://patchwork.ozlabs.org/api/1.2/patches/811736/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/patch/1504892748-1605-10-git-send-email-pablo@netfilter.org/","project":{"id":26,"url":"http://patchwork.ozlabs.org/api/1.2/projects/26/?format=json","name":"Netfilter Development","link_name":"netfilter-devel","list_id":"netfilter-devel.vger.kernel.org","list_email":"netfilter-devel@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1504892748-1605-10-git-send-email-pablo@netfilter.org>","list_archive_url":null,"date":"2017-09-08T17:45:48","name":"[9/9] netfilter: xt_hashlimit: fix build error caused by 64bit division","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"7822ac65e8f5bd90872f0599f9d0f484293db894","submitter":{"id":1315,"url":"http://patchwork.ozlabs.org/api/1.2/people/1315/?format=json","name":"Pablo Neira Ayuso","email":"pablo@netfilter.org"},"delegate":{"id":6139,"url":"http://patchwork.ozlabs.org/api/1.2/users/6139/?format=json","username":"pablo","first_name":"Pablo","last_name":"Neira","email":"pablo@netfilter.org"},"mbox":"http://patchwork.ozlabs.org/project/netfilter-devel/patch/1504892748-1605-10-git-send-email-pablo@netfilter.org/mbox/","series":[{"id":2261,"url":"http://patchwork.ozlabs.org/api/1.2/series/2261/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/list/?series=2261","date":"2017-09-08T17:45:46","name":"[1/9] netfilter: ipvs: fix the issue that sctp_conn_schedule drops non-INIT packet","version":1,"mbox":"http://patchwork.ozlabs.org/series/2261/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/811736/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/811736/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netfilter-devel-owner@vger.kernel.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netfilter-devel-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xpl9v16zdz9sBW\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSat,  9 Sep 2017 03:46:27 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1756791AbdIHRqY (ORCPT <rfc822;incoming@patchwork.ozlabs.org>);\n\tFri, 8 Sep 2017 13:46:24 -0400","from mail.us.es ([193.147.175.20]:54490 \"EHLO mail.us.es\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1756735AbdIHRqF (ORCPT <rfc822; netfilter-devel@vger.kernel.org>);\n\tFri, 8 Sep 2017 13:46:05 -0400","from antivirus1-rhel7.int (unknown [192.168.2.11])\n\tby mail.us.es (Postfix) with ESMTP id E05578D0509\n\tfor <netfilter-devel@vger.kernel.org>;\n\tFri,  8 Sep 2017 19:45:34 +0200 (CEST)","from antivirus1-rhel7.int (localhost [127.0.0.1])\n\tby antivirus1-rhel7.int (Postfix) with ESMTP id D2552B502E\n\tfor <netfilter-devel@vger.kernel.org>;\n\tFri,  8 Sep 2017 19:45:34 +0200 (CEST)","by antivirus1-rhel7.int (Postfix, from userid 99)\n\tid C7F6EB5028; Fri,  8 Sep 2017 19:45:34 +0200 (CEST)","from antivirus1-rhel7.int (localhost [127.0.0.1])\n\tby antivirus1-rhel7.int (Postfix) with ESMTP id B5224B5026;\n\tFri,  8 Sep 2017 19:45:32 +0200 (CEST)","from 192.168.1.97 (192.168.1.97) by antivirus1-rhel7.int\n\t(F-Secure/fsigk_smtp/550/antivirus1-rhel7.int); \n\tFri, 08 Sep 2017 19:45:32 +0200 (CEST)","from salvia.here (129.166.216.87.static.jazztel.es\n\t[87.216.166.129]) (Authenticated sender: pneira@us.es)\n\tby entrada.int (Postfix) with ESMTPA id 5B4D344581E0;\n\tFri,  8 Sep 2017 19:45:32 +0200 (CEST)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.1 (2015-04-28) on\n\tantivirus1-rhel7.int","X-Spam-Level":"","X-Spam-Status":"No, score=-108.2 required=7.5 tests=ALL_TRUSTED,BAYES_50,\n\tSMTPAUTH_US2,USER_IN_WHITELIST autolearn=disabled version=3.4.1","X-Virus-Status":"clean(F-Secure/fsigk_smtp/550/antivirus1-rhel7.int)","X-SMTPAUTHUS":"auth mail.us.es","From":"Pablo Neira Ayuso <pablo@netfilter.org>","To":"netfilter-devel@vger.kernel.org","Cc":"davem@davemloft.net, netdev@vger.kernel.org","Subject":"[PATCH 9/9] netfilter: xt_hashlimit: fix build error caused by\n\t64bit division","Date":"Fri,  8 Sep 2017 19:45:48 +0200","Message-Id":"<1504892748-1605-10-git-send-email-pablo@netfilter.org>","X-Mailer":"git-send-email 2.1.4","In-Reply-To":"<1504892748-1605-1-git-send-email-pablo@netfilter.org>","References":"<1504892748-1605-1-git-send-email-pablo@netfilter.org>","X-Virus-Scanned":"ClamAV using ClamSMTP","Sender":"netfilter-devel-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netfilter-devel.vger.kernel.org>","X-Mailing-List":"netfilter-devel@vger.kernel.org"},"content":"From: Vishwanath Pai <vpai@akamai.com>\n\n64bit division causes build/link errors on 32bit architectures. It\nprints out error messages like:\n\nERROR: \"__aeabi_uldivmod\" [net/netfilter/xt_hashlimit.ko] undefined!\n\nThe value of avg passed through by userspace in BYTE mode cannot exceed\nU32_MAX. Which means 64bit division in user2rate_bytes is unnecessary.\nTo fix this I have changed the type of param 'user' to u32.\n\nSince anything greater than U32_MAX is an invalid input we error out in\nhashlimit_mt_check_common() when this is the case.\n\nChanges in v2:\n\tMaking return type as u32 would cause an overflow for small\n\tvalues of 'user' (for example 2, 3 etc). To avoid this I bumped up\n\t'r' to u64 again as well as the return type. This is OK since the\n\tvariable that stores the result is u64. We still avoid 64bit\n\tdivision here since 'user' is u32.\n\nFixes: bea74641e378 (\"netfilter: xt_hashlimit: add rate match mode\")\nSigned-off-by: Vishwanath Pai <vpai@akamai.com>\nSigned-off-by: Pablo Neira Ayuso <pablo@netfilter.org>\n---\n net/netfilter/xt_hashlimit.c | 12 +++++++-----\n 1 file changed, 7 insertions(+), 5 deletions(-)","diff":"diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c\nindex 962ea4a63d9f..5da8746f7b88 100644\n--- a/net/netfilter/xt_hashlimit.c\n+++ b/net/netfilter/xt_hashlimit.c\n@@ -35,6 +35,7 @@\n #include <linux/netfilter_ipv6/ip6_tables.h>\n #include <linux/netfilter/xt_hashlimit.h>\n #include <linux/mutex.h>\n+#include <linux/kernel.h>\n \n MODULE_LICENSE(\"GPL\");\n MODULE_AUTHOR(\"Harald Welte <laforge@netfilter.org>\");\n@@ -527,12 +528,12 @@ static u64 user2rate(u64 user)\n \t}\n }\n \n-static u64 user2rate_bytes(u64 user)\n+static u64 user2rate_bytes(u32 user)\n {\n \tu64 r;\n \n-\tr = user ? 0xFFFFFFFFULL / user : 0xFFFFFFFFULL;\n-\tr = (r - 1) << 4;\n+\tr = user ? U32_MAX / user : U32_MAX;\n+\tr = (r - 1) << XT_HASHLIMIT_BYTE_SHIFT;\n \treturn r;\n }\n \n@@ -588,7 +589,8 @@ static void rateinfo_init(struct dsthash_ent *dh,\n \t\tdh->rateinfo.prev_window = 0;\n \t\tdh->rateinfo.current_rate = 0;\n \t\tif (hinfo->cfg.mode & XT_HASHLIMIT_BYTES) {\n-\t\t\tdh->rateinfo.rate = user2rate_bytes(hinfo->cfg.avg);\n+\t\t\tdh->rateinfo.rate =\n+\t\t\t\tuser2rate_bytes((u32)hinfo->cfg.avg);\n \t\t\tif (hinfo->cfg.burst)\n \t\t\t\tdh->rateinfo.burst =\n \t\t\t\t\thinfo->cfg.burst * dh->rateinfo.rate;\n@@ -870,7 +872,7 @@ static int hashlimit_mt_check_common(const struct xt_mtchk_param *par,\n \n \t/* Check for overflow. */\n \tif (revision >= 3 && cfg->mode & XT_HASHLIMIT_RATE_MATCH) {\n-\t\tif (cfg->avg == 0) {\n+\t\tif (cfg->avg == 0 || cfg->avg > U32_MAX) {\n \t\t\tpr_info(\"hashlimit invalid rate\\n\");\n \t\t\treturn -ERANGE;\n \t\t}\n","prefixes":["9/9"]}