diff options
author | Bart Van Assche <bvanassche@acm.org> | 2014-01-04 08:21:42 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-01-08 18:36:18 -0500 |
commit | 174be70b638ceb1038f466b5ca014f6b1d9c8a59 (patch) | |
tree | 26a76fb6f4b20b6601e1abaf4c34c2446754b548 | |
parent | 98233b21cd6e6b9bd8ad5d4756bda1c051567468 (diff) |
driver-core: Fix use-after-free triggered by bus_unregister()
Avoid that bus_unregister() triggers a use-after-free with
CONFIG_DEBUG_KOBJECT_RELEASE=y. This patch avoids that the
following sequence triggers a kernel crash with memory poisoning
enabled:
* bus_register()
* driver_register()
* driver_unregister()
* bus_unregister()
The above sequence causes the bus private data to be freed from
inside the bus_unregister() call although it is not guaranteed in
that function that the reference count on the bus private data has
dropped to zero. As an example, with CONFIG_DEBUG_KOBJECT_RELEASE=y
the ${bus}/drivers kobject is still holding a reference on
bus->p->subsys.kobj via its parent pointer at the time the bus
private data is freed. Fix this by deferring freeing the bus private
data until the last kobject_put() call on bus->p->subsys.kobj.
The kernel oops triggered by the above sequence and with memory
poisoning enabled and that is fixed by this patch is as follows:
general protection fault: 0000 [#1] PREEMPT SMP
CPU: 3 PID: 2711 Comm: kworker/3:32 Tainted: G W O 3.13.0-rc4-debug+ #1
Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
Workqueue: events kobject_delayed_cleanup
task: ffff880037f866d0 ti: ffff88003b638000 task.ti: ffff88003b638000
Call Trace:
[<ffffffff81263105>] ? kobject_get_path+0x25/0x100
[<ffffffff81264354>] kobject_uevent_env+0x134/0x600
[<ffffffff8126482b>] kobject_uevent+0xb/0x10
[<ffffffff81262fa2>] kobject_delayed_cleanup+0xc2/0x1b0
[<ffffffff8106c047>] process_one_work+0x217/0x700
[<ffffffff8106bfdb>] ? process_one_work+0x1ab/0x700
[<ffffffff8106c64b>] worker_thread+0x11b/0x3a0
[<ffffffff8106c530>] ? process_one_work+0x700/0x700
[<ffffffff81074b70>] kthread+0xf0/0x110
[<ffffffff81074a80>] ? insert_kthread_work+0x80/0x80
[<ffffffff815673bc>] ret_from_fork+0x7c/0xb0
[<ffffffff81074a80>] ? insert_kthread_work+0x80/0x80
Code: 89 f8 48 89 e5 f6 82 c0 27 63 81 20 74 15 0f 1f 44 00 00 48 83 c0 01 0f b6 10 f6 82 c0 27 63 81 20 75 f0 5d c3 66 0f 1f 44 00 00 <80> 3f 00 55 48 89 e5 74 15 48 89 f8 0f 1f 40 00 48 83 c0 01 80
RIP [<ffffffff81267ed0>] strlen+0x0/0x30
RSP <ffff88003b639c70>
---[ end trace 210f883ef80376aa ]---
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Acked-by: Ming Lei <ming.lei@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/base/bus.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 73f6c2925281..59dc8086e4fa 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c | |||
@@ -146,8 +146,19 @@ void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr) | |||
146 | } | 146 | } |
147 | EXPORT_SYMBOL_GPL(bus_remove_file); | 147 | EXPORT_SYMBOL_GPL(bus_remove_file); |
148 | 148 | ||
149 | static void bus_release(struct kobject *kobj) | ||
150 | { | ||
151 | struct subsys_private *priv = | ||
152 | container_of(kobj, typeof(*priv), subsys.kobj); | ||
153 | struct bus_type *bus = priv->bus; | ||
154 | |||
155 | kfree(priv); | ||
156 | bus->p = NULL; | ||
157 | } | ||
158 | |||
149 | static struct kobj_type bus_ktype = { | 159 | static struct kobj_type bus_ktype = { |
150 | .sysfs_ops = &bus_sysfs_ops, | 160 | .sysfs_ops = &bus_sysfs_ops, |
161 | .release = bus_release, | ||
151 | }; | 162 | }; |
152 | 163 | ||
153 | static int bus_uevent_filter(struct kset *kset, struct kobject *kobj) | 164 | static int bus_uevent_filter(struct kset *kset, struct kobject *kobj) |
@@ -953,8 +964,6 @@ void bus_unregister(struct bus_type *bus) | |||
953 | kset_unregister(bus->p->devices_kset); | 964 | kset_unregister(bus->p->devices_kset); |
954 | bus_remove_file(bus, &bus_attr_uevent); | 965 | bus_remove_file(bus, &bus_attr_uevent); |
955 | kset_unregister(&bus->p->subsys); | 966 | kset_unregister(&bus->p->subsys); |
956 | kfree(bus->p); | ||
957 | bus->p = NULL; | ||
958 | } | 967 | } |
959 | EXPORT_SYMBOL_GPL(bus_unregister); | 968 | EXPORT_SYMBOL_GPL(bus_unregister); |
960 | 969 | ||