Skip to content

Commit 6fd47ef

Browse files
author
Benjamin Tissoires
committed
HID: bpf: allow write access to quirks field in struct hid_device
This allows to give more control from BPF during report descriptor fixup. We already reset the quirks before calling ->probe(), so now we reset it once before calling hid_bpf_rdesc_fixup(). Reviewed-by: Peter Hutterer <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent 7316fef commit 6fd47ef

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

drivers/hid/bpf/hid_bpf_struct_ops.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static int hid_bpf_ops_btf_struct_access(struct bpf_verifier_log *log,
7979
WRITE_RANGE(hid_device, name, true),
8080
WRITE_RANGE(hid_device, uniq, true),
8181
WRITE_RANGE(hid_device, phys, true),
82+
WRITE_RANGE(hid_device, quirks, false),
8283
};
8384
#undef WRITE_RANGE
8485
const struct btf_type *state = NULL;

drivers/hid/hid-core.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,6 +2709,12 @@ static int __hid_device_probe(struct hid_device *hdev, struct hid_driver *hdrv)
27092709
int ret;
27102710

27112711
if (!hdev->bpf_rsize) {
2712+
unsigned int quirks;
2713+
2714+
/* reset the quirks that has been previously set */
2715+
quirks = hid_lookup_quirk(hdev);
2716+
hdev->quirks = quirks;
2717+
27122718
/* in case a bpf program gets detached, we need to free the old one */
27132719
hid_free_bpf_rdesc(hdev);
27142720

@@ -2718,6 +2724,9 @@ static int __hid_device_probe(struct hid_device *hdev, struct hid_driver *hdrv)
27182724
/* call_hid_bpf_rdesc_fixup will always return a valid pointer */
27192725
hdev->bpf_rdesc = call_hid_bpf_rdesc_fixup(hdev, hdev->dev_rdesc,
27202726
&hdev->bpf_rsize);
2727+
if (quirks ^ hdev->quirks)
2728+
hid_info(hdev, "HID-BPF toggled quirks on the device: %04x",
2729+
quirks ^ hdev->quirks);
27212730
}
27222731

27232732
if (!hid_check_device_match(hdev, hdrv, &id))
@@ -2727,8 +2736,6 @@ static int __hid_device_probe(struct hid_device *hdev, struct hid_driver *hdrv)
27272736
if (!hdev->devres_group_id)
27282737
return -ENOMEM;
27292738

2730-
/* reset the quirks that has been previously set */
2731-
hdev->quirks = hid_lookup_quirk(hdev);
27322739
hdev->driver = hdrv;
27332740

27342741
if (hdrv->probe) {

0 commit comments

Comments
 (0)