Commit 28a5501c authored by Dongliang Mu's avatar Dongliang Mu Committed by Stefan Schmidt

ieee802154: hwsim: Fix memory leak in hwsim_add_one

No matter from hwsim_remove or hwsim_del_radio_nl, hwsim_del fails to
remove the entry in the edges list. Take the example below, phy0, phy1
and e0 will be deleted, resulting in e1 not freed and accessed in the
future.

              hwsim_phys
                  |
    ------------------------------
    |                            |
phy0 (edges)                 phy1 (edges)
   ----> e1 (idx = 1)             ----> e0 (idx = 0)

Fix this by deleting and freeing all the entries in the edges list
between hwsim_edge_unsubscribe_me and list_del(&phy->list).

Reported-by: syzbot+b80c9959009a9325cdff@syzkaller.appspotmail.com
Fixes: 1c9f4a3f ("ieee802154: hwsim: fix rcu handling")
Signed-off-by: default avatarDongliang Mu <mudongliangabcd@gmail.com>
Acked-by: default avatarAlexander Aring <aahringo@redhat.com>
Link: https://lore.kernel.org/r/20210616020901.2759466-1-mudongliangabcd@gmail.comSigned-off-by: default avatarStefan Schmidt <stefan@datenfreihafen.org>
parent ab372c22
...@@ -824,12 +824,17 @@ static int hwsim_add_one(struct genl_info *info, struct device *dev, ...@@ -824,12 +824,17 @@ static int hwsim_add_one(struct genl_info *info, struct device *dev,
static void hwsim_del(struct hwsim_phy *phy) static void hwsim_del(struct hwsim_phy *phy)
{ {
struct hwsim_pib *pib; struct hwsim_pib *pib;
struct hwsim_edge *e;
hwsim_edge_unsubscribe_me(phy); hwsim_edge_unsubscribe_me(phy);
list_del(&phy->list); list_del(&phy->list);
rcu_read_lock(); rcu_read_lock();
list_for_each_entry_rcu(e, &phy->edges, list) {
list_del_rcu(&e->list);
hwsim_free_edge(e);
}
pib = rcu_dereference(phy->pib); pib = rcu_dereference(phy->pib);
rcu_read_unlock(); rcu_read_unlock();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment