linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Bug in BCMA: device_unregister causing "NULL pointer dereference at"
@ 2011-07-07 15:25 Rafał Miłecki
  2011-07-07 15:27 ` Rafał Miłecki
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Rafał Miłecki @ 2011-07-07 15:25 UTC (permalink / raw)
  To: linux-wireless, Linux Kernel Mailing List

I've problem with bcma and bus subsystem.

This works fine:
modprobe bcma; rmmod bcma

This:
modprobe bcma; modprobe b43; rmmod b43; rmmod bcma
causes:
BUG: unable to handle kernel NULL pointer dereference at   (null)

My BCMA has only 3 fores, out of them only 1 is registered as device:
bcma: Core 0 found: ChipCommon (manuf 0x4BF, id 0x800, rev 0x22, class 0x0)
bcma: Core 1 found: IEEE 802.11 (manuf 0x4BF, id 0x812, rev 0x17, class 0x0)
bcma: Core 2 found: PCIe (manuf 0x4BF, id 0x820, rev 0x0F, class 0x0)

The dereference comes out from
static void bcma_unregister_cores(struct bcma_bus *bus)

There is a simple loop:
list_for_each_entry(core, &bus->cores, list) {
	if (core->dev_registered)
		device_unregister(&core->dev);
}


So when I unload bcma after I got driver (b43) for 0x812 core, I get
NULL pointer dereference.

Any tip, why does it happen?

-- 
Rafał

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug in BCMA: device_unregister causing "NULL pointer dereference at"
  2011-07-07 15:25 Bug in BCMA: device_unregister causing "NULL pointer dereference at" Rafał Miłecki
@ 2011-07-07 15:27 ` Rafał Miłecki
  2011-07-14 14:45 ` Francois Romieu
  2011-07-21  7:18 ` Rafał Miłecki
  2 siblings, 0 replies; 6+ messages in thread
From: Rafał Miłecki @ 2011-07-07 15:27 UTC (permalink / raw)
  To: linux-wireless, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 1080 bytes --]

W dniu 7 lipca 2011 17:25 użytkownik Rafał Miłecki <zajec5@gmail.com> napisał:
> I've problem with bcma and bus subsystem.
>
> This works fine:
> modprobe bcma; rmmod bcma
>
> This:
> modprobe bcma; modprobe b43; rmmod b43; rmmod bcma
> causes:
> BUG: unable to handle kernel NULL pointer dereference at   (null)
>
> My BCMA has only 3 fores, out of them only 1 is registered as device:
> bcma: Core 0 found: ChipCommon (manuf 0x4BF, id 0x800, rev 0x22, class 0x0)
> bcma: Core 1 found: IEEE 802.11 (manuf 0x4BF, id 0x812, rev 0x17, class 0x0)
> bcma: Core 2 found: PCIe (manuf 0x4BF, id 0x820, rev 0x0F, class 0x0)
>
> The dereference comes out from
> static void bcma_unregister_cores(struct bcma_bus *bus)
>
> There is a simple loop:
> list_for_each_entry(core, &bus->cores, list) {
>        if (core->dev_registered)
>                device_unregister(&core->dev);
> }
>
>
> So when I unload bcma after I got driver (b43) for 0x812 core, I get
> NULL pointer dereference.
>
> Any tip, why does it happen?

Dmesg

-- 
Rafał

[-- Attachment #2: dmesg.log --]
[-- Type: application/octet-stream, Size: 3530 bytes --]

[  222.393217] bcma: Unregistering driver
[  228.242887] bcma: Core 0x820 registered:0
[  228.242892] bcma: Core 0x812 registered:1
[  228.243956] BUG: unable to handle kernel NULL pointer dereference at   (null)
[  228.243972] IP: [<c03dca4e>] kobject_del+0x2e/0x60
[  228.243988] *pdpt = 000000001b80c001 *pde = 0000000000000000 
[  228.243997] Oops: 0002 [#1] PREEMPT SMP 
[  228.244006] Modules linked in: arc4 ssb mmc_core pcmcia pcmcia_core mac80211 cfg80211 bcma(-) ip6t_LOG xt_tcpudp xt_pkttype ipt_LOG xt_limit snd_pcm_oss snd_mixer_oss snd_seq snd_seq_device edd af_packet ip6t_REJECT nf_conntrack_ipv6 nf_defrag_ipv6 ip6table_raw xt_NOTRACK ipt_REJECT iptable_raw iptable_filter ip6table_mangle nf_conntrack_netbios_ns nf_conntrack_broadcast nf_conntrack_ipv4 nf_defrag_ipv4 ip_tables xt_conntrack nf_conntrack ip6table_filter ip6_tables x_tables ext3 jbd dm_mod snd_intel8x0 snd_ac97_codec ac97_bus snd_pcm sg snd_timer snd ns558 serio_raw ppdev pata_amd floppy gameport i2c_nforce2 parport_pc parport soundcore forcedeth k8temp pcspkr snd_page_alloc button ext4 mbcache jbd2 crc16 sd_mod fan processor ata_generic pata_via pata_jmicron sata_nv sata_via thermal thermal_sys [last unloaded: b43]
[  228.244024] 
[  228.244024] Pid: 3380, comm: rmmod Not tainted 3.0.0-rc5-wl-b43+ #81          K8NF4G-SATA2/K8NF4G-SATA2
[  228.244024] EIP: 0060:[<c03dca4e>] EFLAGS: 00010246 CPU: 0
[  228.244024] EIP is at kobject_del+0x2e/0x60
[  228.244024] EAX: db8e6a18 EBX: db8e6a14 ECX: db4f1a14 EDX: 00000000
[  228.244024] ESI: db8e6a14 EDI: da106860 EBP: db529e48 ESP: db529e44
[  228.244024]  DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068
[  228.244024] Process rmmod (pid: 3380, ti=db528000 task=d78ec5f0 task.ti=db528000)
[  228.244024] Stack:
[  228.244024]  db8e6a0c db529e5c c048c51c db8e6a0c db8e6a00 da106860 db529e78 c048c569
[  228.244024]  da106860 db529e78 c0624f28 dd0075c8 db905e18 db529e94 dd005448 dd0075c8
[  228.244024]  00000812 00000001 da106800 db905e00 db529ea8 dd006ce4 da106860 da106800
[  228.244024] Call Trace:
[  228.244024]  [<c048c51c>] device_del+0x11c/0x150
[  228.244024]  [<c048c569>] device_unregister+0x19/0x60
[  228.244024]  [<c0624f28>] ? printk+0x28/0x30
[  228.244024]  [<dd005448>] bcma_bus_unregister+0x68/0x70 [bcma]
[  228.244024]  [<dd006ce4>] bcma_host_pci_remove+0x24/0x60 [bcma]
[  228.244024]  [<c03fcfbf>] pci_device_remove+0x3f/0xf0
[  228.244024]  [<c048f086>] __device_release_driver+0x56/0xa0
[  228.244024]  [<c048f7ef>] driver_detach+0x8f/0xa0
[  228.244024]  [<c048ef2c>] bus_remove_driver+0x6c/0xe0
[  228.244024]  [<c048fb51>] driver_unregister+0x41/0x70
[  228.244024]  [<c037a0af>] ? sysfs_remove_file+0xf/0x20
[  228.244024]  [<c03fcccd>] pci_unregister_driver+0x2d/0x80
[  228.244024]  [<dd007085>] bcma_host_pci_exit+0xd/0xf [bcma]
[  228.244024]  [<dd00706c>] bcma_modexit+0x8/0x14 [bcma]
[  228.244024]  [<c02827c9>] sys_delete_module+0x129/0x200
[  228.244024]  [<c02fa1a6>] ? remove_vma+0x46/0x60
[  228.244024]  [<c02fb0d1>] ? do_munmap+0x1f1/0x270
[  228.244024]  [<c062e0d8>] sysenter_do_call+0x12/0x28
[  228.244024] Code: 89 e5 53 89 c3 74 51 e8 c1 e7 f9 ff 8b 43 10 80 63 20 fd 85 c0 74 32 83 c0 08 e8 de b1 24 00 8b 4b 04 8d 43 04 8b 53 08 89 51 04 
[  228.244024]  0a 89 43 04 89 43 08 8b 43 10 83 c0 08 e8 8f af 24 00 8b 43 
[  228.244024] EIP: [<c03dca4e>] kobject_del+0x2e/0x60 SS:ESP 0068:db529e44
[  228.244024] CR2: 0000000000000000
[  228.244511] ---[ end trace 4001c153024e24d0 ]---
[  228.244520] note: rmmod[3380] exited with preempt_count 1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug in BCMA: device_unregister causing "NULL pointer dereference at"
  2011-07-07 15:25 Bug in BCMA: device_unregister causing "NULL pointer dereference at" Rafał Miłecki
  2011-07-07 15:27 ` Rafał Miłecki
@ 2011-07-14 14:45 ` Francois Romieu
  2011-07-21  7:14   ` Rafał Miłecki
  2011-07-21  7:18 ` Rafał Miłecki
  2 siblings, 1 reply; 6+ messages in thread
From: Francois Romieu @ 2011-07-14 14:45 UTC (permalink / raw)
  To: Rafał Miłecki; +Cc: linux-wireless, Linux Kernel Mailing List

Rafał Miłecki <zajec5@gmail.com> :
[...]
> Any tip, why does it happen?

bcma_release_core_dev kfrees core while its list_head is still used ?

May be something like this :

diff --git a/drivers/bcma/main.c b/drivers/bcma/main.c
index be52344..85fb3aa 100644
--- a/drivers/bcma/main.c
+++ b/drivers/bcma/main.c
@@ -110,11 +110,14 @@ static int bcma_register_cores(struct bcma_bus *bus)
 
 static void bcma_unregister_cores(struct bcma_bus *bus)
 {
-	struct bcma_device *core;
+	struct bcma_device *core, *next;
 
-	list_for_each_entry(core, &bus->cores, list) {
+	list_for_each_entry_safe(core, next, &bus->cores, list) {
+		list_del(&core->list);
 		if (core->dev_registered)
 			device_unregister(&core->dev);
+		else
+			kfree(core);
 	}
 }
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: Bug in BCMA: device_unregister causing "NULL pointer dereference at"
  2011-07-14 14:45 ` Francois Romieu
@ 2011-07-21  7:14   ` Rafał Miłecki
  0 siblings, 0 replies; 6+ messages in thread
From: Rafał Miłecki @ 2011-07-21  7:14 UTC (permalink / raw)
  To: Francois Romieu; +Cc: linux-wireless, Linux Kernel Mailing List

W dniu 14 lipca 2011 16:45 użytkownik Francois Romieu
<romieu@fr.zoreil.com> napisał:
> Rafał Miłecki <zajec5@gmail.com> :
> [...]
>> Any tip, why does it happen?
>
> bcma_release_core_dev kfrees core while its list_head is still used ?
>
> May be something like this :
>
> diff --git a/drivers/bcma/main.c b/drivers/bcma/main.c
> index be52344..85fb3aa 100644
> --- a/drivers/bcma/main.c
> +++ b/drivers/bcma/main.c
> @@ -110,11 +110,14 @@ static int bcma_register_cores(struct bcma_bus *bus)
>
>  static void bcma_unregister_cores(struct bcma_bus *bus)
>  {
> -       struct bcma_device *core;
> +       struct bcma_device *core, *next;
>
> -       list_for_each_entry(core, &bus->cores, list) {
> +       list_for_each_entry_safe(core, next, &bus->cores, list) {
> +               list_del(&core->list);
>                if (core->dev_registered)
>                        device_unregister(&core->dev);
> +               else
> +                       kfree(core);
>        }
>  }

Thanks for your help, but I'm afraid crash happens in totally
different place. Have you take a look at dmesg.log from my second
e-mail? NULL ptr exception happens in kobject_del.

-- 
Rafał

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug in BCMA: device_unregister causing "NULL pointer dereference at"
  2011-07-07 15:25 Bug in BCMA: device_unregister causing "NULL pointer dereference at" Rafał Miłecki
  2011-07-07 15:27 ` Rafał Miłecki
  2011-07-14 14:45 ` Francois Romieu
@ 2011-07-21  7:18 ` Rafał Miłecki
  2011-07-21 16:33   ` Pavel Roskin
  2 siblings, 1 reply; 6+ messages in thread
From: Rafał Miłecki @ 2011-07-21  7:18 UTC (permalink / raw)
  To: linux-wireless, Linux Kernel Mailing List

W dniu 7 lipca 2011 17:25 użytkownik Rafał Miłecki <zajec5@gmail.com> napisał:
> I've problem with bcma and bus subsystem.
>
> This works fine:
> modprobe bcma; rmmod bcma
>
> This:
> modprobe bcma; modprobe b43; rmmod b43; rmmod bcma
> causes:
> BUG: unable to handle kernel NULL pointer dereference at   (null)
>
> My BCMA has only 3 fores, out of them only 1 is registered as device:
> bcma: Core 0 found: ChipCommon (manuf 0x4BF, id 0x800, rev 0x22, class 0x0)
> bcma: Core 1 found: IEEE 802.11 (manuf 0x4BF, id 0x812, rev 0x17, class 0x0)
> bcma: Core 2 found: PCIe (manuf 0x4BF, id 0x820, rev 0x0F, class 0x0)
>
> The dereference comes out from
> static void bcma_unregister_cores(struct bcma_bus *bus)
>
> There is a simple loop:
> list_for_each_entry(core, &bus->cores, list) {
>        if (core->dev_registered)
>                device_unregister(&core->dev);
> }
>
>
> So when I unload bcma after I got driver (b43) for 0x812 core, I get
> NULL pointer dereference.
>
> Any tip, why does it happen?

I've tracked where does crash really happen (kobject_del does not
really say much). The real forwardtrace is:
device_unregister → device_del → kobject_del → kobj_kset_leave →
kobj_kset_leave → list_del_init

If you take a look at list_del_init, it touches "prev" and "next". So
I've added some debugging:
pr_info("core->dev.kobj.entry.prev: 0x%p\n", core->dev.kobj.entry.prev);
pr_info("core->dev.kobj.entry.next: 0x%p\n", core->dev.kobj.entry.next);

modprobe bcma && rmmod bcma:
[  342.866366] bcma: Unregistering device for core 0x812
[  342.866380] bcma: core->dev.kobj.entry.prev: 0xdb82780c
[  342.866382] bcma: core->dev.kobj.entry.next: 0xda044980

modprobe bcma && modprobe b43 && rmmod b43 && rmmod bcma:
[  612.819306] bcma: Unregistering device for core 0x812
[  612.819320] bcma: core->dev.kobj.entry.prev: 0x  (null)
[  612.819322] bcma: core->dev.kobj.entry.next: 0xd7fe6614
[  612.819971] BUG: unable to handle kernel NULL pointer dereference at   (null)
[  612.819989] IP: [<c03dcfbe>] kobject_del+0x2e/0x60

I've no idea why kobj entry list gets corrupted after loading b43
driver supporting device for core 0x812.

Any help now maybe?

-- 
Rafał

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug in BCMA: device_unregister causing "NULL pointer dereference at"
  2011-07-21  7:18 ` Rafał Miłecki
@ 2011-07-21 16:33   ` Pavel Roskin
  0 siblings, 0 replies; 6+ messages in thread
From: Pavel Roskin @ 2011-07-21 16:33 UTC (permalink / raw)
  To: Rafał Miłecki; +Cc: linux-wireless, Linux Kernel Mailing List

On 07/21/2011 03:18 AM, Rafał Miłecki wrote:

>> So when I unload bcma after I got driver (b43) for 0x812 core, I get
>> NULL pointer dereference.
>>
>> Any tip, why does it happen?
>
> I've tracked where does crash really happen (kobject_del does not
> really say much). The real forwardtrace is:
> device_unregister → device_del → kobject_del → kobj_kset_leave →
> kobj_kset_leave → list_del_init
>
> If you take a look at list_del_init, it touches "prev" and "next". So
> I've added some debugging:
> pr_info("core->dev.kobj.entry.prev: 0x%p\n", core->dev.kobj.entry.prev);
> pr_info("core->dev.kobj.entry.next: 0x%p\n", core->dev.kobj.entry.next);

There are options for debugging that you may want to enable:

CONFIG_DEBUG_LIST
CONFIG_DEBUG_OBJECTS
CONFIG_DEBUG_KOBJECT

Actually, consider enabling most debug options as possible, except 
perhaps the most time consuming (such as CONFIG_DEBUG_KMEMLEAK).  Maybe 
you are passing a freed pointer or something.

Print the pointers you are passing to device_register() and 
device_unregister().

> [  612.819320] bcma: core->dev.kobj.entry.prev: 0x  (null)

You may want to make it a macro and print it in most bcma functions.

-- 
Regards,
Pavel Roskin

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-07-21 16:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-07 15:25 Bug in BCMA: device_unregister causing "NULL pointer dereference at" Rafał Miłecki
2011-07-07 15:27 ` Rafał Miłecki
2011-07-14 14:45 ` Francois Romieu
2011-07-21  7:14   ` Rafał Miłecki
2011-07-21  7:18 ` Rafał Miłecki
2011-07-21 16:33   ` Pavel Roskin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).