Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp996042yba; Thu, 4 Apr 2019 02:02:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYvRCRQQpKJMC/GikltV/q7pBkrHjnxpaPrTW0h0QidDPNbPvOLJGsw7e27MaXagsmGFUk X-Received: by 2002:a17:902:442:: with SMTP id 60mr5210478ple.107.1554368541444; Thu, 04 Apr 2019 02:02:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554368541; cv=none; d=google.com; s=arc-20160816; b=u/rRnOYtO06R/wAH2NbVkx/WuleT0C3WDmzdE3mjbnsoUOzsaMi3sMmbenqfngTY8F 9r4zntjWSFW9895v5pJJ4Z7O/1FL6SbcYjfO2FLhY8fHAnmbnQxQVcdvWp5i+BvIF+tu YatbwWhpmFZNyt+fU5vmzkrW0qmyx3LiyTwBQdcqASYRrh54SCHxv3BrzZWqsmtb2dLR QL2l4+k9/vCotptHoJzlZ2OLYGVS7mXQ55qZVtl339MKLFROH05SiRl3ru5CZUUthznD hjqlAO63RqSKbfjI9d9hL898URXtDEqKHbXNxMAFUxGF/hnyGbyuTLWtY4w+4NBxLdYo UBLg== 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=X7XBFF2jtN74uZXBuGlExjN+P7nL5LTPk845ZS19q6w=; b=EhbV/OLlzdDMwFuYumeOl0dSSVqv0l5UnQ1h/MO3AdzsVMbzfdnEGwaXjGA1Mf5urB b0U9EiY02hxrRoJMW5WsbBokGArJanEug3r/crZQWboJPbGwfMSsDdySUF19CzF4sWEe k9uEJnl1UThiwmkpseekaeVKiS4xamR7/0u791+6hcpeM417jVNc9SxUTclrc3Ir5Fsu 3ikippmfV+Rtd3TtA9UwEHc7AyWkzXSImvc8IJbMVzYV1yhxcWI279ChSjH8JYezEluW YN/U4E1YGp+v4Rrm4Y0PXDPsTk8Nf+YOQ9HEzO2hqpo5RatrXdxn/vEaeo++MUpojhgI V5bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UcsATU9O; 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 b6si15152722pgw.70.2019.04.04.02.02.05; Thu, 04 Apr 2019 02:02: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=UcsATU9O; 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 S1731440AbfDDJBc (ORCPT + 99 others); Thu, 4 Apr 2019 05:01:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:38660 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731430AbfDDJB3 (ORCPT ); Thu, 4 Apr 2019 05:01:29 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 DCEAB2147C; Thu, 4 Apr 2019 09:01:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368488; bh=YfOk10ptb9wvE4vNH4VAQ8gxJD74QhSZ0IUivauz3qc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UcsATU9On2GzVw5Epb7jI/2P9SG/AAHylXJamaBXD2aQCkYh3VobijDsT/LsBx7uZ viDvkDYavcgpVM6+UAO43iXpR3ap/DYGDeiUPPUugGZCjtwiFB8Tp6L7IURU0hNP6d 7TIRTaJf8Wv0ewfj1MGammMFecy+fxWqdDs1wr8c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Zhang Yu , Li RongQing , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 4.19 042/187] netfilter: nf_tables: check the result of dereferencing base_chain->stats Date: Thu, 4 Apr 2019 10:46:19 +0200 Message-Id: <20190404084605.063924036@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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. ------------------ [ 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 60f258f2c707..a3850414dba2 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