]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
driver core: platform: use the correct callback type for bus_find_device
authorSami Tolvanen <samitolvanen@google.com>
Tue, 12 Nov 2019 21:41:56 +0000 (13:41 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Dec 2019 21:30:45 +0000 (22:30 +0100)
commit 492c88720d36eb662f9f10c1633f7726fbb07fc4 upstream.

platform_find_device_by_driver calls bus_find_device and passes
platform_match as the callback function. Casting the function to a
mismatching type trips indirect call Control-Flow Integrity (CFI) checking.

This change adds a callback function with the correct type and instead
of casting the function, explicitly casts the second parameter to struct
device_driver* as expected by platform_match.

Fixes: 36f3313d6bff9 ("platform: Add platform_find_device_by_driver() helper")
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20191112214156.3430-1-samitolvanen@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/platform.c

index b230beb6ccb41ba8beb5fbaf87972f69b94a33e3..3c0cd20925b71c5f82cde27402546583239ec2ff 100644 (file)
@@ -1278,6 +1278,11 @@ struct bus_type platform_bus_type = {
 };
 EXPORT_SYMBOL_GPL(platform_bus_type);
 
+static inline int __platform_match(struct device *dev, const void *drv)
+{
+       return platform_match(dev, (struct device_driver *)drv);
+}
+
 /**
  * platform_find_device_by_driver - Find a platform device with a given
  * driver.
@@ -1288,7 +1293,7 @@ struct device *platform_find_device_by_driver(struct device *start,
                                              const struct device_driver *drv)
 {
        return bus_find_device(&platform_bus_type, start, drv,
-                              (void *)platform_match);
+                              __platform_match);
 }
 EXPORT_SYMBOL_GPL(platform_find_device_by_driver);