]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
HID: bpf: prevent the same struct_ops to be attached more than once
authorBenjamin Tissoires <bentiss@kernel.org>
Tue, 23 Jul 2024 16:21:53 +0000 (18:21 +0200)
committerBenjamin Tissoires <bentiss@kernel.org>
Wed, 24 Jul 2024 16:27:21 +0000 (18:27 +0200)
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>
drivers/hid/bpf/hid_bpf_struct_ops.c

index f59cce6e437f7720f028d988d79b23a5810dfedd..cd696c59ba0f4faec12234cb3154ca09dced5384 100644 (file)
@@ -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);
@@ -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)