From nobody Sat Sep 26 05:28:42 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C0AE4908D7; Fri, 4 Sep 2026 12:53:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788526395; cv=none; b=j/f+ucV6pSvJ+SHWF4oqIffM/eeolE1cfLRKwxoGMvU5Cmnoep1kkJVMn2/8EdgiPLPmXOdzzlSYlM0rSRvvd3lX0YpydM9nZh6PiARBuR3zPdmYsCijMnwe1hg6YML8lgFzAQ+KfhHoAMWu5SczoCuGEtlB8eQEMvl3CSGwMpU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788526395; c=relaxed/simple; bh=L8KDIiF6iGv9ptfT58v6CZCR07cETsON7FR/0HYuHQA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SzS1JOuHyE/UvzJEO2gPC/lJpmg3xOSbehBeDRMRfR9eU/B4tfpQpKDwtzdV9D9Jw3BW2bwY/yvQPE/VxeL1VJYqJIEo8eA2TrmIj0gbUYNrYtoH1W4sRh9kihy8DmuEv/C6vDpOGZWTRwwV2VI0GNCl5/RTtKBc6Dc/X3Dejw4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TsM8aRyK; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TsM8aRyK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A3F71F00A3E; Fri, 4 Sep 2026 12:53:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788526393; bh=rVMJoTW/YhpeXi6fOD69gnnxshNIuAa7yQ+rp/Ersbc=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=TsM8aRyKsuesQpMQLsE4IzCeio6y2bf239331iqatoUx72IABNUju7mzqe6HMjtrI n+V4QZvxPh4+1WyEZRRPIpJIkxlRcKZlFzHK3Y4BDe9fpTY8m8tLJgKVufRI2X6yY9 vMF3Tt/v+IJG/xhLI0j567+Q/KwGK1NeDfEzJHfNuqDVzCHCYfn+m+raI0VudCFOfr Lef8JcoKQl8kS5Mhu6wWzgngVFlZcMj6c0IVcB8IWM7GTMkvcNXLquyKkQQnQpfJRd IAJyN6yrlSXWp6u3Doo08MKZkiUGsXKDn+G+67xKKQSuY5jjDGEaA4DRiI6NUBj3nk SeULcLr4ciHKA== From: Benjamin Tissoires Date: Fri, 04 Sep 2026 14:52:59 +0200 Subject: [PATCH 1/3] selftests/hid: add define for commonly used buf size Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260904-wip-bpf-check_report-v1-1-efe9a2a1ed28@kernel.org> References: <20260904-wip-bpf-check_report-v1-0-efe9a2a1ed28@kernel.org> In-Reply-To: <20260904-wip-bpf-check_report-v1-0-efe9a2a1ed28@kernel.org> To: Jiri Kosina , Shuah Khan Cc: linux-input@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788526390; l=6156; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=L8KDIiF6iGv9ptfT58v6CZCR07cETsON7FR/0HYuHQA=; b=5vof8CtsjDMaRabUHh/FMGT1jGmaiazR3HbEe2FuIyFIz62bUL/xuL8fUfVlL9paqOelwy+9S lkvYgq9cmDfCeQUVymC1QzNeJ7Z+s3uuUJxTnw0ZZ8w3RxV57tqLGEv X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= If we want to add another report descriptor without report IDs with a report size bigger than 10, we have multiple magic values to replace. Put a #define once and for all, so we don't have dangling ones. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/hid_bpf.c | 38 ++++++++++++++++------------= ---- tools/testing/selftests/hid/hid_common.h | 3 ++- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/hid/hid_bpf.c b/tools/testing/selftest= s/hid/hid_bpf.c index b851339308c2..e865ee55b4f1 100644 --- a/tools/testing/selftests/hid/hid_bpf.c +++ b/tools/testing/selftests/hid/hid_bpf.c @@ -5,7 +5,7 @@ #include =20 struct hid_hw_request_syscall_args { - __u8 data[10]; + __u8 data[MAX_BUF_SIZE]; unsigned int hid; int retval; size_t size; @@ -168,7 +168,7 @@ TEST_F(hid_bpf, raw_event) const struct test_program progs[] =3D { { .name =3D "hid_first_event" }, }; - __u8 buf[10] =3D {0}; + __u8 buf[MAX_BUF_SIZE] =3D {0}; int err; =20 LOAD_PROGRAMS(progs); @@ -219,7 +219,7 @@ TEST_F(hid_bpf, subprog_raw_event) const struct test_program progs[] =3D { { .name =3D "hid_subprog_first_event" }, }; - __u8 buf[10] =3D {0}; + __u8 buf[MAX_BUF_SIZE] =3D {0}; int err; =20 LOAD_PROGRAMS(progs); @@ -277,7 +277,7 @@ TEST_F(hid_bpf, test_attach_detach) { .name =3D "hid_second_event" }, }; struct bpf_link *link; - __u8 buf[10] =3D {0}; + __u8 buf[MAX_BUF_SIZE] =3D {0}; int err, link_fd; =20 LOAD_PROGRAMS(progs); @@ -362,7 +362,7 @@ TEST_F(hid_bpf, test_hid_change_report) const struct test_program progs[] =3D { { .name =3D "hid_change_report_id" }, }; - __u8 buf[10] =3D {0}; + __u8 buf[MAX_BUF_SIZE] =3D {0}; int err; =20 LOAD_PROGRAMS(progs); @@ -389,13 +389,13 @@ TEST_F(hid_bpf, test_hid_user_input_report_call) { struct hid_hw_request_syscall_args args =3D { .retval =3D -1, - .size =3D 10, + .size =3D MAX_BUF_SIZE, }; DECLARE_LIBBPF_OPTS(bpf_test_run_opts, tattrs, .ctx_in =3D &args, .ctx_size_in =3D sizeof(args), ); - __u8 buf[10] =3D {0}; + __u8 buf[MAX_BUF_SIZE] =3D {0}; int err, prog_fd; =20 LOAD_BPF; @@ -435,7 +435,7 @@ TEST_F(hid_bpf, test_hid_user_output_report_call) { struct hid_hw_request_syscall_args args =3D { .retval =3D -1, - .size =3D 10, + .size =3D MAX_BUF_SIZE, }; DECLARE_LIBBPF_OPTS(bpf_test_run_opts, tattrs, .ctx_in =3D &args, @@ -484,7 +484,7 @@ TEST_F(hid_bpf, test_hid_user_raw_request_call) .retval =3D -1, .type =3D HID_FEATURE_REPORT, .request_type =3D HID_REQ_GET_REPORT, - .size =3D 10, + .size =3D MAX_BUF_SIZE, }; DECLARE_LIBBPF_OPTS(bpf_test_run_opts, tattrs, .ctx_in =3D &args, @@ -517,7 +517,7 @@ TEST_F(hid_bpf, test_hid_filter_raw_request_call) const struct test_program progs[] =3D { { .name =3D "hid_test_filter_raw_request" }, }; - __u8 buf[10] =3D {0}; + __u8 buf[MAX_BUF_SIZE] =3D {0}; int err; =20 LOAD_PROGRAMS(progs); @@ -570,7 +570,7 @@ TEST_F(hid_bpf, test_hid_change_raw_request_call) const struct test_program progs[] =3D { { .name =3D "hid_test_hidraw_raw_request" }, }; - __u8 buf[10] =3D {0}; + __u8 buf[MAX_BUF_SIZE] =3D {0}; int err; =20 LOAD_PROGRAMS(progs); @@ -596,7 +596,7 @@ TEST_F(hid_bpf, test_hid_infinite_loop_raw_request_call) const struct test_program progs[] =3D { { .name =3D "hid_test_infinite_loop_raw_request" }, }; - __u8 buf[10] =3D {0}; + __u8 buf[MAX_BUF_SIZE] =3D {0}; int err; =20 LOAD_PROGRAMS(progs); @@ -619,7 +619,7 @@ TEST_F(hid_bpf, test_hid_filter_output_report_call) const struct test_program progs[] =3D { { .name =3D "hid_test_filter_output_report" }, }; - __u8 buf[10] =3D {0}; + __u8 buf[MAX_BUF_SIZE] =3D {0}; int err; =20 LOAD_PROGRAMS(progs); @@ -672,7 +672,7 @@ TEST_F(hid_bpf, test_hid_change_output_report_call) const struct test_program progs[] =3D { { .name =3D "hid_test_hidraw_output_report" }, }; - __u8 buf[10] =3D {0}; + __u8 buf[MAX_BUF_SIZE] =3D {0}; int err; =20 LOAD_PROGRAMS(progs); @@ -696,7 +696,7 @@ TEST_F(hid_bpf, test_hid_infinite_loop_output_report_ca= ll) const struct test_program progs[] =3D { { .name =3D "hid_test_infinite_loop_output_report" }, }; - __u8 buf[10] =3D {0}; + __u8 buf[MAX_BUF_SIZE] =3D {0}; int err; =20 LOAD_PROGRAMS(progs); @@ -722,7 +722,7 @@ TEST_F(hid_bpf, test_multiply_events_wq) const struct test_program progs[] =3D { { .name =3D "hid_test_multiply_events_wq" }, }; - __u8 buf[10] =3D {0}; + __u8 buf[MAX_BUF_SIZE] =3D {0}; int err; =20 LOAD_PROGRAMS(progs); @@ -760,7 +760,7 @@ TEST_F(hid_bpf, test_multiply_events) const struct test_program progs[] =3D { { .name =3D "hid_test_multiply_events" }, }; - __u8 buf[10] =3D {0}; + __u8 buf[MAX_BUF_SIZE] =3D {0}; int err; =20 LOAD_PROGRAMS(progs); @@ -794,7 +794,7 @@ TEST_F(hid_bpf, test_hid_infinite_loop_input_report_cal= l) const struct test_program progs[] =3D { { .name =3D "hid_test_infinite_loop_input_report" }, }; - __u8 buf[10] =3D {0}; + __u8 buf[MAX_BUF_SIZE] =3D {0}; int err; =20 LOAD_PROGRAMS(progs); @@ -848,7 +848,7 @@ TEST_F(hid_bpf, test_hid_attach_flags) .insert_head =3D 0, }, }; - __u8 buf[10] =3D {0}; + __u8 buf[MAX_BUF_SIZE] =3D {0}; int err; =20 LOAD_PROGRAMS(progs); diff --git a/tools/testing/selftests/hid/hid_common.h b/tools/testing/selft= ests/hid/hid_common.h index e3b267446fa0..4567336f131d 100644 --- a/tools/testing/selftests/hid/hid_common.h +++ b/tools/testing/selftests/hid/hid_common.h @@ -13,6 +13,7 @@ #include =20 #define SHOW_UHID_DEBUG 0 +#define MAX_BUF_SIZE 10 =20 #define min(a, b) \ ({ __typeof__(a) _a =3D (a); \ @@ -110,7 +111,7 @@ static pthread_cond_t uhid_started =3D PTHREAD_COND_INI= TIALIZER; =20 static pthread_mutex_t uhid_output_mtx =3D PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t uhid_output_cond =3D PTHREAD_COND_INITIALIZER; -static unsigned char output_report[10]; +static unsigned char output_report[MAX_BUF_SIZE]; =20 /* no need to protect uhid_stopped, only one thread accesses it */ static bool uhid_stopped; --=20 2.55.0 From nobody Sat Sep 26 05:28:42 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8547D3EDACD; Fri, 4 Sep 2026 12:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788526396; cv=none; b=QaMgVLf4yOUKS0LMBjdlEA7C1gEKFFxu2YDvTrRZzzWN1y5qZaZLgS+/TX4iINbBQA0CdNd9tvu3LjircEeatUH5R6dnpxwR6hfaWkkvJTXthS8DndbvyRlroSyBKhL+RSuR6vUgiRMxqQ2aqobSXLoDuET9sahOMYBLSKHbOHI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788526396; c=relaxed/simple; bh=wUwPUKo0jf4PK8RHKD8/IPzBd9Q7ihhOyso3SZvS5qU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SELhvXr423xKBgPCzceqt7fUSuqmn0d7hA0N/5R0FQsZNrC5TUfKhLpbrg7jEqD0vpsreWG3zW0VHT5yJwq7th9jhTrh+XFwLFvy6hga+rNnQ6K1gBZi4kzTwlmgpPbtxNXrimwoONEEATPbdqyLB1YJRnk39FB8ObZiTSFF+B4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Uwg36NlG; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Uwg36NlG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22E2D1F00A3D; Fri, 4 Sep 2026 12:53:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788526395; bh=HuyUkb9QsgfNFHqyR5g942koc/YUlOHj8jX0auIKN/w=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Uwg36NlG7O/JKqjKd1HAXPiJpW7Kf7t8qJtkY8cNBRrHIv5lNy6R1L3uurIDuVuTS kkRbDn0kYUr4OAgDlVpu7jw9ZM/ItIVlQPat9ahtVyGEbXblSjKRqtmV1spUMLEOfI SNt9/N8rRJz8Ftgbm8A/7MTzQEdmzAqCJebZ+G+cURubeqt8uFDeklmRau6OmV/zJK MA0O4DsuNMUqPjx/ZQAp0yLTk2YromIgdX7diFujUGmEKpJmfVXOYlR2tOO737ZttY a1vCxQNbOdYCRIvpv6H7aW5ayg9b2EiFkcSmhaLTMMfjTtnZenQm7JzzUDJB79fYCe 5OOYCqpDkrslA== From: Benjamin Tissoires Date: Fri, 04 Sep 2026 14:53:00 +0200 Subject: [PATCH 2/3] HID: bpf: fix __hid_bpf_hw_check_params report length Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260904-wip-bpf-check_report-v1-2-efe9a2a1ed28@kernel.org> References: <20260904-wip-bpf-check_report-v1-0-efe9a2a1ed28@kernel.org> In-Reply-To: <20260904-wip-bpf-check_report-v1-0-efe9a2a1ed28@kernel.org> To: Jiri Kosina , Shuah Khan Cc: linux-input@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788526390; l=2503; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=wUwPUKo0jf4PK8RHKD8/IPzBd9Q7ihhOyso3SZvS5qU=; b=k/WKkJAdMWqjWJUD84OovAXPDp+7ZSra2FteNQmA+Fro5PKJPnC4lcbVBmBGbPbd11uoQetIR 5wOeVy4iETGDfxRJxkiWyQZ0mxR9JLlVkULilEU6m7sofB7pf9h6ocE X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= Turns out that USB, I2C and other transport drivers (except uhid which just passes the data) still need to have the report ID in the first byte. Because they expect the first byte to be the report ID or 0, when the report ID is 0, they strip that first byte before forwarding to the device. This means that the transport layer forwards a buffer of size N-1 to the device, which gets rejected. Fixes: 5599f8019661 ("HID: bpf: export hid_hw_output_report as a BPF kfunc") Signed-off-by: Benjamin Tissoires --- drivers/hid/bpf/hid_bpf_dispatch.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf_d= ispatch.c index 536f6d01fd14..b1de1dd0f21d 100644 --- a/drivers/hid/bpf/hid_bpf_dispatch.c +++ b/drivers/hid/bpf/hid_bpf_dispatch.c @@ -359,7 +359,7 @@ hid_bpf_release_context(struct hid_bpf_ctx *ctx) =20 static int __hid_bpf_hw_check_params(struct hid_bpf_ctx *ctx, __u8 *buf, size_t *buf_= _sz, - enum hid_report_type rtype) + enum hid_report_type rtype, bool hw_request) { struct hid_report_enum *report_enum; struct hid_report *report; @@ -388,6 +388,10 @@ __hid_bpf_hw_check_params(struct hid_bpf_ctx *ctx, __u= 8 *buf, size_t *buf__sz, =20 report_len =3D hid_report_len(report); =20 + /* unnumbered reports need to have a report ID reserved in the first byte= */ + if (hw_request && report_enum->numbered =3D=3D 0) + report_len +=3D 1; + if (*buf__sz > report_len) *buf__sz =3D report_len; =20 @@ -420,7 +424,7 @@ hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, = size_t buf__sz, return -EDEADLOCK; =20 /* check arguments */ - ret =3D __hid_bpf_hw_check_params(ctx, buf, &size, rtype); + ret =3D __hid_bpf_hw_check_params(ctx, buf, &size, rtype, true); if (ret) return ret; =20 @@ -480,7 +484,7 @@ hid_bpf_hw_output_report(struct hid_bpf_ctx *ctx, __u8 = *buf, size_t buf__sz) return -EDEADLOCK; =20 /* check arguments */ - ret =3D __hid_bpf_hw_check_params(ctx, buf, &size, HID_OUTPUT_REPORT); + ret =3D __hid_bpf_hw_check_params(ctx, buf, &size, HID_OUTPUT_REPORT, tru= e); if (ret) return ret; =20 @@ -506,7 +510,7 @@ __hid_bpf_input_report(struct hid_bpf_ctx *ctx, enum hi= d_report_type type, u8 *b return -EDEADLOCK; =20 /* check arguments */ - ret =3D __hid_bpf_hw_check_params(ctx, buf, &size, type); + ret =3D __hid_bpf_hw_check_params(ctx, buf, &size, type, false); if (ret) return ret; =20 --=20 2.55.0 From nobody Sat Sep 26 05:28:42 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F29149365E; Fri, 4 Sep 2026 12:53:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788526399; cv=none; b=NVm7F5S/kCQ5ado6tWV+gFbYskkYnSeo0EcrC0Zk4ffOeR/sZpm0YCiLxryp5N1Za971Grb/YTyDj+099O7f7w4JEaWvFdIfNjTPhOkxbWKedUTJzgwoaL4gOJojdm8CulcnQBLrfvuJlb6gxRfAtBN/1+/g0spRhb7iPDfAL4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788526399; c=relaxed/simple; bh=i3zdWQXao6mJbUcYA6Qbebb0X6DWZLTCMR0y7Fo/qVI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XYzK4V2XvG/+ca26qq/5sHOYgbz/EwZ0DbB3g7KLab63eU6mE+qMJkBtey4PlzfrbdXntxAD3aD+TiD2I2SxPQtx4LcufIwlQIol2GdvxYPVVfQ8xWTbJcAkiGY8NE7/4/Hh9tpuIjAT5fAAlTaTqzA4mLTYxxOTt4kBaMXQ5DU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Zart/WXB; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Zart/WXB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF5DC1F00A3E; Fri, 4 Sep 2026 12:53:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788526397; bh=/QBo+IywvBFKQ91oQJ//NJtvKzWxxCKh0qWpivsM9x8=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Zart/WXBoei/laHnQMhcj9seusOMKLAghP5oFUAjdZGV0PDw2R+ee1SxwvYf2nNZv cMaYkmKh4sKtdmahiT+G/+46g1kBxqN+/P7T0zrS+JF8QopO+rwdd9VnK5IJdXLpSe pFZod1vufrJo/pY2gp1wNytWdMRDu0G0VabtScQYNxIKoMMSNULC0I5ycIPu5T/QjR /lsZjfrGMeHs8lWhevchQVm/a9cReEkh3L1Mt1XxJf5E3x5bGZ2RtQFZYI+u8LHKdn 09PREaIR8HLpuubr7hPB+TxzeRP2VEI9RE/01Hr3m5dU2wKSXnyNZbyYt3kBH0uq9b NuENC68HXD9Wg== From: Benjamin Tissoires Date: Fri, 04 Sep 2026 14:53:01 +0200 Subject: [PATCH 3/3] selftests/hid: add unnumbered variant to the hid_bpf tests Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260904-wip-bpf-check_report-v1-3-efe9a2a1ed28@kernel.org> References: <20260904-wip-bpf-check_report-v1-0-efe9a2a1ed28@kernel.org> In-Reply-To: <20260904-wip-bpf-check_report-v1-0-efe9a2a1ed28@kernel.org> To: Jiri Kosina , Shuah Khan Cc: linux-input@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788526390; l=5643; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=i3zdWQXao6mJbUcYA6Qbebb0X6DWZLTCMR0y7Fo/qVI=; b=pTgH0QSp3BWXY34Z9KGAlvWrxmJJ8dlUinSv1fMpggkVG9eCxnd8LMi/iUxi4fj3DwImDNPyd 53NRVVMykxoCuiuqNcz9BXTSQD6IS6DsTXP9sfZwsfIonhrMMsRshvw X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= A bug appeared in hid_bpf_dispatch.c where it wasn't properly handling unnumbered reports. Add a device variant without report IDs so we can also test them. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/hid_bpf.c | 53 ++++++++++++++++++++++++++--= ---- tools/testing/selftests/hid/hid_common.h | 24 ++++++++++++++- tools/testing/selftests/hid/progs/hid.c | 2 +- 3 files changed, 68 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/hid/hid_bpf.c b/tools/testing/selftest= s/hid/hid_bpf.c index e865ee55b4f1..d1bd07caf991 100644 --- a/tools/testing/selftests/hid/hid_bpf.c +++ b/tools/testing/selftests/hid/hid_bpf.c @@ -54,11 +54,27 @@ FIXTURE_TEARDOWN(hid_bpf) { hid_bpf_teardown(_metadata, self, variant); \ } while (0) =20 +FIXTURE_VARIANT(hid_bpf) { + __u8 *rdesc; + size_t rdesc_size; +}; + +FIXTURE_VARIANT_ADD(hid_bpf, numbered) { + .rdesc =3D rdesc, + .rdesc_size =3D sizeof(rdesc), +}; + +FIXTURE_VARIANT_ADD(hid_bpf, unnumbered) { + .rdesc =3D fido2_rdesc, + .rdesc_size =3D sizeof(fido2_rdesc), +}; + FIXTURE_SETUP(hid_bpf) { int err; =20 - err =3D setup_uhid(_metadata, &self->hid, BUS_USB, 0x0001, 0x0a36, rdesc,= sizeof(rdesc)); + err =3D setup_uhid(_metadata, &self->hid, BUS_USB, 0x0001, 0x0a36, + variant->rdesc, variant->rdesc_size); ASSERT_OK(err); } =20 @@ -402,8 +418,11 @@ TEST_F(hid_bpf, test_hid_user_input_report_call) =20 args.hid =3D self->hid.hid_id; args.data[0] =3D 1; /* report ID */ - args.data[1] =3D 2; /* report ID */ - args.data[2] =3D 42; /* report ID */ + args.data[1] =3D 2; + args.data[2] =3D 42; + + if (variant->rdesc =3D=3D fido2_rdesc) + args.data[0] =3D 0; =20 prog_fd =3D bpf_program__fd(self->skel->progs.hid_user_input_report); =20 @@ -421,8 +440,13 @@ TEST_F(hid_bpf, test_hid_user_input_report_call) /* read the data from hidraw */ memset(buf, 0, sizeof(buf)); err =3D read(self->hidraw_fd, buf, sizeof(buf)); - ASSERT_EQ(err, 6) TH_LOG("read_hidraw"); - ASSERT_EQ(buf[0], 1); + if (variant->rdesc =3D=3D rdesc) { + ASSERT_EQ(err, 6) TH_LOG("read_hidraw"); + } else { + ASSERT_EQ(err, 64) + TH_LOG("read_hidraw"); + } + ASSERT_EQ(buf[0], args.data[0]); ASSERT_EQ(buf[1], 2); ASSERT_EQ(buf[2], 42); } @@ -448,8 +472,11 @@ TEST_F(hid_bpf, test_hid_user_output_report_call) =20 args.hid =3D self->hid.hid_id; args.data[0] =3D 1; /* report ID */ - args.data[1] =3D 2; /* report ID */ - args.data[2] =3D 42; /* report ID */ + args.data[1] =3D 2; + args.data[2] =3D 42; + + if (variant->rdesc =3D=3D fido2_rdesc) + args.data[0] =3D 0; =20 prog_fd =3D bpf_program__fd(self->skel->progs.hid_user_output_report); =20 @@ -465,9 +492,14 @@ TEST_F(hid_bpf, test_hid_user_output_report_call) ASSERT_OK(err) TH_LOG("error while calling bpf_prog_test_run_opts"); ASSERT_OK(cond_err) TH_LOG("error while calling waiting for the condition= "); =20 - ASSERT_EQ(args.retval, 3); + if (variant->rdesc =3D=3D rdesc) { + ASSERT_EQ(args.retval, 3); + } else if (variant->rdesc =3D=3D fido2_rdesc) { + ASSERT_EQ(args.retval, 65) + TH_LOG("report size error, should have 64 + 1 extra byte for the report = ID 0"); + } =20 - ASSERT_EQ(output_report[0], 1); + ASSERT_EQ(output_report[0], args.data[0]); ASSERT_EQ(output_report[1], 2); ASSERT_EQ(output_report[2], 42); =20 @@ -879,6 +911,9 @@ TEST_F(hid_bpf, test_rdesc_fixup) }; int err, desc_size; =20 + if (variant->rdesc !=3D rdesc) + SKIP(return, "not compatible report descriptor"); + LOAD_PROGRAMS(progs); =20 /* check that hid_rdesc_fixup() was executed */ diff --git a/tools/testing/selftests/hid/hid_common.h b/tools/testing/selft= ests/hid/hid_common.h index 4567336f131d..b7890ba2878f 100644 --- a/tools/testing/selftests/hid/hid_common.h +++ b/tools/testing/selftests/hid/hid_common.h @@ -13,7 +13,7 @@ #include =20 #define SHOW_UHID_DEBUG 0 -#define MAX_BUF_SIZE 10 +#define MAX_BUF_SIZE 128 =20 #define min(a, b) \ ({ __typeof__(a) _a =3D (a); \ @@ -98,6 +98,28 @@ static unsigned char rdesc[] =3D { =20 static __u8 feature_data[] =3D { 1, 2 }; =20 +static __maybe_unused unsigned char fido2_rdesc[] =3D { + 0x06, 0xd0, 0xf1, /* Usage Page (FIDO Alliance) */ + 0x09, 0x01, /* Usage (U2F Authenticator Device) */ + 0xa1, 0x01, /* Collection (Application) */ + 0x09, 0x20, /* Usage (Input Report Data) */ + 0x15, 0x00, /* Logical Minimum (0) */ + 0x26, 0xff, 0x00, /* Logical Maximum (255) */ + 0x75, 0x08, /* Report Size (8) */ + 0x95, 0x40, /* Report Count (64) */ + 0x81, 0x02, /* Input (Data,Var,Abs) */ + 0x09, 0x21, /* Usage (Output Report Data) */ + 0x15, 0x00, /* Logical Minimum (0) */ + 0x26, 0xff, 0x00, /* Logical Maximum (255) */ + 0x75, 0x08, /* Report Size (8) */ + 0x95, 0x40, /* Report Count (64) */ + 0x91, 0x02, /* Output (Data,Var,Abs) */ + 0x06, 0x00, 0xff, /* Usage Page (Vendor Defined Page 1) */ + 0x09, 0x22, /* Usage (Vendor Usage 0x22) */ + 0xb1, 0x02, /* Feature (Data,Var,Abs) */ + 0xc0, /* End Collection */ +}; + #define ASSERT_OK(data) ASSERT_FALSE(data) #define ASSERT_OK_PTR(ptr) ASSERT_NE(NULL, ptr) =20 diff --git a/tools/testing/selftests/hid/progs/hid.c b/tools/testing/selfte= sts/hid/progs/hid.c index b21fbb13c926..605d8a5f9cb2 100644 --- a/tools/testing/selftests/hid/progs/hid.c +++ b/tools/testing/selftests/hid/progs/hid.c @@ -98,7 +98,7 @@ struct hid_bpf_ops change_report_id =3D { =20 struct hid_hw_request_syscall_args { /* data needs to come at offset 0 so we can use it in calls */ - __u8 data[10]; + __u8 data[128]; unsigned int hid; int retval; size_t size; --=20 2.55.0