Re: [PATCH HID 03/12] HID: bpf: add HID-BPF hooks for hid_hw_raw_requests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jun 21, 2024 at 1:56 AM Benjamin Tissoires <bentiss@xxxxxxxxxx> wrote:
>
> This allows to intercept and prevent or change the behavior of
> hid_hw_raw_request() from a bpf program.
>
> The intent is to solve a couple of use case:
> - firewalling a HID device: a firewall can monitor who opens the hidraw
>   nodes and then prevent or allow access to write operations on that
>   hidraw node.
> - change the behavior of a device and emulate a new HID feature request
>
> The hook is allowed to be run as sleepable so it can itself call
> hid_bpf_hw_request(), which allows to "convert" one feature request into
> another or even call the feature request on a different HID device on the
> same physical device.
>
> Signed-off-by: Benjamin Tissoires <bentiss@xxxxxxxxxx>
>
> ---
>
> Here checkpatch complains about:
> WARNING: use of RCU tasks trace is incorrect outside BPF or core RCU code
>
> However, we are jumping in BPF code, so I think this is correct, but I'd
> like to have the opinion on the BPF folks.
> ---
>  drivers/hid/bpf/hid_bpf_dispatch.c   | 36 ++++++++++++++++++++++++++++++++++++
>  drivers/hid/bpf/hid_bpf_struct_ops.c |  1 +
>  drivers/hid/hid-core.c               |  6 ++++++
>  include/linux/hid_bpf.h              | 35 +++++++++++++++++++++++++++++++++++
>  4 files changed, 78 insertions(+)
>
> diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf_dispatch.c
> index 2df31decaac3..813b53119b85 100644
> --- a/drivers/hid/bpf/hid_bpf_dispatch.c
> +++ b/drivers/hid/bpf/hid_bpf_dispatch.c
> @@ -74,6 +74,42 @@ dispatch_hid_bpf_device_event(struct hid_device *hdev, enum hid_report_type type
>  }
>  EXPORT_SYMBOL_GPL(dispatch_hid_bpf_device_event);
>
> +int dispatch_hid_bpf_raw_requests(struct hid_device *hdev,
> +                                 unsigned char reportnum, u8 *buf,
> +                                 u32 size, enum hid_report_type rtype,
> +                                 enum hid_class_request reqtype,
> +                                 u64 source)
> +{
> +       struct hid_bpf_ctx_kern ctx_kern = {
> +               .ctx = {
> +                       .hid = hdev,
> +                       .allocated_size = size,
> +                       .size = size,
> +               },
> +               .data = buf,
> +       };
> +       struct hid_bpf_ops *e;
> +       int ret;
> +
> +       if (rtype >= HID_REPORT_TYPES)
> +               return -EINVAL;
> +
> +       rcu_read_lock_trace();

checkpatch is correct.
What is this for?





[Index of Archives]     [Linux Media Devel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Linux Wireless Networking]     [Linux Omap]

  Powered by Linux