Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4486677ybx; Mon, 4 Nov 2019 14:13:55 -0800 (PST) X-Google-Smtp-Source: APXvYqxCZd01hU6rpy54ouaYn8sZqI7yTFmPga4KZKnQw3Waq6y8Nc7oNSnRNoLPC/JoQGTENSk8 X-Received: by 2002:a50:f05c:: with SMTP id u28mr31772246edl.265.1572905635700; Mon, 04 Nov 2019 14:13:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905635; cv=none; d=google.com; s=arc-20160816; b=kWoqQIGakUpvHCM9Q5xNY+0n8yV1n6ehbkTwRXkpVXEaHH0NaqyoVxoPgrIwnh7Jvm dostcr3DhSeeV2SwQmHbZDj2pDyXDGS00rMpgdT2Vi2HHBdm8k+i/uSbIY1jLIuoYRq+ aPZ11YyYhOejw8YJr2fn3AeSLMDwqyOLgrRuScYVfX54Euw8T+eN6i8NF5SnZMcKEzBD ukbM2AvhWWHuOrXE/FeFYAFVfGVrSTWoth1133uLNElvd/+/J3AS51vHY06fBCjipKeT 64Ci1vFRtxVDEtEuhhEVKjnaaT3xTfW14eKqXGwdNcAL9H5c85qYNOP2iCdYumiq4Lwy 1mew== 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=ZEi2OAjSHXUTBZ6t1xh7ufEobEhobeyOkuVN1oishvA=; b=uMtbz7bfqpTGifqov3Ss+eMvC00TYGcWPfcpEZDfO9kip8fyRxKX00JOpSTIE9nGKi 8Gr00VJztBSmtyV4mGZu5qE+x0DW/Acsph0ugC1Bzglmmf1Un6t6t1JWrmIbWs8rqBAX CMPvwCU1pFeheFi7fRBTLOymHNa3JfdVm2lVs5iNM8Ze6OpFB0+uh04Yxt7nol88JxuJ hl/1RCTaUZG3Ht3Bg9jfxdLivBZ4i4RwGPO5kYV6bv4IPT9Y8pU1QeNLhswP2eC4FZmw D/MVPTosxrxNmTKIqmxwCjdARnAbTQk+iRC9p7xKEQ4RmWnX5VjzquDSjeQJtZFXrmMH +Xaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HE1ijT9i; 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 e12si1541025ejx.169.2019.11.04.14.13.32; Mon, 04 Nov 2019 14:13:55 -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=HE1ijT9i; 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 S2390604AbfKDWLB (ORCPT + 99 others); Mon, 4 Nov 2019 17:11:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:44222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390255AbfKDWK6 (ORCPT ); Mon, 4 Nov 2019 17:10:58 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (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 314F3205C9; Mon, 4 Nov 2019 22:10:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572905456; bh=wII4zYAKW2AB6MRY98IU+2NzS/8tIMNJ99+GiVVGI70=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HE1ijT9iqJHTvkTHbYD0d2IT33XezH8LewweK/Pv1pocMA66y4j4CfadCrtYog6Sa HS27E8m6SjUqSl/KF2WlpSLpGcCMjSbmLxmmM55EWfykqETTzyZQD4DCaB6SklpFRp 3ZbJN+Ju42EuJJJKpHAOuvLmXEhiv+RsKzrrNMu4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot , Jozsef Kadlecsik , Florian Westphal , Pablo Neira Ayuso , Jakub Kicinski Subject: [PATCH 5.3 153/163] netfilter: conntrack: avoid possible false sharing Date: Mon, 4 Nov 2019 22:45:43 +0100 Message-Id: <20191104212151.368336381@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212140.046021995@linuxfoundation.org> References: <20191104212140.046021995@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: Eric Dumazet commit e37542ba111f3974dc622ae0a21c1787318de500 upstream. As hinted by KCSAN, we need at least one READ_ONCE() to prevent a compiler optimization. More details on : https://github.com/google/ktsan/wiki/READ_ONCE-and-WRITE_ONCE#it-may-improve-performance sysbot report : BUG: KCSAN: data-race in __nf_ct_refresh_acct / __nf_ct_refresh_acct read to 0xffff888123eb4f08 of 4 bytes by interrupt on cpu 0: __nf_ct_refresh_acct+0xd4/0x1b0 net/netfilter/nf_conntrack_core.c:1796 nf_ct_refresh_acct include/net/netfilter/nf_conntrack.h:201 [inline] nf_conntrack_tcp_packet+0xd40/0x3390 net/netfilter/nf_conntrack_proto_tcp.c:1161 nf_conntrack_handle_packet net/netfilter/nf_conntrack_core.c:1633 [inline] nf_conntrack_in+0x410/0xaa0 net/netfilter/nf_conntrack_core.c:1727 ipv4_conntrack_in+0x27/0x40 net/netfilter/nf_conntrack_proto.c:178 nf_hook_entry_hookfn include/linux/netfilter.h:135 [inline] nf_hook_slow+0x83/0x160 net/netfilter/core.c:512 nf_hook include/linux/netfilter.h:260 [inline] NF_HOOK include/linux/netfilter.h:303 [inline] ip_rcv+0x12f/0x1a0 net/ipv4/ip_input.c:523 __netif_receive_skb_one_core+0xa7/0xe0 net/core/dev.c:5004 __netif_receive_skb+0x37/0xf0 net/core/dev.c:5118 netif_receive_skb_internal+0x59/0x190 net/core/dev.c:5208 napi_skb_finish net/core/dev.c:5671 [inline] napi_gro_receive+0x28f/0x330 net/core/dev.c:5704 receive_buf+0x284/0x30b0 drivers/net/virtio_net.c:1061 virtnet_receive drivers/net/virtio_net.c:1323 [inline] virtnet_poll+0x436/0x7d0 drivers/net/virtio_net.c:1428 napi_poll net/core/dev.c:6352 [inline] net_rx_action+0x3ae/0xa50 net/core/dev.c:6418 __do_softirq+0x115/0x33f kernel/softirq.c:292 write to 0xffff888123eb4f08 of 4 bytes by task 7191 on cpu 1: __nf_ct_refresh_acct+0xfb/0x1b0 net/netfilter/nf_conntrack_core.c:1797 nf_ct_refresh_acct include/net/netfilter/nf_conntrack.h:201 [inline] nf_conntrack_tcp_packet+0xd40/0x3390 net/netfilter/nf_conntrack_proto_tcp.c:1161 nf_conntrack_handle_packet net/netfilter/nf_conntrack_core.c:1633 [inline] nf_conntrack_in+0x410/0xaa0 net/netfilter/nf_conntrack_core.c:1727 ipv4_conntrack_local+0xbe/0x130 net/netfilter/nf_conntrack_proto.c:200 nf_hook_entry_hookfn include/linux/netfilter.h:135 [inline] nf_hook_slow+0x83/0x160 net/netfilter/core.c:512 nf_hook include/linux/netfilter.h:260 [inline] __ip_local_out+0x1f7/0x2b0 net/ipv4/ip_output.c:114 ip_local_out+0x31/0x90 net/ipv4/ip_output.c:123 __ip_queue_xmit+0x3a8/0xa40 net/ipv4/ip_output.c:532 ip_queue_xmit+0x45/0x60 include/net/ip.h:236 __tcp_transmit_skb+0xdeb/0x1cd0 net/ipv4/tcp_output.c:1158 __tcp_send_ack+0x246/0x300 net/ipv4/tcp_output.c:3685 tcp_send_ack+0x34/0x40 net/ipv4/tcp_output.c:3691 tcp_cleanup_rbuf+0x130/0x360 net/ipv4/tcp.c:1575 Reported by Kernel Concurrency Sanitizer on: CPU: 1 PID: 7191 Comm: syz-fuzzer Not tainted 5.3.0+ #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Fixes: cc16921351d8 ("netfilter: conntrack: avoid same-timeout update") Signed-off-by: Eric Dumazet Reported-by: syzbot Cc: Jozsef Kadlecsik Cc: Florian Westphal Acked-by: Pablo Neira Ayuso Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_conntrack_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -1793,8 +1793,8 @@ void __nf_ct_refresh_acct(struct nf_conn if (nf_ct_is_confirmed(ct)) extra_jiffies += nfct_time_stamp; - if (ct->timeout != extra_jiffies) - ct->timeout = extra_jiffies; + if (READ_ONCE(ct->timeout) != extra_jiffies) + WRITE_ONCE(ct->timeout, extra_jiffies); acct: if (do_acct) nf_ct_acct_update(ct, ctinfo, skb->len);