diff options
| author | Benjamin Tissoires <bentiss@kernel.org> | 2024-06-26 15:46:23 +0200 | 
|---|---|---|
| committer | Benjamin Tissoires <bentiss@kernel.org> | 2024-06-27 10:58:19 +0200 | 
| commit | 67eccf151d76a9939ad8a50c6db5cb486b01df24 (patch) | |
| tree | 1a2b0d02140df64b820dded3ccc511d38d47ee1d /drivers/hid/bpf | |
| parent | ebae0b2a6f4b3b949f30f076fbc65d3b0bb04785 (diff) | |
HID: add source argument to HID low level functions
This allows to know who actually sent what when we process the request
to the device.
This will be useful for a BPF firewall program to allow or not requests
coming from a dedicated hidraw node client.
Link: https://patch.msgid.link/20240626-hid_hw_req_bpf-v2-2-cfd60fb6c79f@kernel.org
Acked-by: Jiri Kosina <jkosina@suse.com>
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
Diffstat (limited to 'drivers/hid/bpf')
| -rw-r--r-- | drivers/hid/bpf/hid_bpf_dispatch.c | 12 | ||||
| -rw-r--r-- | drivers/hid/bpf/hid_bpf_struct_ops.c | 2 | 
2 files changed, 8 insertions, 6 deletions
| diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf_dispatch.c index b7b11a7c69db..2df31decaac3 100644 --- a/drivers/hid/bpf/hid_bpf_dispatch.c +++ b/drivers/hid/bpf/hid_bpf_dispatch.c @@ -24,7 +24,7 @@ EXPORT_SYMBOL(hid_ops);  u8 *  dispatch_hid_bpf_device_event(struct hid_device *hdev, enum hid_report_type type, u8 *data, -			      u32 *size, int interrupt) +			      u32 *size, int interrupt, u64 source)  {  	struct hid_bpf_ctx_kern ctx_kern = {  		.ctx = { @@ -50,7 +50,7 @@ dispatch_hid_bpf_device_event(struct hid_device *hdev, enum hid_report_type type  	rcu_read_lock();  	list_for_each_entry_rcu(e, &hdev->bpf.prog_list, list) {  		if (e->hid_device_event) { -			ret = e->hid_device_event(&ctx_kern.ctx, type); +			ret = e->hid_device_event(&ctx_kern.ctx, type, source);  			if (ret < 0) {  				rcu_read_unlock();  				return ERR_PTR(ret); @@ -359,7 +359,8 @@ hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz,  					      dma_data,  					      size,  					      rtype, -					      reqtype); +					      reqtype, +					      (__u64)ctx);  	if (ret > 0)  		memcpy(buf, dma_data, ret); @@ -398,7 +399,8 @@ hid_bpf_hw_output_report(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz)  	ret = hid_ops->hid_hw_output_report(hdev,  						dma_data, -						size); +						size, +						(__u64)ctx);  	kfree(dma_data);  	return ret; @@ -429,7 +431,7 @@ hid_bpf_input_report(struct hid_bpf_ctx *ctx, enum hid_report_type type, u8 *buf  	hdev = (struct hid_device *)ctx->hid; /* discard const */ -	return hid_ops->hid_input_report(hdev, type, buf, size, 0); +	return hid_ops->hid_input_report(hdev, type, buf, size, 0, (__u64)ctx);  }  __bpf_kfunc_end_defs(); diff --git a/drivers/hid/bpf/hid_bpf_struct_ops.c b/drivers/hid/bpf/hid_bpf_struct_ops.c index 5f200557ff12..8063db1c8d62 100644 --- a/drivers/hid/bpf/hid_bpf_struct_ops.c +++ b/drivers/hid/bpf/hid_bpf_struct_ops.c @@ -257,7 +257,7 @@ static void hid_bpf_unreg(void *kdata)  	hid_put_device(hdev);  } -static int __hid_bpf_device_event(struct hid_bpf_ctx *ctx, enum hid_report_type type) +static int __hid_bpf_device_event(struct hid_bpf_ctx *ctx, enum hid_report_type type, __u64 source)  {  	return 0;  } | 
