2024-05-27 06:58:44

by Yunshui Jiang

[permalink] [raw]
Subject: [PATCH v2] Bluetooth: 6lowpan: use DEV_STAT_INC() to avoid races

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.

Signed-off-by: yunshui <[email protected]>
---
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_device *dev,
goto drop;
}

- dev->stats.rx_bytes += skb->len;
- dev->stats.rx_packets++;
+ DEV_STATS_ADD(dev, rx_bytes, skb->len);
+ DEV_STATS_INC(dev, rx_packets);

consume_skb(local_skb);
consume_skb(skb);
@@ -323,8 +323,8 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
goto drop;
}

- dev->stats.rx_bytes += skb->len;
- dev->stats.rx_packets++;
+ DEV_STATS_ADD(dev, rx_bytes, skb->len);
+ DEV_STATS_INC(dev, rx_packets);

consume_skb(local_skb);
consume_skb(skb);
@@ -336,7 +336,8 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
return NET_RX_SUCCESS;

drop:
- dev->stats.rx_dropped++;
+
+ DEV_STATS_INC(dev, rx_dropped);
return NET_RX_DROP;
}

@@ -445,13 +446,13 @@ static int send_pkt(struct l2cap_chan *chan, struct sk_buff *skb,

err = l2cap_chan_send(chan, &msg, skb->len);
if (err > 0) {
- netdev->stats.tx_bytes += err;
- netdev->stats.tx_packets++;
+ DEV_STATS_ADD(netdev, tx_bytes, err);
+ DEV_STATS_INC(netdev, tx_packets);
return 0;
}

if (err < 0)
- netdev->stats.tx_errors++;
+ DEV_STATS_INC(netdev, tx_errors);

return err;
}
--
2.34.1



2024-05-27 07:04:01

by Paul Menzel

[permalink] [raw]
Subject: Re: [PATCH v2] Bluetooth: 6lowpan: use DEV_STAT_INC() to avoid races

Dear yunshui,


Thank you for your patch. One formal request:

Am 27.05.24 um 08:52 schrieb yunshui:
> 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.
>
> Signed-off-by: yunshui <[email protected]>

Could you please use your full name? Maybe:

$ git config --global user.name "Jiang Yunshui"
$ git commit --amend --author="Jiang Yunshui <[email protected]>"

[…]


Kind regards,

Paul