Skip to content

Commit 492c887

Browse files
samitolvanengregkh
authored andcommitted
driver core: platform: use the correct callback type for bus_find_device
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: 36f3313 ("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>
1 parent 030cc78 commit 492c887

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎drivers/base/platform.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,11 @@ struct bus_type platform_bus_type = {
13101310
};
13111311
EXPORT_SYMBOL_GPL(platform_bus_type);
13121312

1313+
static inline int __platform_match(struct device *dev, const void *drv)
1314+
{
1315+
return platform_match(dev, (struct device_driver *)drv);
1316+
}
1317+
13131318
/**
13141319
* platform_find_device_by_driver - Find a platform device with a given
13151320
* driver.
@@ -1320,7 +1325,7 @@ struct device *platform_find_device_by_driver(struct device *start,
13201325
const struct device_driver *drv)
13211326
{
13221327
return bus_find_device(&platform_bus_type, start, drv,
1323-
(void *)platform_match);
1328+
__platform_match);
13241329
}
13251330
EXPORT_SYMBOL_GPL(platform_find_device_by_driver);
13261331

0 commit comments

Comments
 (0)