Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2959861imu; Mon, 19 Nov 2018 08:38:52 -0800 (PST) X-Google-Smtp-Source: AJdET5eo4dHMNMmdW4iB54YWOPoZa7j2VLiJoMUpzSkCvTZq5nUyO70I9qtgSNATTXNv6z6dHKm1 X-Received: by 2002:a63:4d66:: with SMTP id n38mr20809424pgl.270.1542645532466; Mon, 19 Nov 2018 08:38:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542645532; cv=none; d=google.com; s=arc-20160816; b=sjcZnfx1Ix1Un7phSj346C5Qzh4Y0v+fCc/NP0jSA21Obpac4wFwWt9a2KDsVCe0on qjzKIqa8degXwn4gdkKiNcV72Vpx+8Qem2ISdfv9pD29sG8cg55bvcL3TBiJB7Gdgvkq qeboVsvAQD2dIpAhQ4hmk/fq56+JVScYSm9gJuzkFN316YnAqcdufoEWpNepmaFAk++B xBXa72f/EVvDmBsfgTMxrkA/DzFsJ90U4e0XCLZVsqPLscdrx+aPia7TN0PHFHHzv8aW Mdfj8zd1/DwVLSyRhyg7xEbS32GIP3zOK4s4skAf0HNhBVXW9a6n+qMoNvKb5myv/iM0 Yulw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=S8hzkMpQMZHBFLJxtEIMPkj4fKN5n0XoMBcUgmMRgjo=; b=R/rz546uel9EJNKvYnNBBMNF4kvtXlVcPPfN6j3tRUdpGzjcVNX3SEZV+lIML+3ab+ 7izVFNkhFH4X4i1Agk6CHp2yK030eQULupP+Mv4vwDsgz3co2cO1gZMeHw/Y7eFAEL4M hdktzhRpaxkNAr2Ft/fTdNs/Xz/7XKcDzftDrxSVMrVktKULsZ9Jl3lLFVN6HuNeWUeQ Ayf+2YXqJJYHyD/RzHFI6Wl8PvNy9XlHvbO4QWxWMq8HcZUmEycTxJ2OB8pWf+Q3ij3v ZVkID+Eb6UnvJXYXt/fWNsD9AEPbjrJvJMqs6nAeW9s7RG9sZNGiLBlYeuNZmJ1iEqEs YVNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=L1OF7CXp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s17si39008903pgi.513.2018.11.19.08.38.37; Mon, 19 Nov 2018 08:38:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=L1OF7CXp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731802AbeKTDAF (ORCPT + 99 others); Mon, 19 Nov 2018 22:00:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:59828 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730366AbeKTDAE (ORCPT ); Mon, 19 Nov 2018 22:00:04 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 15732214C1; Mon, 19 Nov 2018 16:35:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542645356; bh=nP7/IFVyodYvE7h1GWvYYa7oJLlTcqeIotZYD4KYW3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L1OF7CXp4+/JowghTC6242d5fadiSQALReYuv8sHft+nENeY6YwHfnB9ORUNbdeCN J3pYVFvib8uPq8bMveFpxiLBNfbbenPvHFpMPG/Hlgt1NW6traWg6bkYmQ2eF2Rho1 BD67TnsvE9LB0I0RWoB6x//As7et50bb9vuv/LO0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vasily Khoruzhick , Pablo Neira Ayuso Subject: [PATCH 4.19 105/205] netfilter: conntrack: fix calculation of next bucket number in early_drop Date: Mon, 19 Nov 2018 17:26:52 +0100 Message-Id: <20181119162633.855865262@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162616.586062722@linuxfoundation.org> References: <20181119162616.586062722@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vasily Khoruzhick commit f393808dc64149ccd0e5a8427505ba2974a59854 upstream. If there's no entry to drop in bucket that corresponds to the hash, early_drop() should look for it in other buckets. But since it increments hash instead of bucket number, it actually looks in the same bucket 8 times: hsize is 16k by default (14 bits) and hash is 32-bit value, so reciprocal_scale(hash, hsize) returns the same value for hash..hash+7 in most cases. Fix it by increasing bucket number instead of hash and rename _hash to bucket to avoid future confusion. Fixes: 3e86638e9a0b ("netfilter: conntrack: consider ct netns in early_drop logic") Cc: # v4.7+ Signed-off-by: Vasily Khoruzhick Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_conntrack_core.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -1073,19 +1073,22 @@ static unsigned int early_drop_list(stru return drops; } -static noinline int early_drop(struct net *net, unsigned int _hash) +static noinline int early_drop(struct net *net, unsigned int hash) { - unsigned int i; + unsigned int i, bucket; for (i = 0; i < NF_CT_EVICTION_RANGE; i++) { struct hlist_nulls_head *ct_hash; - unsigned int hash, hsize, drops; + unsigned int hsize, drops; rcu_read_lock(); nf_conntrack_get_ht(&ct_hash, &hsize); - hash = reciprocal_scale(_hash++, hsize); + if (!i) + bucket = reciprocal_scale(hash, hsize); + else + bucket = (bucket + 1) % hsize; - drops = early_drop_list(net, &ct_hash[hash]); + drops = early_drop_list(net, &ct_hash[bucket]); rcu_read_unlock(); if (drops) {