Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp217144ybl; Thu, 22 Aug 2019 23:12:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqyXgIGW18K+4wh9bnrQEPMod87JpPkmXCcMW4nG/J/gWcdQLVkgaMmoviX24EcX0CWSgdvY X-Received: by 2002:a63:1f1b:: with SMTP id f27mr2459444pgf.233.1566540741238; Thu, 22 Aug 2019 23:12:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566540741; cv=none; d=google.com; s=arc-20160816; b=Yk6xJD3KFzJwyl5Dk03FWPN9FQd181GyaWny2Y5bL0A9aA7YNTUzzENIqtwqlaNZiu uHNkDcRVfStI26lB2nR0l1h6+7fZNuxjzejeq8+gf9Ns6NH17fxvXxYppsp96/JOVAwR Gng95fu95snLU3q62vfP8lSZ+o0mMp1P61KOznSeQbsP5wBvMkSrH+2DJMUAoLth7N5t 71T1N2avXPPwmQB8PczlhbQZHS9I1p7w/n7Bte4uD7uA9PVyxtfHqlWe01FnJWU08vVm 8qt9dHyDTjon+GGcuh4WtSzc6dk6X0zinBsGOJR9UvjpwiztLlHdAEEl2bWN7QiscqWw gIXA== 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=7EQEOEF02Zmi9z0Ri4sU4MYkEH0oMivlFC0JzKkFwdE=; b=G7fGr3/LauehBrWY2X77wIch2Hv/fzFY6n/P9TNd/5+0/SnQIIfmMO4nFC9wrQxGmg QxtRouIpg/RI9kKBrBbyqT2erGNG7ibg4uXDGSIm5kVMl6LEmDTkUkecbkRt/oxmwzF7 5q94+/i3Re5BIPblIcGHI8Sh3q55YTwM4cROdmD3kHgohhlTz/scIzLk4aSAul1UfIu8 0klEOwKKLYe3UHs4lVPNeSKr5BCFRe4blznRMr4yOhZbE6i8rz5zh1QHFRPzcT7MBIUr JMuqi0qbkyBHATzsFfpvq8PJUD+BaN6GMY4N6EYU3dbRi/aDYyT8dMEHquxzPx8rYTO8 2VGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=N0GocdUv; 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 69si1503013pla.262.2019.08.22.23.12.03; Thu, 22 Aug 2019 23:12:21 -0700 (PDT) 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=N0GocdUv; 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 S2405044AbfHVRje (ORCPT + 99 others); Thu, 22 Aug 2019 13:39:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:45318 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404122AbfHVRYN (ORCPT ); Thu, 22 Aug 2019 13:24:13 -0400 Received: from localhost (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (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 AED0B23400; Thu, 22 Aug 2019 17:24:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566494652; bh=YLSDIMuCDp/pQ8b1bLsyZv4ffLewgbv3UcvNqC6fHM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N0GocdUvDnxbzA8eX9W1Iq8O7X/8fpQdWFfG7m0tbkFLjic2v35acQ5avaj9efaVq HJog6QNp2GVmJUtA3RQhVJLD9CV7F9qKxr04I2ZhkHuhJilWv7qNgClT6ecluS2g8R 363u5BRPy0+7FGGa+Fy/wmTaNwoapdxkzPC8ftC4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dirk Morris , Florian Westphal , Pablo Neira Ayuso Subject: [PATCH 4.9 093/103] netfilter: conntrack: Use consistent ct id hash calculation Date: Thu, 22 Aug 2019 10:19:21 -0700 Message-Id: <20190822171732.933803946@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190822171728.445189830@linuxfoundation.org> References: <20190822171728.445189830@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Dirk Morris commit 656c8e9cc1badbc18eefe6ba01d33ebbcae61b9a upstream. Change ct id hash calculation to only use invariants. Currently the ct id hash calculation is based on some fields that can change in the lifetime on a conntrack entry in some corner cases. The current hash uses the whole tuple which contains an hlist pointer which will change when the conntrack is placed on the dying list resulting in a ct id change. This patch also removes the reply-side tuple and extension pointer from the hash calculation so that the ct id will will not change from initialization until confirmation. Fixes: 3c79107631db1f7 ("netfilter: ctnetlink: don't use conntrack/expect object addresses as id") Signed-off-by: Dirk Morris Acked-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_conntrack_core.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -308,13 +308,12 @@ EXPORT_SYMBOL_GPL(nf_ct_invert_tuple); * table location, we assume id gets exposed to userspace. * * Following nf_conn items do not change throughout lifetime - * of the nf_conn after it has been committed to main hash table: + * of the nf_conn: * * 1. nf_conn address - * 2. nf_conn->ext address - * 3. nf_conn->master address (normally NULL) - * 4. tuple - * 5. the associated net namespace + * 2. nf_conn->master address (normally NULL) + * 3. the associated net namespace + * 4. the original direction tuple */ u32 nf_ct_get_id(const struct nf_conn *ct) { @@ -324,9 +323,10 @@ u32 nf_ct_get_id(const struct nf_conn *c net_get_random_once(&ct_id_seed, sizeof(ct_id_seed)); a = (unsigned long)ct; - b = (unsigned long)ct->master ^ net_hash_mix(nf_ct_net(ct)); - c = (unsigned long)ct->ext; - d = (unsigned long)siphash(&ct->tuplehash, sizeof(ct->tuplehash), + b = (unsigned long)ct->master; + c = (unsigned long)nf_ct_net(ct); + d = (unsigned long)siphash(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple, + sizeof(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple), &ct_id_seed); #ifdef CONFIG_64BIT return siphash_4u64((u64)a, (u64)b, (u64)c, (u64)d, &ct_id_seed);