[PATCH] driver core: class : fix slab-use-after-free Read in class_register()

From: Greg Kroah-Hartman
Date: Sat Apr 01 2023 - 06:10:37 EST


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@xxxxxxxxxx>
Reported-and-tested-by: <syzbot+41d665317c811d4d88aa@xxxxxxxxxxxxxxxxxxxxxxxxx>
Fixes: dcfbb67e48a2 ("driver core: class: use lock_class_key already present in struct subsys_private")
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
drivers/base/class.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index 2991936c80db..ac1808d1a2e8 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -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);
}

--
2.40.0