Skip to content

Commit

Permalink
HID: bpf: prevent the same struct_ops to be attached more than once
Browse files Browse the repository at this point in the history
If the struct_ops is already attached, we should bail out or we will
end up in various locks and pointer issues while unregistering.

Link: https://patch.msgid.link/[email protected]
Signed-off-by: Benjamin Tissoires <[email protected]>
  • Loading branch information
Benjamin Tissoires committed Jul 24, 2024
1 parent f64c1a4 commit acd34cf
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/hid/bpf/hid_bpf_struct_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ static int hid_bpf_reg(void *kdata, struct bpf_link *link)
struct hid_device *hdev;
int count, err = 0;

/* prevent multiple attach of the same struct_ops */
if (ops->hdev)
return -EINVAL;

hdev = hid_get_device(ops->hid_id);
if (IS_ERR(hdev))
return PTR_ERR(hdev);
Expand Down Expand Up @@ -248,6 +252,7 @@ static void hid_bpf_unreg(void *kdata, struct bpf_link *link)

list_del_rcu(&ops->list);
synchronize_srcu(&hdev->bpf.srcu);
ops->hdev = NULL;

reconnect = hdev->bpf.rdesc_ops == ops;
if (reconnect)
Expand Down

0 comments on commit acd34cf

Please sign in to comment.