{"id":812126,"url":"http://patchwork.ozlabs.org/api/patches/812126/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/patch/1505043701-13255-1-git-send-email-geert@linux-m68k.org/","project":{"id":26,"url":"http://patchwork.ozlabs.org/api/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":"<1505043701-13255-1-git-send-email-geert@linux-m68k.org>","list_archive_url":null,"date":"2017-09-10T11:41:41","name":"netfilter: nat: Do not use ARRAY_SIZE() on spinlocks to fix zero div","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"43d1c8677de96d6acd3454135c87be90dbda5dd7","submitter":{"id":703,"url":"http://patchwork.ozlabs.org/api/people/703/?format=json","name":"Geert Uytterhoeven","email":"geert@linux-m68k.org"},"delegate":{"id":6139,"url":"http://patchwork.ozlabs.org/api/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/1505043701-13255-1-git-send-email-geert@linux-m68k.org/mbox/","series":[{"id":2393,"url":"http://patchwork.ozlabs.org/api/series/2393/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/list/?series=2393","date":"2017-09-10T11:41:41","name":"netfilter: nat: Do not use ARRAY_SIZE() on spinlocks to fix zero div","version":1,"mbox":"http://patchwork.ozlabs.org/series/2393/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/812126/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/812126/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 3xqq0L16kSz9sDB\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSun, 10 Sep 2017 21:41:54 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751537AbdIJLlq (ORCPT <rfc822;incoming@patchwork.ozlabs.org>);\n\tSun, 10 Sep 2017 07:41:46 -0400","from michel.telenet-ops.be ([195.130.137.88]:53732 \"EHLO\n\tmichel.telenet-ops.be\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1751498AbdIJLlo (ORCPT\n\t<rfc822;netfilter-devel@vger.kernel.org>);\n\tSun, 10 Sep 2017 07:41:44 -0400","from ayla.of.borg ([84.195.106.246])\n\tby michel.telenet-ops.be with bizsmtp\n\tid 7nhi1w0085JzmfG06nhiuW; Sun, 10 Sep 2017 13:41:43 +0200","from ramsan.of.borg ([192.168.97.29] helo=ramsan)\n\tby ayla.of.borg with esmtp (Exim 4.86_2)\n\t(envelope-from <geert@linux-m68k.org>)\n\tid 1dr0cL-0000u7-7p; Sun, 10 Sep 2017 13:41:37 +0200","from geert by ramsan with local (Exim 4.86_2)\n\t(envelope-from <geert@linux-m68k.org>)\n\tid 1dr0cQ-0003ST-3K; Sun, 10 Sep 2017 13:41:42 +0200"],"From":"Geert Uytterhoeven <geert@linux-m68k.org>","To":"Pablo Neira Ayuso <pablo@netfilter.org>,\n\tJozsef Kadlecsik <kadlec@blackhole.kfki.hu>,\n\tFlorian Westphal <fw@strlen.de>, \"David S . Miller\" <davem@davemloft.net>","Cc":"Arnd Bergmann <arnd@arndb.de>, netfilter-devel@vger.kernel.org,\n\tcoreteam@netfilter.org, netdev@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org, Geert Uytterhoeven <geert@linux-m68k.org>","Subject":"[PATCH] netfilter: nat: Do not use ARRAY_SIZE() on spinlocks to fix\n\tzero div","Date":"Sun, 10 Sep 2017 13:41:41 +0200","Message-Id":"<1505043701-13255-1-git-send-email-geert@linux-m68k.org>","X-Mailer":"git-send-email 2.7.4","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","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":"If no spinlock debugging options (CONFIG_GENERIC_LOCKBREAK,\nCONFIG_DEBUG_SPINLOCK, CONFIG_DEBUG_LOCK_ALLOC) are enabled on a UP\nplatform (e.g. m68k defconfig), arch_spinlock_t is an empty struct,\nhence using ARRAY_SIZE(nf_nat_locks) causes a division by zero:\n\n    net/netfilter/nf_nat_core.c: In function ‘nf_nat_setup_info’:\n    net/netfilter/nf_nat_core.c:432: warning: division by zero\n    net/netfilter/nf_nat_core.c: In function ‘__nf_nat_cleanup_conntrack’:\n    net/netfilter/nf_nat_core.c:535: warning: division by zero\n    net/netfilter/nf_nat_core.c:537: warning: division by zero\n    net/netfilter/nf_nat_core.c: In function ‘nf_nat_init’:\n    net/netfilter/nf_nat_core.c:810: warning: division by zero\n    net/netfilter/nf_nat_core.c:811: warning: division by zero\n    net/netfilter/nf_nat_core.c:824: warning: division by zero\n\nFix this by using the CONNTRACK_LOCKS definition instead.\n\nSuggested-by: Florian Westphal <fw@strlen.de>\nFixes: 8073e960a03bf7b5 (\"netfilter: nat: use keyed locks\")\nSigned-off-by: Geert Uytterhoeven <geert@linux-m68k.org>\n---\n net/netfilter/nf_nat_core.c | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)","diff":"diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c\nindex f393a7086025f6c5..af8345fc4fbde30a 100644\n--- a/net/netfilter/nf_nat_core.c\n+++ b/net/netfilter/nf_nat_core.c\n@@ -429,7 +429,7 @@ nf_nat_setup_info(struct nf_conn *ct,\n \n \t\tsrchash = hash_by_src(net,\n \t\t\t\t      &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);\n-\t\tlock = &nf_nat_locks[srchash % ARRAY_SIZE(nf_nat_locks)];\n+\t\tlock = &nf_nat_locks[srchash % CONNTRACK_LOCKS];\n \t\tspin_lock_bh(lock);\n \t\thlist_add_head_rcu(&ct->nat_bysource,\n \t\t\t\t   &nf_nat_bysource[srchash]);\n@@ -532,9 +532,9 @@ static void __nf_nat_cleanup_conntrack(struct nf_conn *ct)\n \tunsigned int h;\n \n \th = hash_by_src(nf_ct_net(ct), &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);\n-\tspin_lock_bh(&nf_nat_locks[h % ARRAY_SIZE(nf_nat_locks)]);\n+\tspin_lock_bh(&nf_nat_locks[h % CONNTRACK_LOCKS]);\n \thlist_del_rcu(&ct->nat_bysource);\n-\tspin_unlock_bh(&nf_nat_locks[h % ARRAY_SIZE(nf_nat_locks)]);\n+\tspin_unlock_bh(&nf_nat_locks[h % CONNTRACK_LOCKS]);\n }\n \n static int nf_nat_proto_clean(struct nf_conn *ct, void *data)\n@@ -807,8 +807,8 @@ static int __init nf_nat_init(void)\n \n \t/* Leave them the same for the moment. */\n \tnf_nat_htable_size = nf_conntrack_htable_size;\n-\tif (nf_nat_htable_size < ARRAY_SIZE(nf_nat_locks))\n-\t\tnf_nat_htable_size = ARRAY_SIZE(nf_nat_locks);\n+\tif (nf_nat_htable_size < CONNTRACK_LOCKS)\n+\t\tnf_nat_htable_size = CONNTRACK_LOCKS;\n \n \tnf_nat_bysource = nf_ct_alloc_hashtable(&nf_nat_htable_size, 0);\n \tif (!nf_nat_bysource)\n@@ -821,7 +821,7 @@ static int __init nf_nat_init(void)\n \t\treturn ret;\n \t}\n \n-\tfor (i = 0; i < ARRAY_SIZE(nf_nat_locks); i++)\n+\tfor (i = 0; i < CONNTRACK_LOCKS; i++)\n \t\tspin_lock_init(&nf_nat_locks[i]);\n \n \tnf_ct_helper_expectfn_register(&follow_master_nat);\n","prefixes":[]}