Skip to content

Commit acd34cf

Browse files
author
Benjamin Tissoires
committed
HID: bpf: prevent the same struct_ops to be attached more than once
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/20240723-fix-6-11-bpf-v1-3-b9d770346784@kernel.org Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
1 parent f64c1a4 commit acd34cf

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/hid/bpf/hid_bpf_struct_ops.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ static int hid_bpf_reg(void *kdata, struct bpf_link *link)
183183
struct hid_device *hdev;
184184
int count, err = 0;
185185

186+
/* prevent multiple attach of the same struct_ops */
187+
if (ops->hdev)
188+
return -EINVAL;
189+
186190
hdev = hid_get_device(ops->hid_id);
187191
if (IS_ERR(hdev))
188192
return PTR_ERR(hdev);
@@ -248,6 +252,7 @@ static void hid_bpf_unreg(void *kdata, struct bpf_link *link)
248252

249253
list_del_rcu(&ops->list);
250254
synchronize_srcu(&hdev->bpf.srcu);
255+
ops->hdev = NULL;
251256

252257
reconnect = hdev->bpf.rdesc_ops == ops;
253258
if (reconnect)

0 commit comments

Comments
 (0)