netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Eric Dumazet <edumazet@google.com>,
	Willem de Bruijn <willemb@google.com>,
	"David S . Miller" <davem@davemloft.net>,
	Sasha Levin <sashal@kernel.org>,
	netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 4.14 349/371] packet: fix data-race in fanout_flow_is_huge()
Date: Thu, 16 Jan 2020 12:23:41 -0500	[thread overview]
Message-ID: <20200116172403.18149-292-sashal@kernel.org> (raw)
In-Reply-To: <20200116172403.18149-1-sashal@kernel.org>

From: Eric Dumazet <edumazet@google.com>

[ Upstream commit b756ad928d98e5ef0b74af7546a6a31a8dadde00 ]

KCSAN reported the following data-race [1]

Adding a couple of READ_ONCE()/WRITE_ONCE() should silence it.

Since the report hinted about multiple cpus using the history
concurrently, I added a test avoiding writing on it if the
victim slot already contains the desired value.

[1]

BUG: KCSAN: data-race in fanout_demux_rollover / fanout_demux_rollover

read to 0xffff8880b01786cc of 4 bytes by task 18921 on cpu 1:
 fanout_flow_is_huge net/packet/af_packet.c:1303 [inline]
 fanout_demux_rollover+0x33e/0x3f0 net/packet/af_packet.c:1353
 packet_rcv_fanout+0x34e/0x490 net/packet/af_packet.c:1453
 deliver_skb net/core/dev.c:1888 [inline]
 dev_queue_xmit_nit+0x15b/0x540 net/core/dev.c:1958
 xmit_one net/core/dev.c:3195 [inline]
 dev_hard_start_xmit+0x3f5/0x430 net/core/dev.c:3215
 __dev_queue_xmit+0x14ab/0x1b40 net/core/dev.c:3792
 dev_queue_xmit+0x21/0x30 net/core/dev.c:3825
 neigh_direct_output+0x1f/0x30 net/core/neighbour.c:1530
 neigh_output include/net/neighbour.h:511 [inline]
 ip6_finish_output2+0x7a2/0xec0 net/ipv6/ip6_output.c:116
 __ip6_finish_output net/ipv6/ip6_output.c:142 [inline]
 __ip6_finish_output+0x2d7/0x330 net/ipv6/ip6_output.c:127
 ip6_finish_output+0x41/0x160 net/ipv6/ip6_output.c:152
 NF_HOOK_COND include/linux/netfilter.h:294 [inline]
 ip6_output+0xf2/0x280 net/ipv6/ip6_output.c:175
 dst_output include/net/dst.h:436 [inline]
 ip6_local_out+0x74/0x90 net/ipv6/output_core.c:179
 ip6_send_skb+0x53/0x110 net/ipv6/ip6_output.c:1795
 udp_v6_send_skb.isra.0+0x3ec/0xa70 net/ipv6/udp.c:1173
 udpv6_sendmsg+0x1906/0x1c20 net/ipv6/udp.c:1471
 inet6_sendmsg+0x6d/0x90 net/ipv6/af_inet6.c:576
 sock_sendmsg_nosec net/socket.c:637 [inline]
 sock_sendmsg+0x9f/0xc0 net/socket.c:657
 ___sys_sendmsg+0x2b7/0x5d0 net/socket.c:2311
 __sys_sendmmsg+0x123/0x350 net/socket.c:2413
 __do_sys_sendmmsg net/socket.c:2442 [inline]
 __se_sys_sendmmsg net/socket.c:2439 [inline]
 __x64_sys_sendmmsg+0x64/0x80 net/socket.c:2439
 do_syscall_64+0xcc/0x370 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

write to 0xffff8880b01786cc of 4 bytes by task 18922 on cpu 0:
 fanout_flow_is_huge net/packet/af_packet.c:1306 [inline]
 fanout_demux_rollover+0x3a4/0x3f0 net/packet/af_packet.c:1353
 packet_rcv_fanout+0x34e/0x490 net/packet/af_packet.c:1453
 deliver_skb net/core/dev.c:1888 [inline]
 dev_queue_xmit_nit+0x15b/0x540 net/core/dev.c:1958
 xmit_one net/core/dev.c:3195 [inline]
 dev_hard_start_xmit+0x3f5/0x430 net/core/dev.c:3215
 __dev_queue_xmit+0x14ab/0x1b40 net/core/dev.c:3792
 dev_queue_xmit+0x21/0x30 net/core/dev.c:3825
 neigh_direct_output+0x1f/0x30 net/core/neighbour.c:1530
 neigh_output include/net/neighbour.h:511 [inline]
 ip6_finish_output2+0x7a2/0xec0 net/ipv6/ip6_output.c:116
 __ip6_finish_output net/ipv6/ip6_output.c:142 [inline]
 __ip6_finish_output+0x2d7/0x330 net/ipv6/ip6_output.c:127
 ip6_finish_output+0x41/0x160 net/ipv6/ip6_output.c:152
 NF_HOOK_COND include/linux/netfilter.h:294 [inline]
 ip6_output+0xf2/0x280 net/ipv6/ip6_output.c:175
 dst_output include/net/dst.h:436 [inline]
 ip6_local_out+0x74/0x90 net/ipv6/output_core.c:179
 ip6_send_skb+0x53/0x110 net/ipv6/ip6_output.c:1795
 udp_v6_send_skb.isra.0+0x3ec/0xa70 net/ipv6/udp.c:1173
 udpv6_sendmsg+0x1906/0x1c20 net/ipv6/udp.c:1471
 inet6_sendmsg+0x6d/0x90 net/ipv6/af_inet6.c:576
 sock_sendmsg_nosec net/socket.c:637 [inline]
 sock_sendmsg+0x9f/0xc0 net/socket.c:657
 ___sys_sendmsg+0x2b7/0x5d0 net/socket.c:2311
 __sys_sendmmsg+0x123/0x350 net/socket.c:2413
 __do_sys_sendmmsg net/socket.c:2442 [inline]
 __se_sys_sendmmsg net/socket.c:2439 [inline]
 __x64_sys_sendmmsg+0x64/0x80 net/socket.c:2439
 do_syscall_64+0xcc/0x370 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Reported by Kernel Concurrency Sanitizer on:
CPU: 0 PID: 18922 Comm: syz-executor.3 Not tainted 5.4.0-rc6+ #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011

Fixes: 3b3a5b0aab5b ("packet: rollover huge flows before small flows")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/packet/af_packet.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index e788f9c7c398..46b7fac82775 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1337,15 +1337,21 @@ static void packet_sock_destruct(struct sock *sk)
 
 static bool fanout_flow_is_huge(struct packet_sock *po, struct sk_buff *skb)
 {
-	u32 rxhash;
+	u32 *history = po->rollover->history;
+	u32 victim, rxhash;
 	int i, count = 0;
 
 	rxhash = skb_get_hash(skb);
 	for (i = 0; i < ROLLOVER_HLEN; i++)
-		if (po->rollover->history[i] == rxhash)
+		if (READ_ONCE(history[i]) == rxhash)
 			count++;
 
-	po->rollover->history[prandom_u32() % ROLLOVER_HLEN] = rxhash;
+	victim = prandom_u32() % ROLLOVER_HLEN;
+
+	/* Avoid dirtying the cache line if possible */
+	if (READ_ONCE(history[victim]) != rxhash)
+		WRITE_ONCE(history[victim], rxhash);
+
 	return count > (ROLLOVER_HLEN >> 1);
 }
 
-- 
2.20.1


  parent reply	other threads:[~2020-01-16 17:32 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200116172403.18149-1-sashal@kernel.org>
2020-01-16 17:18 ` [PATCH AUTOSEL 4.14 067/371] iwlwifi: mvm: avoid possible access out of array Sasha Levin
2020-01-16 17:19 ` [PATCH AUTOSEL 4.14 068/371] net/mlx5: Take lock with IRQs disabled to avoid deadlock Sasha Levin
2020-01-16 17:19 ` [PATCH AUTOSEL 4.14 069/371] iwlwifi: mvm: fix A-MPDU reference assignment Sasha Levin
2020-01-16 17:19 ` [PATCH AUTOSEL 4.14 080/371] iwlwifi: mvm: fix RSS config command Sasha Levin
2020-01-16 17:19 ` [PATCH AUTOSEL 4.14 084/371] net: phy: fixed_phy: Fix fixed_phy not checking GPIO Sasha Levin
2020-01-16 17:19 ` [PATCH AUTOSEL 4.14 110/371] net: dsa: qca8k: Enable delay for RGMII_ID mode Sasha Levin
2020-01-16 17:19 ` [PATCH AUTOSEL 4.14 126/371] netfilter: nft_set_hash: fix lookups with fixed size hash on big endian Sasha Levin
2020-01-16 17:20 ` [PATCH AUTOSEL 4.14 128/371] net: aquantia: fixed instack structure overflow Sasha Levin
2020-01-16 17:20 ` [PATCH AUTOSEL 4.14 135/371] net: sh_eth: fix a missing check of of_get_phy_mode Sasha Levin
2020-01-16 17:20 ` [PATCH AUTOSEL 4.14 143/371] tipc: tipc clang warning Sasha Levin
2020-01-16 17:20 ` [PATCH AUTOSEL 4.14 154/371] dccp: Fix memleak in __feat_register_sp Sasha Levin
2020-01-16 17:20 ` [PATCH AUTOSEL 4.14 157/371] ehea: Fix a copy-paste err in ehea_init_port_res Sasha Levin
2020-01-16 17:20 ` [PATCH AUTOSEL 4.14 161/371] net: hns3: fix for vport->bw_limit overflow problem Sasha Levin
2020-01-16 17:20 ` [PATCH AUTOSEL 4.14 164/371] tipc: set sysctl_tipc_rmem and named_timeout right range Sasha Levin
2020-01-16 17:20 ` [PATCH AUTOSEL 4.14 169/371] 6lowpan: Off by one handling ->nexthdr Sasha Levin
2020-01-16 17:20 ` [PATCH AUTOSEL 4.14 176/371] packet: in recvmsg msg_name return at least sizeof sockaddr_ll Sasha Levin
2020-01-16 17:20 ` [PATCH AUTOSEL 4.14 182/371] net: ena: fix swapped parameters when calling ena_com_indirect_table_fill_entry Sasha Levin
2020-01-16 17:20 ` [PATCH AUTOSEL 4.14 183/371] net: ena: fix: Free napi resources when ena_up() fails Sasha Levin
2020-01-16 17:20 ` [PATCH AUTOSEL 4.14 184/371] net: ena: fix incorrect test of supported hash function Sasha Levin
2020-01-16 17:20 ` [PATCH AUTOSEL 4.14 185/371] net: ena: fix ena_com_fill_hash_function() implementation Sasha Levin
2020-01-16 17:21 ` [PATCH AUTOSEL 4.14 192/371] l2tp: Fix possible NULL pointer dereference Sasha Levin
2020-01-16 17:21 ` [PATCH AUTOSEL 4.14 197/371] netfilter: ebtables: CONFIG_COMPAT: reject trailing data after last rule Sasha Levin
2020-01-16 17:21 ` [PATCH AUTOSEL 4.14 220/371] inet: frags: call inet_frags_fini() after unregister_pernet_subsys() Sasha Levin
2020-01-16 17:21 ` [PATCH AUTOSEL 4.14 221/371] netvsc: unshare skb in VF rx handler Sasha Levin
2020-01-16 17:21 ` [PATCH AUTOSEL 4.14 225/371] mpls: fix warning with multi-label encap Sasha Levin
2020-01-16 17:21 ` [PATCH AUTOSEL 4.14 227/371] qed: iWARP - Use READ_ONCE and smp_store_release to access ep->state Sasha Levin
2020-01-16 17:21 ` [PATCH AUTOSEL 4.14 231/371] net: netem: fix backlog accounting for corrupted GSO frames Sasha Levin
2020-01-16 17:21 ` [PATCH AUTOSEL 4.14 232/371] net/af_iucv: always register net_device notifier Sasha Levin
2020-01-16 17:21 ` [PATCH AUTOSEL 4.14 241/371] bnxt_en: Fix ethtool selftest crash under error conditions Sasha Levin
2020-01-16 17:21 ` [PATCH AUTOSEL 4.14 244/371] rxrpc: Fix uninitialized error code in rxrpc_send_data_packet() Sasha Levin
2020-01-16 17:21 ` [PATCH AUTOSEL 4.14 247/371] net: pasemi: fix an use-after-free in pasemi_mac_phy_init() Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 251/371] libertas_tf: Use correct channel range in lbtf_geo_init Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 252/371] qed: reduce maximum stack frame size Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 258/371] tipc: reduce risk of wakeup queue starvation Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 261/371] net/mlx5: Fix mlx5_ifc_query_lag_out_bits Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 268/371] net/rds: Add a few missing rds_stat_names entries Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 269/371] bnxt_en: Fix handling FRAG_ERR when NVM_INSTALL_UPDATE cmd fails Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 273/371] mac80211: minstrel_ht: fix per-group max throughput rate initialization Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 287/371] ath9k: dynack: fix possible deadlock in ath_dynack_node_{de}init Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 289/371] net: sonic: return NETDEV_TX_OK if failed to map buffer Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 295/371] ixgbe: sync the first fragment unconditionally Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 297/371] net: sonic: replace dev_kfree_skb in sonic_send_packet Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 299/371] ath10k: adjust skb length in ath10k_sdio_mbox_rx_packet Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 301/371] net/rds: Fix 'ib_evt_handler_call' element in 'rds_ib_stat_names' Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 303/371] net: aquantia: Fix aq_vec_isr_legacy() return value Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 304/371] net: hisilicon: Fix signedness bug in hix5hd2_dev_probe() Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 305/371] net: broadcom/bcmsysport: Fix signedness in bcm_sysport_probe() Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 306/371] net: stmmac: dwmac-meson8b: Fix signedness bug in probe Sasha Levin
2020-01-16 17:22 ` [PATCH AUTOSEL 4.14 307/371] net: axienet: fix a " Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 308/371] of: mdio: Fix a signedness bug in of_phy_get_and_connect() Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 309/371] net: ethernet: stmmac: Fix signedness bug in ipq806x_gmac_of_parse() Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 310/371] ipv6: Handle race in addrconf_dad_work Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 312/371] net: stmmac: gmac4+: Not all Unicast addresses may be available Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 313/371] mac80211: accept deauth frames in IBSS mode Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 314/371] llc: fix another potential sk_buff leak in llc_ui_sendmsg() Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 315/371] llc: fix sk_buff refcounting in llc_conn_state_process() Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 316/371] net: stmmac: fix length of PTP clock's name string Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 317/371] act_mirred: Fix mirred_init_module error handling Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 318/371] net: avoid possible false sharing in sk_leave_memory_pressure() Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 319/371] net: add {READ|WRITE}_ONCE() annotations on ->rskq_accept_head Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 320/371] tcp: annotate lockless access to tcp_memory_pressure Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 324/371] net: netem: fix error path for corrupted GSO frames Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 325/371] net: netem: correct the parent's backlog when corrupted packet was dropped Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 326/371] net: qca_spi: Move reset_count to struct qcaspi Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 329/371] mt7601u: fix bbp version check in mt7601u_wait_bbp_ready Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 333/371] cw1200: Fix a signedness bug in cw1200_load_firmware() Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 338/371] rtlwifi: Remove unnecessary NULL check in rtl_regd_init Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 345/371] hv_netvsc: flag software created hash value Sasha Levin
2020-01-16 17:23 ` [PATCH AUTOSEL 4.14 346/371] net: neigh: use long type to store jiffies delta Sasha Levin
2020-01-16 17:23 ` Sasha Levin [this message]
2020-01-16 17:24 ` [PATCH AUTOSEL 4.14 368/371] tipc: fix wrong timeout input for tipc_wait_for_cond() Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200116172403.18149-292-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).