Skip to content

Commit aec9db3

Browse files
error27davem330
authored andcommitted
6LoWPAN: use the _safe version of list_for_each
When we kfree(entry) that causes a use-after-free bug so we have to use list_for_each_entry_safe() safe here. Signed-off-by: Dan Carpenter <error27@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 90d0963 commit aec9db3

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎net/ieee802154/6lowpan.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,15 +813,17 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
813813
struct lowpan_dev_info *lowpan_dev = lowpan_dev_info(dev);
814814
struct net_device *real_dev = lowpan_dev->real_dev;
815815
struct lowpan_dev_record *entry;
816+
struct lowpan_dev_record *tmp;
816817

817818
ASSERT_RTNL();
818819

819820
mutex_lock(&lowpan_dev_info(dev)->dev_list_mtx);
820-
list_for_each_entry(entry, &lowpan_devices, list)
821+
list_for_each_entry_safe(entry, tmp, &lowpan_devices, list) {
821822
if (entry->ldev == dev) {
822823
list_del(&entry->list);
823824
kfree(entry);
824825
}
826+
}
825827
mutex_unlock(&lowpan_dev_info(dev)->dev_list_mtx);
826828

827829
mutex_destroy(&lowpan_dev_info(dev)->dev_list_mtx);

0 commit comments

Comments
 (0)