Skip to content

Commit cfef46d

Browse files
thohuongtranvudavem330
authored andcommitted
ravb: Fix use-after-free ravb_tstamp_skb
When a Tx timestamp is requested, a pointer to the skb is stored in the ravb_tstamp_skb struct. This was done without an skb_get. There exists the possibility that the skb could be freed by ravb_tx_free (when ravb_tx_free is called from ravb_start_xmit) before the timestamp was processed, leading to a use-after-free bug. Use skb_get when filling a ravb_tstamp_skb struct, and add appropriate frees/consumes when a ravb_tstamp_skb struct is freed. Fixes: c156633 ("Renesas Ethernet AVB driver proper") Signed-off-by: Tho Vu <[email protected]> Signed-off-by: Kazuya Mizuguchi <[email protected]> Signed-off-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5cbe910 commit cfef46d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/net/ethernet/renesas/ravb_main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22
/* Renesas Ethernet AVB device driver
33
*
4-
* Copyright (C) 2014-2015 Renesas Electronics Corporation
4+
* Copyright (C) 2014-2019 Renesas Electronics Corporation
55
* Copyright (C) 2015 Renesas Solutions Corp.
66
* Copyright (C) 2015-2016 Cogent Embedded, Inc. <[email protected]>
77
*
@@ -513,7 +513,10 @@ static void ravb_get_tx_tstamp(struct net_device *ndev)
513513
kfree(ts_skb);
514514
if (tag == tfa_tag) {
515515
skb_tstamp_tx(skb, &shhwtstamps);
516+
dev_consume_skb_any(skb);
516517
break;
518+
} else {
519+
dev_kfree_skb_any(skb);
517520
}
518521
}
519522
ravb_modify(ndev, TCCR, TCCR_TFR, TCCR_TFR);
@@ -1564,7 +1567,7 @@ static netdev_tx_t ravb_start_xmit(struct sk_buff *skb, struct net_device *ndev)
15641567
}
15651568
goto unmap;
15661569
}
1567-
ts_skb->skb = skb;
1570+
ts_skb->skb = skb_get(skb);
15681571
ts_skb->tag = priv->ts_skb_tag++;
15691572
priv->ts_skb_tag &= 0x3ff;
15701573
list_add_tail(&ts_skb->list, &priv->ts_skb_list);
@@ -1693,6 +1696,7 @@ static int ravb_close(struct net_device *ndev)
16931696
/* Clear the timestamp list */
16941697
list_for_each_entry_safe(ts_skb, ts_skb2, &priv->ts_skb_list, list) {
16951698
list_del(&ts_skb->list);
1699+
kfree_skb(ts_skb->skb);
16961700
kfree(ts_skb);
16971701
}
16981702

0 commit comments

Comments
 (0)