Re: [rtc-linux] Re: [BUG 2.6.30_rc5] Null pointer dereference in rtc-cmos driver

From: Kay Sievers
Date: Sat May 16 2009 - 19:37:47 EST


On Sun, May 17, 2009 at 00:49, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:

> This should fix the symptoms:

> +++ a/drivers/rtc/rtc-cmos.c
> @@ -1179,7 +1179,9 @@ static int __init cmos_init(void)
> Â Â Â Âint retval = 0;
>
> Â#ifdef CONFIG_PNP
> - Â Â Â pnp_register_driver(&cmos_pnp_driver);
> + Â Â Â retval = pnp_register_driver(&cmos_pnp_driver);
> + Â Â Â if (retval < 0)
> + Â Â Â Â Â Â Â return retval;
> Â#endif

That looks like a good fix.

> Can someone please test it?

I'll try to reproduce it.

>> > > [ Â 10.428728] BUG: unable to handle kernel NULL pointer dereference at 00000018
...
>> > > [ Â 10.459009] Â[<c03037e6>] ? driver_remove_file+0xf/0x11

> But we have arguably multiple more bugs here.
> pnp_unregister_driver(unregistered-driver) shouldn't oops the kernel.
> Neither pnp_unregister_driver() nor driver_unregister() nor
> bus_remove_driver() nor driver_remove_file() nor sysfs_remove_file()
> detected this.
>
> Kay, Greg: there are already a pile of checks on that path, but it
> seems there's one missing. ÂCould you please take a look and decide at
> the design level where this check should be occurring?

The issue is caused by a trying to unregister a driver which never got
registered before. I guess we try to access the private part of the
driver to reach the kobject, but for unregistered drivers there is no
such thing at that time. In:
driver_remove_file()
we try to access the private part:
sysfs_remove_file(&drv->p->kobj, ...
and that is NULL, for an unregistered driver, I would expect.

I'll try to reproduce the issue, and see if your fix cover the real problem.
If I can reproduce it, I'll take a look where to add a check for this.

Thanks,
Kay
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/