From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796247641; b=Jytk6/cXaSOGVyAByeUGM3bGT1e8WAgxHnqwX+82NYY+LrMUwBuWaT9SDSHgGo726IbW 84DmVL1N7UxOxDIky9mVb9yAd1uChzSaSPcqTD342n2bLaL2Js4qm4/qrfrFfyJyh1u8X dL96wod8In+Hz0Tt1MgWIMcBnjGK4hOloblHYFaO4Zkxbq0kntd2PVLRpXkaHRhJPXtyh I6zneTdE3Xv8XoUEeYhq6TcfYeQZWNPl0D+I/U5Y5XNVT6sLS902RjU5kr4YvFzVCz7sW 4UL9KpRRyGWDCiM7afC4R4BihcUBKMQpxnKlmhC3pChLjxbR5mzN0WchB+4iy+XBU6A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796247641; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=iXgc8BlNuXobPJ/D7bL1dYEfQpHxA+Egmyb4qQsIsm4=; b=H3CWKBuMyg3IfBtoYipe/12XGxmBrguAJfg3cBklWs0S3+FZbGbs1czdE3Jqb/nIZkeA JXQkLQ4tDwSFntNJyP3TskQAeUUq+PEKN4PfvsgXsHtVMUpI3EoByBvsuWqF8WzOKV5Br nX1lu69ddwbjS1RclXbTMnk/ZtjXy9d4hGPnrDonqxJKEbWXNXLpxjVuOI61SRJbdhJLK aiqCcdsqWE1Jad6I1RGF7ncJG1xZ8PfmBNZI/Vf+Cuj5a1ponvoYDN8668YJfL7TYC0vX shXpRdfSLfzNtTRr+DkWo6PyScmlY16iI/cWcDAnKcKuJudMlTgTYLPFWTVJ++KM3Kg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Fz9uQD+j; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDB94606A322; Wed, 2 Dec 2026 21:40:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Fz9uQD+j Received: by smtp.kernel.org (Postfix) with ESMTPSA id 697341F00893; Wed, 2 Dec 2026 21:40:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796247641; bh=iXgc8BlNuXobPJ/D7bL1dYEfQpHxA+Egmyb4qQsIsm4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Fz9uQD+jbSB6tX6NG48mwUTX7Gi5Ch78qK5RgkhNRKC1GyorxZqXv1aV/Dfc9R+OU hF+YITGkvONfSSw0+sMwoRYZ95CQ0kIswjNiiydR2OIA8/PNklRmMBsw7x5f2uDGw8 fkbG0cL/mULBtnGhVpr9Z6+4Qf2go1zemX/F/UT6S6Ew2ncGiigD2dwVe4fGVBv86t 3XSLfpiOSHqPJH3BrQdzA+U7DaatIibjfK1NfaitPKBEpo6P8Q/Digmdu8GXnx6pvh XORs4U+ZPfJJ7dN9m+ebTrq9Z29OuAgE8hmvY0DdWarevY7DJmTp1lkyf16OPGeu9D o0isN8NttHRng== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 3/4] HID: bpf: don't copy a report longer than the device event buffer Reply-To: sashiko-reviews@lists.linux.dev To: "Yassine Ouamer" Cc: linux-input@vger.kernel.org, bpf@vger.kernel.org, dmitry.torokhov@gmail.com In-Reply-To: <20261202-hid-bpf-event-buffer-v1-3-53e3b6ce8336@proton.me> References: <20261202-hid-bpf-event-buffer-v1-0-53e3b6ce8336@proton.me> <20261202-hid-bpf-event-buffer-v1-3-53e3b6ce8336@proton.me> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 21:40:41 +0000 X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] HID: bpf: unclamped *size in dispatch_hid_bpf_device_event() when size is 0 -- commit 427f1ddc5c111a0ad5c8eadb8072a9ea963b193e Author: Yassine Ouamer HID: bpf: don't copy a report longer than the device event buffer This commit clamps the input report size copied into the HID-BPF device event buffer to hdev->bpf.allocated_data to prevent an out-of-bounds write when a device sends a report larger than declared in its descriptor. > diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf= _dispatch.c > index 714014560fb8d..df4c30dd6c05d 100644 > --- a/drivers/hid/bpf/hid_bpf_dispatch.c > +++ b/drivers/hid/bpf/hid_bpf_dispatch.c > @@ -50,8 +50,15 @@ dispatch_hid_bpf_device_event(struct hid_device *hdev,= enum hid_report_type type > if (!hdev->bpf.device_data) > return data; > =20 > + /* > + * A device may send a report longer than its report descriptor > + * declares, and so longer than the buffer: the programs get what > + * fits, which holds the longest report the descriptor declares. > + */ > + ctx_kern.ctx.size =3D min(*size, hdev->bpf.allocated_data); > + > memset(ctx_kern.data, 0, hdev->bpf.allocated_data); > - memcpy(ctx_kern.data, data, *size); > + memcpy(ctx_kern.data, data, ctx_kern.ctx.size); > =20 > rcu_read_lock(); > list_for_each_entry_rcu(e, &hdev->bpf.prog_list, list) { [Severity: Medium] Can *size remain larger than hdev->bpf.allocated_data on return if a BPF program sets ctx->size (or ctx->retval) to 0 and returns 0? hid_bpf_ops_btf_struct_access() allows hid_device_event programs to write to ctx->retval / ctx->size, and the exit path only writes ctx_kern.ctx.size back to *size when it is non-zero: drivers/hid/bpf/hid_bpf_dispatch.c:dispatch_hid_bpf_device_event() { ... ret =3D ctx_kern.ctx.size; if (ret) { if (ret > ctx_kern.ctx.allocated_size) return ERR_PTR(-EINVAL); *size =3D ret; } *buf_size =3D ctx_kern.ctx.allocated_size; return ctx_kern.data; } When ctx_kern.ctx.size is 0, dispatch_hid_bpf_device_event() returns hdev->bpf.device_data while leaving *size at the original oversized report length, so __hid_input_report() can read past the end of hdev->bpf.device_data in hid_dump_report() and hdrv->raw_event(). Clamping *size directly before initializing ctx_kern.ctx.size would avoid this. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202-hid-bpf-ev= ent-buffer-v1-0-53e3b6ce8336@proton.me?part=3D3