Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp1524458rwj; Sun, 18 Dec 2022 09:51:11 -0800 (PST) X-Google-Smtp-Source: AMrXdXsRBm55ZiaMCmxcY37IYf87v9Q1yts0U4DJvohqY00Bge95RzWLx4eznbWSik0MyjgWBKP3 X-Received: by 2002:a05:6a20:4409:b0:b0:3e0f:508d with SMTP id ce9-20020a056a20440900b000b03e0f508dmr2024617pzb.55.1671385871162; Sun, 18 Dec 2022 09:51:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671385871; cv=none; d=google.com; s=arc-20160816; b=pFkb7ZARed9XprsTOqgNWjyYvd+KVMYLcZeYZ40p9yy8ocQRC0B+V8uYyCCdAy5aS2 2DT2S0qdg24wkBgqQKPFZOTD9tQkVP8TiIepFfGfco4AKKDqA9fkUMbr2aRPVAXTx7m3 lVu9zD4MUxp/WvbypYA+a76uaqLZNZq1fAC6P3Lgw5xpl/SHl+T6DQVdtLfQTA6VcZjx HrKNQL/gyf+WKNg+6WAKG5awdZ7tMtxJ30zV7XY5aSlnj/a9gwKthMQzwojNofac3mGy MR4Er1rTASuDxHYL86TPsF6jEwlG21o1CWJIofKQOpOifQSP39iabTUFf3tCYvki2GPM 1eWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7EwbTXbZZox+gxV703v4yRq1OGlEqdc/r9UjRlr5Wsc=; b=HpeMOJscREehzR2w0B0AKcyiPRiTgHrpRbpOFtFqEKLs1t446UBYfyCfFfa9B76o5m wLntxgga7ghDVE2RfWylybcnKbMqe++UmE5ZSVSaVxy2Ux30QUUbJkkZ2cOl3s13c7SJ ExySSIJQSuLRObsahL3+CM/Rj5AKHAhjre6P2YHJh7Tab6hJ4ZmVwKq87TVkvdMy9jnd /DmdxtfuhLKiIlknB8PLQP6uiJB6ry1ZiiC8xu5EN3gI/hEvcDCoVsgsFON0u80VjejF D78KF2QFXGzEx2xLlKJljX4RKYWK6dYGfONdNyq3iU9wicgdnfFeJXSUp1gNmeQoJEBi VKWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PEXCKHct; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 65-20020a630844000000b004795c10a6c6si8612327pgi.665.2022.12.18.09.51.02; Sun, 18 Dec 2022 09:51:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PEXCKHct; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232560AbiLRQm5 (ORCPT + 70 others); Sun, 18 Dec 2022 11:42:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232558AbiLRQlT (ORCPT ); Sun, 18 Dec 2022 11:41:19 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D98B7F017; Sun, 18 Dec 2022 08:14:46 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 877DAB80B43; Sun, 18 Dec 2022 16:14:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 058FFC433F0; Sun, 18 Dec 2022 16:14:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671380084; bh=Qs8z/eMb9zZap8vuy7TCJ7fXrIA0nWBv7Nf/yamGJUA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PEXCKHct0Y+tmardnYbvkbTFeUJCdQqWBFEiadA99Yop3cIJHF64hzhV2wi9LUGyD EHlhsO4UMqfC4JlK/lyPfdQyl2mTZ8hL5xnpwoMzJjj5Xb/Cil7FGNo8tjo9zqEe93 MioVkpYIkC+0i5Z8E4H4HxXmm/xYh4AQtKPDlU1oJ/4bwjySSvb9AZqZQe9gROiPgE aWo3WjOlAbZTD4NqSaOSHYAAXm2/luedcGRcVl2w43T4Ve1bxhTCXVX0b8Oq7IQuYi 0CCir76uG54+Cxooihi7MRlYq/zNL+DLrYzbw0/gCtbEfwS5f5jWxGkEx6G9Ecydpy EudLgyniNAxVA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Eric Dumazet , syzbot , "David S . Miller" , Sasha Levin , yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 29/46] ipv6/sit: use DEV_STATS_INC() to avoid data-races Date: Sun, 18 Dec 2022 11:12:27 -0500 Message-Id: <20221218161244.930785-29-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221218161244.930785-1-sashal@kernel.org> References: <20221218161244.930785-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ Upstream commit cb34b7cf17ecf33499c9298943f85af247abc1e9 ] syzbot/KCSAN reported that multiple cpus are updating dev->stats.tx_error concurrently. This is because sit tunnels are NETIF_F_LLTX, meaning their ndo_start_xmit() is not protected by a spinlock. While original KCSAN report was about tx path, rx path has the same issue. Reported-by: syzbot Signed-off-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv6/sit.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index 946871741f12..d4cdc2b1b468 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -696,7 +696,7 @@ static int ipip6_rcv(struct sk_buff *skb) skb->dev = tunnel->dev; if (packet_is_spoofed(skb, iph, tunnel)) { - tunnel->dev->stats.rx_errors++; + DEV_STATS_INC(tunnel->dev, rx_errors); goto out; } @@ -716,8 +716,8 @@ static int ipip6_rcv(struct sk_buff *skb) net_info_ratelimited("non-ECT from %pI4 with TOS=%#x\n", &iph->saddr, iph->tos); if (err > 1) { - ++tunnel->dev->stats.rx_frame_errors; - ++tunnel->dev->stats.rx_errors; + DEV_STATS_INC(tunnel->dev, rx_frame_errors); + DEV_STATS_INC(tunnel->dev, rx_errors); goto out; } } @@ -948,7 +948,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, if (!rt) { rt = ip_route_output_flow(tunnel->net, &fl4, NULL); if (IS_ERR(rt)) { - dev->stats.tx_carrier_errors++; + DEV_STATS_INC(dev, tx_carrier_errors); goto tx_error_icmp; } dst_cache_set_ip4(&tunnel->dst_cache, &rt->dst, fl4.saddr); @@ -956,14 +956,14 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, if (rt->rt_type != RTN_UNICAST) { ip_rt_put(rt); - dev->stats.tx_carrier_errors++; + DEV_STATS_INC(dev, tx_carrier_errors); goto tx_error_icmp; } tdev = rt->dst.dev; if (tdev == dev) { ip_rt_put(rt); - dev->stats.collisions++; + DEV_STATS_INC(dev, collisions); goto tx_error; } @@ -976,7 +976,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, mtu = dst_mtu(&rt->dst) - t_hlen; if (mtu < IPV4_MIN_MTU) { - dev->stats.collisions++; + DEV_STATS_INC(dev, collisions); ip_rt_put(rt); goto tx_error; } @@ -1015,7 +1015,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom); if (!new_skb) { ip_rt_put(rt); - dev->stats.tx_dropped++; + DEV_STATS_INC(dev, tx_dropped); kfree_skb(skb); return NETDEV_TX_OK; } @@ -1045,7 +1045,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, dst_link_failure(skb); tx_error: kfree_skb(skb); - dev->stats.tx_errors++; + DEV_STATS_INC(dev, tx_errors); return NETDEV_TX_OK; } @@ -1064,7 +1064,7 @@ static netdev_tx_t sit_tunnel_xmit__(struct sk_buff *skb, return NETDEV_TX_OK; tx_error: kfree_skb(skb); - dev->stats.tx_errors++; + DEV_STATS_INC(dev, tx_errors); return NETDEV_TX_OK; } @@ -1093,7 +1093,7 @@ static netdev_tx_t sit_tunnel_xmit(struct sk_buff *skb, return NETDEV_TX_OK; tx_err: - dev->stats.tx_errors++; + DEV_STATS_INC(dev, tx_errors); kfree_skb(skb); return NETDEV_TX_OK; -- 2.35.1