driver core: class: fix slab-use-after-free Read in class_register()
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 1 Apr 2023 10:09:26 +0000 (12:09 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 1 Apr 2023 10:20:54 +0000 (12:20 +0200)
Syzbot found that we had forgotten to unregister the lock_class_key when
using it in commit dcfbb67e48a2 ("driver core: class: use lock_class_key
already present in struct subsys_private") so fix that up and correctly
release it when done.

Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Reported-and-tested-by: <syzbot+41d665317c811d4d88aa@syzkaller.appspotmail.com>
Fixes: dcfbb67e48a2 ("driver core: class: use lock_class_key already present in struct subsys_private")
Link: https://lore.kernel.org/r/2023040126-blandness-duckling-bd55@gregkh
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/class.c

index 06b96d6faa19c26603a6e2ddf35eefaba1f065db..65502bd7d5c571eb18b9d769829b479c981cc849 100644 (file)
@@ -103,6 +103,7 @@ static void class_release(struct kobject *kobj)
                pr_debug("class '%s' does not have a release() function, "
                         "be careful\n", class->name);
 
+       lockdep_unregister_key(&cp->lock_key);
        kfree(cp);
 }