Skip to content

Commit 32d0a49

Browse files
edumazetdavem330
authored andcommitted
macsec: use DEV_STATS_INC()
syzbot/KCSAN reported data-races in macsec whenever dev->stats fields are updated. It appears all of these updates can happen from multiple cpus. Adopt SMP safe DEV_STATS_INC() to update dev->stats fields. Fixes: c09440f ("macsec: introduce IEEE 802.1AE driver") Reported-by: syzbot <syzkaller@googlegroups.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Sabrina Dubroca <sd@queasysnail.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6b47808 commit 32d0a49

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

drivers/net/macsec.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ static bool macsec_post_decrypt(struct sk_buff *skb, struct macsec_secy *secy, u
743743
u64_stats_update_begin(&rxsc_stats->syncp);
744744
rxsc_stats->stats.InPktsLate++;
745745
u64_stats_update_end(&rxsc_stats->syncp);
746-
secy->netdev->stats.rx_dropped++;
746+
DEV_STATS_INC(secy->netdev, rx_dropped);
747747
return false;
748748
}
749749

@@ -767,7 +767,7 @@ static bool macsec_post_decrypt(struct sk_buff *skb, struct macsec_secy *secy, u
767767
rxsc_stats->stats.InPktsNotValid++;
768768
u64_stats_update_end(&rxsc_stats->syncp);
769769
this_cpu_inc(rx_sa->stats->InPktsNotValid);
770-
secy->netdev->stats.rx_errors++;
770+
DEV_STATS_INC(secy->netdev, rx_errors);
771771
return false;
772772
}
773773

@@ -1069,7 +1069,7 @@ static enum rx_handler_result handle_not_macsec(struct sk_buff *skb)
10691069
u64_stats_update_begin(&secy_stats->syncp);
10701070
secy_stats->stats.InPktsNoTag++;
10711071
u64_stats_update_end(&secy_stats->syncp);
1072-
macsec->secy.netdev->stats.rx_dropped++;
1072+
DEV_STATS_INC(macsec->secy.netdev, rx_dropped);
10731073
continue;
10741074
}
10751075

@@ -1179,7 +1179,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
11791179
u64_stats_update_begin(&secy_stats->syncp);
11801180
secy_stats->stats.InPktsBadTag++;
11811181
u64_stats_update_end(&secy_stats->syncp);
1182-
secy->netdev->stats.rx_errors++;
1182+
DEV_STATS_INC(secy->netdev, rx_errors);
11831183
goto drop_nosa;
11841184
}
11851185

@@ -1196,7 +1196,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
11961196
u64_stats_update_begin(&rxsc_stats->syncp);
11971197
rxsc_stats->stats.InPktsNotUsingSA++;
11981198
u64_stats_update_end(&rxsc_stats->syncp);
1199-
secy->netdev->stats.rx_errors++;
1199+
DEV_STATS_INC(secy->netdev, rx_errors);
12001200
if (active_rx_sa)
12011201
this_cpu_inc(active_rx_sa->stats->InPktsNotUsingSA);
12021202
goto drop_nosa;
@@ -1230,7 +1230,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
12301230
u64_stats_update_begin(&rxsc_stats->syncp);
12311231
rxsc_stats->stats.InPktsLate++;
12321232
u64_stats_update_end(&rxsc_stats->syncp);
1233-
macsec->secy.netdev->stats.rx_dropped++;
1233+
DEV_STATS_INC(macsec->secy.netdev, rx_dropped);
12341234
goto drop;
12351235
}
12361236
}
@@ -1271,7 +1271,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
12711271
if (ret == NET_RX_SUCCESS)
12721272
count_rx(dev, len);
12731273
else
1274-
macsec->secy.netdev->stats.rx_dropped++;
1274+
DEV_STATS_INC(macsec->secy.netdev, rx_dropped);
12751275

12761276
rcu_read_unlock();
12771277

@@ -1308,7 +1308,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
13081308
u64_stats_update_begin(&secy_stats->syncp);
13091309
secy_stats->stats.InPktsNoSCI++;
13101310
u64_stats_update_end(&secy_stats->syncp);
1311-
macsec->secy.netdev->stats.rx_errors++;
1311+
DEV_STATS_INC(macsec->secy.netdev, rx_errors);
13121312
continue;
13131313
}
13141314

@@ -1327,7 +1327,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
13271327
secy_stats->stats.InPktsUnknownSCI++;
13281328
u64_stats_update_end(&secy_stats->syncp);
13291329
} else {
1330-
macsec->secy.netdev->stats.rx_dropped++;
1330+
DEV_STATS_INC(macsec->secy.netdev, rx_dropped);
13311331
}
13321332
}
13331333

@@ -3422,15 +3422,15 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
34223422

34233423
if (!secy->operational) {
34243424
kfree_skb(skb);
3425-
dev->stats.tx_dropped++;
3425+
DEV_STATS_INC(dev, tx_dropped);
34263426
return NETDEV_TX_OK;
34273427
}
34283428

34293429
len = skb->len;
34303430
skb = macsec_encrypt(skb, dev);
34313431
if (IS_ERR(skb)) {
34323432
if (PTR_ERR(skb) != -EINPROGRESS)
3433-
dev->stats.tx_dropped++;
3433+
DEV_STATS_INC(dev, tx_dropped);
34343434
return NETDEV_TX_OK;
34353435
}
34363436

@@ -3667,9 +3667,9 @@ static void macsec_get_stats64(struct net_device *dev,
36673667

36683668
dev_fetch_sw_netstats(s, dev->tstats);
36693669

3670-
s->rx_dropped = dev->stats.rx_dropped;
3671-
s->tx_dropped = dev->stats.tx_dropped;
3672-
s->rx_errors = dev->stats.rx_errors;
3670+
s->rx_dropped = atomic_long_read(&dev->stats.__rx_dropped);
3671+
s->tx_dropped = atomic_long_read(&dev->stats.__tx_dropped);
3672+
s->rx_errors = atomic_long_read(&dev->stats.__rx_errors);
36733673
}
36743674

36753675
static int macsec_get_iflink(const struct net_device *dev)

0 commit comments

Comments
 (0)