Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp867354lqp; Thu, 23 May 2024 02:22:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVJ3uoLKL17laybJIApLOd6SXaII7BN8NBUIeETlosUAMdrAd/fflW+MW4UE5VV03fmdTYkKbO8fFqStPepjyt141pwCZHU+h9xAGFaZw== X-Google-Smtp-Source: AGHT+IHFArOi5c9m2oMTJ1xFSjIdJrsSxcEfpXL9Q5/6iaOgVyRkn1BVq+op5ScAHOZJsLtAZEpv X-Received: by 2002:a50:d654:0:b0:568:cdd8:cf60 with SMTP id 4fb4d7f45d1cf-578329c717emr3611456a12.8.1716456161783; Thu, 23 May 2024 02:22:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716456161; cv=pass; d=google.com; s=arc-20160816; b=eFSQVmZvxz9LMK014VL7ePWBLQsbLxbgZc0Mz4oC6dA+UWNX3f5F3v7CB6Vk6iVlrL WyaSBzDiz0VM95R6fu64C3EE3lFs5YkPjiTkr2mb6Bwq9y87f9Ayl76uBJ9GzjNwMhxb 1cLQ3NJQZMrT1aDj7+/TxqJpAtpxANC0vZ+sPCmoi9xaXzS1duweZCdppP8T1wZ4WAxn vJy7gs8AzydK8JB54jIqA7VjG8tgdL1Gezby6ticPBv/OCYy62m9gYClWjgOGUFtPYHv 9MqiV4Yh5ua7Fxk+1Ss2wzx5x9ciCcCBn+opF4HE9qdsGBPKmX7wgwEJzNrmDeTqpq7l 40Eg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=qEfVgqb84+yrLzNBT82KwSxKgdLRnUX1qHekb5qMRSo=; fh=Pej0NgZ1a9ybYTQj0SvJVM/yughk+ktMoY4204c/wWg=; b=TFQ6jrceX5wCA/EN/HeN4jaN1feR6oeIod9b0DZoDtMiuKVkU8NRFWLirkQeNebSOR lR0q4iZ23xIVu+UwlWJk3LRRWevWG72ABEOdxIRyeed7565ANgPZfqfGUis+0uu5fvJF CRxh8mBvG0Nj2mWX4mfQdTIPiKl0HHSqK2YS5AAsBUnsXeb5LXAPis+xbzbodf/4tV9Y LK/el7i3jrztW1ijAKFNS9VH0viJyrHE6/v0xwKe3U2QKnZz2T0t7lSmehkIWMPWwjco WTamhT9pd/iNgNxgpXbla5oBS1dLzm32gq6jGgIPJORTjc/F7Of6QvejpURPoWyQOhmY 3QIw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-187247-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187247-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-578372e9e30si1370603a12.308.2024.05.23.02.22.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 02:22:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187247-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-187247-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187247-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 856D81F2225E for ; Thu, 23 May 2024 09:22:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 801DC14D2BE; Thu, 23 May 2024 09:19:11 +0000 (UTC) Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CFA214A611; Thu, 23 May 2024 09:19:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716455951; cv=none; b=UzTRxPSPQWNiMSGD45asdI2bBXtHIx8z3YdXV+FcukrHkpC/8aDdcQ8HXcFTs/jXYez6ODqcHvR05L59Au5jBPmDrPJG76MvI8YoIPgy0W40IVqu2CSXte2iYDKihTQ5eJ8RbKtwLc52qe9x93STFTDKT5jxe3cMwohw5F4UbQs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716455951; c=relaxed/simple; bh=tQuy0uP30EbfAn8TGq5g9Z9/8T+P9+C+ScEtuin+UOE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=llT4p/hefvLlil7c7RFGB4ohYVOgFHIxu9G1Ynod9k9mbY/yZsxmFiYr7d3PWgRfmHaUlhG/b6fFdpQkZ7nm4bzbM3dcz9uln0+0ZHioUetURnEA0bj2guR7fTe+eyFhE7UaRblOP4bOhu/AUdDmroMry2wwkbqGuu4/eOiS+oc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 7aa799b418e511ef9305a59a3cc225df-20240523 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.38,REQID:cc5c2a70-4647-4726-9717-05fe619875fc,IP:10, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:-5 X-CID-INFO: VERSION:1.1.38,REQID:cc5c2a70-4647-4726-9717-05fe619875fc,IP:10,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:82c5f88,CLOUDID:6128a8db6d4a1389b61d91186139327c,BulkI D:240523171858W37SIIWU,BulkQuantity:0,Recheck:0,SF:17|19|44|66|24|102,TC:n il,Content:0,EDM:-3,IP:-2,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,CO L:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-UUID: 7aa799b418e511ef9305a59a3cc225df-20240523 Received: from mail.kylinos.cn [(39.156.73.10)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA) with ESMTP id 1359282934; Thu, 23 May 2024 17:18:55 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id 62D2DE000748; Thu, 23 May 2024 17:18:55 +0800 (CST) X-ns-mid: postfix-664F09FF-2518491106 Received: from kylin-pc.. (unknown [172.25.130.133]) by mail.kylinos.cn (NSMail) with ESMTPA id 2EF4BE000748; Thu, 23 May 2024 17:18:54 +0800 (CST) From: yunshui To: linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org Cc: marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com, yunshui , syzbot Subject: [PATCH] Bluetooth: 6lowpan: use DEV_STAT_INC() to avoid races Date: Thu, 23 May 2024 17:18:50 +0800 Message-Id: <20240523091850.1117138-1-jiangyunshui@kylinos.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable syzbot/KCSAN reported that races happen when multiple cpus updating dev->stats.tx_error concurrently. Adopt SMP safe DEV_STATS_INC() to update dev->stats fields. Reported-by: syzbot Signed-off-by: yunshui --- net/bluetooth/6lowpan.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c index 50cfec8ccac4..b8906f55e2b2 100644 --- a/net/bluetooth/6lowpan.c +++ b/net/bluetooth/6lowpan.c @@ -295,8 +295,8 @@ static int recv_pkt(struct sk_buff *skb, struct net_d= evice *dev, goto drop; } =20 - dev->stats.rx_bytes +=3D skb->len; - dev->stats.rx_packets++; + DEV_STATS_ADD(dev, rx_bytes, skb->len); + DEV_STATS_INC(dev, rx_packets); =20 consume_skb(local_skb); consume_skb(skb); @@ -323,8 +323,8 @@ static int recv_pkt(struct sk_buff *skb, struct net_d= evice *dev, goto drop; } =20 - dev->stats.rx_bytes +=3D skb->len; - dev->stats.rx_packets++; + DEV_STATS_ADD(dev, rx_bytes, skb->len); + DEV_STATS_INC(dev, rx_packets); =20 consume_skb(local_skb); consume_skb(skb); @@ -336,7 +336,8 @@ static int recv_pkt(struct sk_buff *skb, struct net_d= evice *dev, return NET_RX_SUCCESS; =20 drop: - dev->stats.rx_dropped++; + + DEV_STATS_INC(dev, rx_dropped); return NET_RX_DROP; } =20 @@ -445,13 +446,13 @@ static int send_pkt(struct l2cap_chan *chan, struct= sk_buff *skb, =20 err =3D l2cap_chan_send(chan, &msg, skb->len); if (err > 0) { - netdev->stats.tx_bytes +=3D err; - netdev->stats.tx_packets++; + DEV_STATS_ADD(netdev, tx_bytes, err); + DEV_STATS_INC(netdev, tx_packets); return 0; } =20 if (err < 0) - netdev->stats.tx_errors++; + DEV_STATS_INC(netdev, tx_errors); =20 return err; } --=20 2.34.1