Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1464166ybl; Thu, 22 Aug 2019 15:13:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqzeM1STa80fqX4+68Bcb9SpZfIzTPL19edOH+e/wd6YR1Rihl7Celd2pu2m+E1KhgbgBCWM X-Received: by 2002:a62:ce0e:: with SMTP id y14mr1560605pfg.73.1566512037886; Thu, 22 Aug 2019 15:13:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566512037; cv=none; d=google.com; s=arc-20160816; b=iAxvRKqIJJTI3+84Y9TSWGbXfwKoXi1734Z0cKfpMN4w/LXDo/n6HVChZnArG9F+7I miTQMumKR0y8fgMNW3p+VrAY85228SB2eTwebcAm1YPVE9ux9Aqtx5AKGfmxGyg4Fhlq YsU2uX+vePXunr20NSzRR/DJ8OH/KapipZdldvkcH4HhfVPAt9KeCGmnGWYpXlX0zcZ/ yNBMJR2Y9+wZr1ny9IeMtUWKb+yeM/ltmgO8Ss8ReN6BwSf+IzL8ZaUSSO3VPY7Cfgi7 Uj0g9bB5vEAWswRld+Iz/EgpZFpv8cm8vCsiQ/TLXJTXWw6vxPyR58delIpGJ0PsYqVn h77A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=g5FUYXyTB0uswugZb/VLM0Qg7iRz6LronQx6M8GDyc0=; b=CGHBslyINx8KzS3kM5iSXGOtIVjoItGoOk9GWqOgQA2lj4hIG1JxlXoRljB+VE41tY VBGUDkbgxJG3Oxhrp35b43WAOIVuXqWAUfq7PY6Tv0XXTpaVlLrQq1GIOIK2BeVKfmy3 VWin8KrzmuMJWkFF0BI9l+ACraNDGbGvqA1gh5ymXQ7AObD2Ndy3xkjA6ABzglO76G+d 7owikkmSVPKPZrDruvf9/CPmGr3Gj2eb8OsjsivvEfQ7FPkN4FT4TwQibhDn7kds8Phj bufhwH/GdcAGDmG9PM4Yq1Mub0L7wpimNeXIf8sOYnw8VpX+mNMBzmtTpLYoOXaauG4e omtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QcmfXojB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j22si397495pgb.352.2019.08.22.15.13.42; Thu, 22 Aug 2019 15:13:57 -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=QcmfXojB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390764AbfHVRJY (ORCPT + 99 others); Thu, 22 Aug 2019 13:09:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:59460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390691AbfHVRJM (ORCPT ); Thu, 22 Aug 2019 13:09:12 -0400 Received: from sasha-vm.mshome.net (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A6F2923407; Thu, 22 Aug 2019 17:09:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566493751; bh=iiHpQG4H/gYs9ZpuGOv5Qyo2mnP/gHrFNQJ+ePLCwvU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QcmfXojBtUNwEmDqM3VoN/y9FQJTaI8UNaQmLL2cwOJqkvHQRCvzedwz5Ep8H2ZU3 1MlziILPShMTLGibaC95Ipd1DSnmMtTOYlhYTgcgxemblWRvNgbWmvsA/jCo0d2WSV Vm1xH18TghgBRmeTmxHlATg61H+YaA679ggdIzvs= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dirk Morris , Florian Westphal , Pablo Neira Ayuso , Greg Kroah-Hartman Subject: [PATCH 5.2 104/135] netfilter: conntrack: Use consistent ct id hash calculation Date: Thu, 22 Aug 2019 13:07:40 -0400 Message-Id: <20190822170811.13303-105-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822170811.13303-1-sashal@kernel.org> References: <20190822170811.13303-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.2.10-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.2.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.2.10-rc1 X-KernelTest-Deadline: 2019-08-24T17:07+00:00 X-stable: review X-Patchwork-Hint: Ignore 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(-) diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index f4f9b8344a32d..e343a030ec262 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -453,13 +453,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) { @@ -469,9 +468,10 @@ u32 nf_ct_get_id(const struct nf_conn *ct) 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); -- 2.20.1