Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Dan Carpenter and committed by
David S. Miller
aec9db35 90d0963d

+3 -1
+3 -1
net/ieee802154/6lowpan.c
··· 813 813 struct lowpan_dev_info *lowpan_dev = lowpan_dev_info(dev); 814 814 struct net_device *real_dev = lowpan_dev->real_dev; 815 815 struct lowpan_dev_record *entry; 816 + struct lowpan_dev_record *tmp; 816 817 817 818 ASSERT_RTNL(); 818 819 819 820 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) { 821 822 if (entry->ldev == dev) { 822 823 list_del(&entry->list); 823 824 kfree(entry); 824 825 } 826 + } 825 827 mutex_unlock(&lowpan_dev_info(dev)->dev_list_mtx); 826 828 827 829 mutex_destroy(&lowpan_dev_info(dev)->dev_list_mtx);