ANDROID: GKI: add vendor hooks to avoid unsupported usb device probing

In GKI config, a lot of USB class drivers are buitin,
these drivers are automatically loaded, so we cannot disable devices probed
if the devices are connected.
We need to disable unsupported USB devices for security reason,
so need this vendor hook to ignore to bind drivers on static id_table.
if vendor hook return bypass as true, then ignore match up staic id_table.
But dynamic id is still allowed since it's configured by userspace.

Bug: 278041365

Change-Id: I1f5ca166fd49ecbc7fd406ceff1f80f3646596db
Signed-off-by: Norihiko Hama <Norihiko.Hama@alpsalpine.com>
This commit is contained in:
Norihiko Hama
2023-06-07 19:10:50 +09:00
committed by Treehugger Robot
parent 2f4e942037
commit afa948d5af
3 changed files with 27 additions and 3 deletions

View File

@@ -335,6 +335,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_get_thermal_zone_device);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_psci_tos_resident_on);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_psci_cpu_suspend);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_usb_new_device_added);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_usb_device_match_id_bypass);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_regmap_update);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alter_mutex_list_add);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mutex_unlock_slowpath);

View File

@@ -31,6 +31,7 @@
#include <linux/usb.h>
#include <linux/usb/quirks.h>
#include <linux/usb/hcd.h>
#include <trace/hooks/usb.h>
#include "usb.h"
@@ -341,8 +342,16 @@ static int usb_probe_interface(struct device *dev)
}
id = usb_match_dynamic_id(intf, driver);
if (!id)
if (!id) {
id = usb_match_id(intf, driver->id_table);
if (id) {
bool bypass = false;
trace_android_vh_usb_device_match_id_bypass(intf, driver, &bypass);
if (bypass)
id = NULL;
}
}
if (!id)
return error;
@@ -887,8 +896,13 @@ static int usb_device_match(struct device *dev, struct device_driver *drv)
usb_drv = to_usb_driver(drv);
id = usb_match_id(intf, usb_drv->id_table);
if (id)
return 1;
if (id) {
bool bypass = false;
trace_android_vh_usb_device_match_id_bypass(intf, usb_drv, &bypass);
if (!bypass)
return 1;
}
id = usb_match_dynamic_id(intf, usb_drv);
if (id)

View File

@@ -20,6 +20,15 @@ struct usb_device;
DECLARE_HOOK(android_vh_usb_new_device_added,
TP_PROTO(struct usb_device *udev, int *err),
TP_ARGS(udev, err));
struct usb_interface;
struct usb_driver;
DECLARE_HOOK(android_vh_usb_device_match_id_bypass,
TP_PROTO(struct usb_interface *intf,
struct usb_driver *usb_drv,
bool *bypass),
TP_ARGS(intf, usb_drv, bypass));
#endif /* _TRACE_HOOK_USB_H */
/* This part must be outside protection */
#include <trace/define_trace.h>