All of lore.kernel.org
 help / color / mirror / Atom feed
* [0/3] Driver core patches for kernel 3.14
@ 2014-01-04 13:19 Bart Van Assche
  2014-01-04 13:20 ` [PATCH 1/3] kobject: Fix source code comment spelling Bart Van Assche
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Bart Van Assche @ 2014-01-04 13:19 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Ming Lei, linux-kernel

This series consists of the following three patches:
0001-kobject-Fix-source-code-comment-spelling.patch
0002-firmware-loader-Add-sparse-annotation.patch
0003-driver-core-Fix-use-after-free-triggered-by-bus_unre.patch


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

* [PATCH 1/3] kobject: Fix source code comment spelling
  2014-01-04 13:19 [0/3] Driver core patches for kernel 3.14 Bart Van Assche
@ 2014-01-04 13:20 ` Bart Van Assche
  2014-01-04 13:20 ` [PATCH 2/3] firmware loader: Add sparse annotation Bart Van Assche
  2014-01-04 13:21 ` [PATCH 3/3] driver-core: Fix use-after-free triggered by bus_unregister() Bart Van Assche
  2 siblings, 0 replies; 6+ messages in thread
From: Bart Van Assche @ 2014-01-04 13:20 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Ming Lei, linux-kernel

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 lib/kobject.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index 5b4b888..0061f55 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -346,7 +346,7 @@ static int kobject_add_varg(struct kobject *kobj, struct kobject *parent,
  *
  * If @parent is set, then the parent of the @kobj will be set to it.
  * If @parent is NULL, then the parent of the @kobj will be set to the
- * kobject associted with the kset assigned to this kobject.  If no kset
+ * kobject associated with the kset assigned to this kobject.  If no kset
  * is assigned to the kobject, then the kobject will be located in the
  * root of the sysfs tree.
  *
-- 
1.8.1.4


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

* [PATCH 2/3] firmware loader: Add sparse annotation
  2014-01-04 13:19 [0/3] Driver core patches for kernel 3.14 Bart Van Assche
  2014-01-04 13:20 ` [PATCH 1/3] kobject: Fix source code comment spelling Bart Van Assche
@ 2014-01-04 13:20 ` Bart Van Assche
  2014-01-08  1:40   ` Ming Lei
  2014-01-04 13:21 ` [PATCH 3/3] driver-core: Fix use-after-free triggered by bus_unregister() Bart Van Assche
  2 siblings, 1 reply; 6+ messages in thread
From: Bart Van Assche @ 2014-01-04 13:20 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Ming Lei, linux-kernel

Avoid that sparse reports the following warning on __fw_free_buf():

drivers/base/firmware_class.c:230:9: warning: context imbalance in '__fw_free_buf' - unexpected unlock

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: Ming Lei <ming.lei@canonical.com>
---
 drivers/base/firmware_class.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index eb8fb94..c2e4540 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -219,6 +219,7 @@ static int fw_lookup_and_allocate_buf(const char *fw_name,
 }
 
 static void __fw_free_buf(struct kref *ref)
+	__releases(&fwc->lock)
 {
 	struct firmware_buf *buf = to_fwbuf(ref);
 	struct firmware_cache *fwc = buf->fwc;
-- 
1.8.1.4


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

* [PATCH 3/3] driver-core: Fix use-after-free triggered by bus_unregister()
  2014-01-04 13:19 [0/3] Driver core patches for kernel 3.14 Bart Van Assche
  2014-01-04 13:20 ` [PATCH 1/3] kobject: Fix source code comment spelling Bart Van Assche
  2014-01-04 13:20 ` [PATCH 2/3] firmware loader: Add sparse annotation Bart Van Assche
@ 2014-01-04 13:21 ` Bart Van Assche
  2014-01-08  2:01   ` Ming Lei
  2 siblings, 1 reply; 6+ messages in thread
From: Bart Van Assche @ 2014-01-04 13:21 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Ming Lei, linux-kernel

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>
---
 drivers/base/bus.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 73f6c29..59dc808 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)
 }
 EXPORT_SYMBOL_GPL(bus_remove_file);
 
+static void bus_release(struct kobject *kobj)
+{
+	struct subsys_private *priv =
+		container_of(kobj, typeof(*priv), subsys.kobj);
+	struct bus_type *bus = priv->bus;
+
+	kfree(priv);
+	bus->p = NULL;
+}
+
 static struct kobj_type bus_ktype = {
 	.sysfs_ops	= &bus_sysfs_ops,
+	.release	= bus_release,
 };
 
 static int bus_uevent_filter(struct kset *kset, struct kobject *kobj)
@@ -953,8 +964,6 @@ void bus_unregister(struct bus_type *bus)
 	kset_unregister(bus->p->devices_kset);
 	bus_remove_file(bus, &bus_attr_uevent);
 	kset_unregister(&bus->p->subsys);
-	kfree(bus->p);
-	bus->p = NULL;
 }
 EXPORT_SYMBOL_GPL(bus_unregister);
 
-- 
1.8.1.4


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

* Re: [PATCH 2/3] firmware loader: Add sparse annotation
  2014-01-04 13:20 ` [PATCH 2/3] firmware loader: Add sparse annotation Bart Van Assche
@ 2014-01-08  1:40   ` Ming Lei
  0 siblings, 0 replies; 6+ messages in thread
From: Ming Lei @ 2014-01-08  1:40 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: Greg Kroah-Hartman, linux-kernel

On Sat, Jan 4, 2014 at 9:20 PM, Bart Van Assche <bvanassche@acm.org> wrote:
> Avoid that sparse reports the following warning on __fw_free_buf():
>
> drivers/base/firmware_class.c:230:9: warning: context imbalance in '__fw_free_buf' - unexpected unlock
>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> Cc: Ming Lei <ming.lei@canonical.com>

Bart, thanks.

Acked-by: Ming Lei <ming.lei@canonical.com>


Thanks,
--
Ming Lei

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

* Re: [PATCH 3/3] driver-core: Fix use-after-free triggered by bus_unregister()
  2014-01-04 13:21 ` [PATCH 3/3] driver-core: Fix use-after-free triggered by bus_unregister() Bart Van Assche
@ 2014-01-08  2:01   ` Ming Lei
  0 siblings, 0 replies; 6+ messages in thread
From: Ming Lei @ 2014-01-08  2:01 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: Greg Kroah-Hartman, linux-kernel

On Sat, Jan 4, 2014 at 9:21 PM, Bart Van Assche <bvanassche@acm.org> wrote:
> 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>
> ---
>  drivers/base/bus.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/base/bus.c b/drivers/base/bus.c
> index 73f6c29..59dc808 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)
>  }
>  EXPORT_SYMBOL_GPL(bus_remove_file);
>
> +static void bus_release(struct kobject *kobj)
> +{
> +       struct subsys_private *priv =
> +               container_of(kobj, typeof(*priv), subsys.kobj);
> +       struct bus_type *bus = priv->bus;
> +
> +       kfree(priv);
> +       bus->p = NULL;
> +}
> +
>  static struct kobj_type bus_ktype = {
>         .sysfs_ops      = &bus_sysfs_ops,
> +       .release        = bus_release,
>  };
>
>  static int bus_uevent_filter(struct kset *kset, struct kobject *kobj)
> @@ -953,8 +964,6 @@ void bus_unregister(struct bus_type *bus)
>         kset_unregister(bus->p->devices_kset);
>         bus_remove_file(bus, &bus_attr_uevent);
>         kset_unregister(&bus->p->subsys);
> -       kfree(bus->p);
> -       bus->p = NULL;
>  }
>  EXPORT_SYMBOL_GPL(bus_unregister);

Looks the fix is fine,

Acked-by: Ming Lei <ming.lei@canonical.com>


Thanks,
--
Ming Lei

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

end of thread, other threads:[~2014-01-08  2:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-04 13:19 [0/3] Driver core patches for kernel 3.14 Bart Van Assche
2014-01-04 13:20 ` [PATCH 1/3] kobject: Fix source code comment spelling Bart Van Assche
2014-01-04 13:20 ` [PATCH 2/3] firmware loader: Add sparse annotation Bart Van Assche
2014-01-08  1:40   ` Ming Lei
2014-01-04 13:21 ` [PATCH 3/3] driver-core: Fix use-after-free triggered by bus_unregister() Bart Van Assche
2014-01-08  2:01   ` Ming Lei

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.