If we haven't set the module to MODULE_ACTIVE state before (in general, no interface has yet been added to batman-adv) then the hna table is not initialised yet. If the kernel changes the mac address of the bat0 interface at this moment then an hna_local_add() called by interface_set_mac_addr() then resulted in a null pointer derefernce. With this patch we are now explicitly checking before if the state is MODULE_ACTIVE right now so that we can assume having an initialised hna table.
Signed-off-by: Linus Lüssing linus.luessing@web.de --- batman-adv-kernelland/soft-interface.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/batman-adv-kernelland/soft-interface.c b/batman-adv-kernelland/soft-interface.c index f098a4f..582134f 100644 --- a/batman-adv-kernelland/soft-interface.c +++ b/batman-adv-kernelland/soft-interface.c @@ -154,9 +154,13 @@ int interface_set_mac_addr(struct net_device *dev, void *p) if (!is_valid_ether_addr(addr->sa_data)) return -EADDRNOTAVAIL;
- hna_local_remove(dev->dev_addr, "mac address changed"); + /* only modify hna-table if it has been initialised before */ + if (atomic_read(&module_state) == MODULE_ACTIVE) { + hna_local_remove(dev->dev_addr, "mac address changed"); + hna_local_add(addr->sa_data); + } + memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); - hna_local_add(dev->dev_addr);
return 0; }
Just for some more clarification about this bug (have a look at the attached call trace): It always occurs when I haven't put an interface into batman-adv and when I'm then changing the mac-address of bat0. I've now added a little check in interface_set_mac_addr() which seems to work nicely here in my setup. I'm also wondering if we should add another sanity check somewhere in hna_local_add() to directly avoid any racy null pointer dereferences in there.
Cheers, Linus
On Sat, Feb 27, 2010 at 02:49:42AM +0100, Linus Lüssing wrote:
If we haven't set the module to MODULE_ACTIVE state before (in general, no interface has yet been added to batman-adv) then the hna table is not initialised yet. If the kernel changes the mac address of the bat0 interface at this moment then an hna_local_add() called by interface_set_mac_addr() then resulted in a null pointer derefernce. With this patch we are now explicitly checking before if the state is MODULE_ACTIVE right now so that we can assume having an initialised hna table.
Signed-off-by: Linus Lüssing linus.luessing@web.de
batman-adv-kernelland/soft-interface.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/batman-adv-kernelland/soft-interface.c b/batman-adv-kernelland/soft-interface.c index f098a4f..582134f 100644 --- a/batman-adv-kernelland/soft-interface.c +++ b/batman-adv-kernelland/soft-interface.c @@ -154,9 +154,13 @@ int interface_set_mac_addr(struct net_device *dev, void *p) if (!is_valid_ether_addr(addr->sa_data)) return -EADDRNOTAVAIL;
- hna_local_remove(dev->dev_addr, "mac address changed");
- /* only modify hna-table if it has been initialised before */
- if (atomic_read(&module_state) == MODULE_ACTIVE) {
hna_local_remove(dev->dev_addr, "mac address changed");
hna_local_add(addr->sa_data);
- }
- memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
hna_local_add(dev->dev_addr);
return 0;
}
1.7.0
Hey,
nice patch and this time well formatted. ;-) Applied in 1578.
Just for some more clarification about this bug (have a look at the attached call trace): It always occurs when I haven't put an interface into batman-adv and when I'm then changing the mac-address of bat0. I've now added a little check in interface_set_mac_addr() which seems to work nicely here in my setup. I'm also wondering if we should add another sanity check somewhere in hna_local_add() to directly avoid any racy null pointer dereferences in there.
I'm not sure it is a good place to put such a check since hna_local_add() is more of a library function which does not know much about the context. However, it could check whether the hna_local_hash had been initialized.
Cheers, Marek
b.a.t.m.a.n@lists.open-mesh.org