summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorBenjamin Tissoires <bentiss@kernel.org>2024-06-26 16:46:22 +0300
committerBenjamin Tissoires <bentiss@kernel.org>2024-06-27 11:58:00 +0300
commitebae0b2a6f4b3b949f30f076fbc65d3b0bb04785 (patch)
tree8ec96bb7ba7659ab7bb01c1c20f02c96547e3895 /drivers
parent9e16bada9299d74fcce1f6b03606a08a2c16da81 (diff)
downloadlinux-ebae0b2a6f4b3b949f30f076fbc65d3b0bb04785.tar.xz
HID: bpf: fix dispatch_hid_bpf_device_event uninitialized ret value
Looks like if a bpf program gets inserted and then removed, hdev->bpf.device_data is then allocated, but the loop iterating over the bpf program is never assigning ret. This is a problem and also revealed another bug in which only the last value of ret was checked. This effectively meant than only the last program in the chain could change the size of the incoming buffer. Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Link: https://lore.kernel.org/all/00f7b624-219f-4a05-a7ad-5335f15a41c7@moroto.mountain Fixes: 4a86220e046d ("HID: bpf: remove tracing HID-BPF capability") Link: https://patch.msgid.link/20240626-hid_hw_req_bpf-v2-1-cfd60fb6c79f@kernel.org Acked-by: Jiri Kosina <jkosina@suse.com> Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hid/bpf/hid_bpf_dispatch.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf_dispatch.c
index 06cc628e7bb4..b7b11a7c69db 100644
--- a/drivers/hid/bpf/hid_bpf_dispatch.c
+++ b/drivers/hid/bpf/hid_bpf_dispatch.c
@@ -57,11 +57,12 @@ dispatch_hid_bpf_device_event(struct hid_device *hdev, enum hid_report_type type
}
if (ret)
- ctx_kern.ctx.retval = ret;
+ ctx_kern.ctx.size = ret;
}
}
rcu_read_unlock();
+ ret = ctx_kern.ctx.size;
if (ret) {
if (ret > ctx_kern.ctx.allocated_size)
return ERR_PTR(-EINVAL);