Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5654941img; Wed, 27 Mar 2019 12:32:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqzGgI0j/IetIpNABeJ0jP8LHLiQzuJxcIaMOkau/DeRACTbPMxI2Rjma2XFNdhI9yoY5tZV X-Received: by 2002:a65:6489:: with SMTP id e9mr20735794pgv.364.1553715149800; Wed, 27 Mar 2019 12:32:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553715149; cv=none; d=google.com; s=arc-20160816; b=DChRNBFClRY3O+qPcBN6HeeLtOHbmbeCYR9O5xOr2hOwHvSVIsxkwY6txCh01i5+6S eemigtTSOS1ZDT4riJI2CUeuoIv/kXlj+/mDR/soe1Qyce99pBqBhrKArktKUFjDAMf2 ek6SMP4ahhgza3AFq7L/1MiB+nxLXXrTDjrxC2xhwTNiNMj94SM8vUnSNqlDH8xFsFrb +iCXCCwXOdOnJ4mKvn4b0byEBNpUhAbi+22J25Hjn4AzUGB8bv47Y4BljpAjRGiCwrqA jhnRkCPFuY48IPcHaeiwtc7Sa41Sa+CnGGtKkUNm+lDE77lE2OJ3TQ1luyXq0QPIdzwu +2ew== 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=1noQCef17rxRYtY0hLgbLZpgqy39MY/hycsgVjMnqBo=; b=nd0g2N7TEDeCAajwDqUMHsRx+onAWbKXfPWd/F47Qxnd/dnymzyBUOwPcDqXUTQk1z KjgicyOsGlBVpN23gYyM7xlqnaa/4/PQ0gDIiI7XT9ckyMTktNX8mJUToMv4eFEMtA96 GIo8SD0j4gNUYigU24OIlPbJ5ss2G639reOo7AAAD4cV5uKuaZMn0TLtSJfI9ChLggd8 XIWNP7PuavnIW8JkZ9P8SbFxQDCQxX4wgmCC9FxplPmZM8SLQOo5atKpEtkiHioFZ+cV SgbKlhINnApxtJcdWSvwYqHUm+1Zi3RtRQuGSYc3SPs/QkuCU1iIRL00njzrE8EFTjo/ cFNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CpPSkokY; 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 f124si6769672pgc.596.2019.03.27.12.32.14; Wed, 27 Mar 2019 12:32:29 -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=CpPSkokY; 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 S2387572AbfC0TaZ (ORCPT + 99 others); Wed, 27 Mar 2019 15:30:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:43866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732562AbfC0SDe (ORCPT ); Wed, 27 Mar 2019 14:03:34 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 B81222184E; Wed, 27 Mar 2019 18:03:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709813; bh=VmseP4cW3fe9niHuW0Is9N0JXM0IwEDP0nn1p6xWHdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CpPSkokY9Ukofq3AalGXgtr739MToPWjtjfFblyD1l0DN4bb8QFWb6Qwq5e4JPBGw VO43NlNqmWevUFsD30H4Z5aGji+SleYgtkHxpPncPTxteWrb670y1tp3l+Si+4sAqP jY6vWz28XcF13rXcdDDh+h0FvgZKQj9cMLmAv5MU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Li RongQing , Eric Dumazet , Zhang Yu , Pablo Neira Ayuso , Sasha Levin , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 053/262] netfilter: nf_tables: check the result of dereferencing base_chain->stats Date: Wed, 27 Mar 2019 13:58:28 -0400 Message-Id: <20190327180158.10245-53-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 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: Li RongQing [ Upstream commit a9f5e78c403d2d62ade4f4c85040efc85f4049b8 ] Check the result of dereferencing base_chain->stats, instead of result of this_cpu_ptr with NULL. base_chain->stats maybe be changed to NULL when a chain is updated and a new NULL counter can be attached. And we do not need to check returning of this_cpu_ptr since base_chain->stats is from percpu allocator if it is non-NULL, this_cpu_ptr returns a valid value. And fix two sparse error by replacing rcu_access_pointer and rcu_dereference with READ_ONCE under rcu_read_lock. Thanks for Eric's help to finish this patch. Fixes: 009240940e84c1 ("netfilter: nf_tables: don't assume chain stats are set when jumplabel is set") Signed-off-by: Eric Dumazet Signed-off-by: Zhang Yu Signed-off-by: Li RongQing Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nf_tables_core.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/net/netfilter/nf_tables_core.c b/net/netfilter/nf_tables_core.c index a50500232b0a..7e8dae82ca52 100644 --- a/net/netfilter/nf_tables_core.c +++ b/net/netfilter/nf_tables_core.c @@ -98,21 +98,23 @@ static noinline void nft_update_chain_stats(const struct nft_chain *chain, const struct nft_pktinfo *pkt) { struct nft_base_chain *base_chain; + struct nft_stats __percpu *pstats; struct nft_stats *stats; base_chain = nft_base_chain(chain); - if (!rcu_access_pointer(base_chain->stats)) - return; - local_bh_disable(); - stats = this_cpu_ptr(rcu_dereference(base_chain->stats)); - if (stats) { + rcu_read_lock(); + pstats = READ_ONCE(base_chain->stats); + if (pstats) { + local_bh_disable(); + stats = this_cpu_ptr(pstats); u64_stats_update_begin(&stats->syncp); stats->pkts++; stats->bytes += pkt->skb->len; u64_stats_update_end(&stats->syncp); + local_bh_enable(); } - local_bh_enable(); + rcu_read_unlock(); } struct nft_jumpstack { -- 2.19.1