From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2479C42A8C; Wed, 23 Jul 2025 04:40:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753245656; cv=none; b=glPM3Nc2XxHeKDHft2zO64jN/39CWbVHyMDM8oD3jkMe24SMI/Iisapjhccm/WiHcvrjcpf5mlFEz18ON4Q0PArgb8BtYYvvOaHqS363/W4EfaE023B5VVQAY+imEf3dprfq1SKpsUIc23R9VNGN1Cr58vZTDuQz+LAJC08SGhI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753245656; c=relaxed/simple; bh=bEV3xQsbqa9RtUVmL1vuV+XnEDHTVKPCd1/rOUW8jBI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=nnd5w+MbXllSyMQ54GwW6LGjLjCoa3WpTzQ4fVQNYV9JijEWzMU/SPwe2LOJFyhjIkxzAr1U/TYdTTL0yBKoFpa7xYVwDlhXbKokE8YTd/Bm9nDWNuuNd6wrxiy0zKuqJjBc4Ird1gHFc/iBHJ+wERR0LDlrSjxk3445pkP15pE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pr+RUXbZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pr+RUXbZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32797C4CEE7; Wed, 23 Jul 2025 04:40:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753245655; bh=bEV3xQsbqa9RtUVmL1vuV+XnEDHTVKPCd1/rOUW8jBI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=pr+RUXbZEPa9Cgha8L4zNJ6qHrrogoJGcqB79vL9oNlQ+FsxfYuz/4HgpiI64dshF wxsT62nmifJh2D9Sg1SW6aiK1UQB05zvf56I86JzhvV4MeQ5lai9S/1Cwiny74I2S0 OABtWaE3nalnk6VeV1BznejNWdS/AeSLMWfTss10E1lhBw04tqJeqmQxvE7FLZG4bk DmwdxUz2BhdywGB7E6zayOkwMD/VErYpV6wEgBB5fM6RP07Lz097zQ9Hi6BEOMLgs6 BJVaQQZn7qyZbGgEF8zMoBzm+645/g8q835EHXHpC/q3pgpwCXfc1wcQrEB8xafDpE AxxRZ0UOGB4gQ== Message-ID: <1a2d0220-5862-4cba-8d0f-2eb7556c9620@kernel.org> Date: Wed, 23 Jul 2025 06:40:52 +0200 Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RESEND] HID: multitouch: fix slab out-of-bounds access in mt_report_fixup() To: Qasim Ijaz Cc: jikos@kernel.org, bentiss@kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Dmitry Savin References: <20250722080003.3605-1-qasdev00@gmail.com> Content-Language: en-US From: Jiri Slaby Autocrypt: addr=jirislaby@kernel.org; keydata= xsFNBE6S54YBEACzzjLwDUbU5elY4GTg/NdotjA0jyyJtYI86wdKraekbNE0bC4zV+ryvH4j rrcDwGs6tFVrAHvdHeIdI07s1iIx5R/ndcHwt4fvI8CL5PzPmn5J+h0WERR5rFprRh6axhOk rSD5CwQl19fm4AJCS6A9GJtOoiLpWn2/IbogPc71jQVrupZYYx51rAaHZ0D2KYK/uhfc6neJ i0WqPlbtIlIrpvWxckucN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06Y/+Kzdr 90eUVneqM2TUQQbK+Kh7JwmGVrRGNqQrDk+gRNvKnGwFNeTkTKtJ0P8jYd7P1gZb9Fwj9YLx jhn/sVIhNmEBLBoI7PL+9fbILqJPHgAwW35rpnq4f/EYTykbk1sa13Tav6btJ+4QOgbcezWI wZ5w/JVfEJW9JXp3BFAVzRQ5nVrrLDAJZ8Y5ioWcm99JtSIIxXxt9FJaGc1Bgsi5K/+dyTKL wLMJgiBzbVx8G+fCJJ9YtlNOPWhbKPlrQ8+AY52Aagi9WNhe6XfJdh5g6ptiOILm330mkR4g W6nEgZVyIyTq3ekOuruftWL99qpP5zi+eNrMmLRQx9iecDNgFr342R9bTDlb1TLuRb+/tJ98 f/bIWIr0cqQmqQ33FgRhrG1+Xml6UXyJ2jExmlO8JljuOGeXYh6ZkIEyzqzffzBLXZCujlYQ DFXpyMNVJ2ZwPmX2mWEoYuaBU0JN7wM+/zWgOf2zRwhEuD3A2cO2PxoiIfyUEfB9SSmffaK/ S4xXoB6wvGENZ85Hg37C7WDNdaAt6Xh2uQIly5grkgvWppkNy4ZHxE+jeNsU7tg= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 22. 07. 25, 13:19, Qasim Ijaz wrote: > On Tue, Jul 22, 2025 at 11:16:15AM +0200, Jiri Slaby wrote: >> On 22. 07. 25, 10:00, Qasim Ijaz wrote: >>> A malicious HID device can trigger a slab out-of-bounds during >>> mt_report_fixup() by passing in report descriptor smaller than >>> 607 bytes. mt_report_fixup() attempts to patch byte offset 607 >>> of the descriptor with 0x25 by first checking if byte offset >>> 607 is 0x15 however it lacks bounds checks to verify if the >>> descriptor is big enough before conducting this check. Fix >>> this vulnerability by ensuring the descriptor size is >>> greater than or equal to 608 before accessing it. >>> >>> Below is the KASAN splat after the out of bounds access happens: >>> >>> [ 13.671954] ================================================================== >>> [ 13.672667] BUG: KASAN: slab-out-of-bounds in mt_report_fixup+0x103/0x110 >>> [ 13.673297] Read of size 1 at addr ffff888103df39df by task kworker/0:1/10 >>> [ 13.673297] >>> [ 13.673297] CPU: 0 UID: 0 PID: 10 Comm: kworker/0:1 Not tainted 6.15.0-00005-gec5d573d83f4-dirty #3 >>> [ 13.673297] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-debian-1.16.2-1 04/04 >>> [ 13.673297] Call Trace: >>> [ 13.673297] >>> [ 13.673297] dump_stack_lvl+0x5f/0x80 >>> [ 13.673297] print_report+0xd1/0x660 >>> [ 13.673297] kasan_report+0xe5/0x120 >>> [ 13.673297] __asan_report_load1_noabort+0x18/0x20 >>> [ 13.673297] mt_report_fixup+0x103/0x110 >>> [ 13.673297] hid_open_report+0x1ef/0x810 >>> [ 13.673297] mt_probe+0x422/0x960 >>> [ 13.673297] hid_device_probe+0x2e2/0x6f0 >>> [ 13.673297] really_probe+0x1c6/0x6b0 >>> [ 13.673297] __driver_probe_device+0x24f/0x310 >>> [ 13.673297] driver_probe_device+0x4e/0x220 >>> [ 13.673297] __device_attach_driver+0x169/0x320 >>> [ 13.673297] bus_for_each_drv+0x11d/0x1b0 >>> [ 13.673297] __device_attach+0x1b8/0x3e0 >>> [ 13.673297] device_initial_probe+0x12/0x20 >>> [ 13.673297] bus_probe_device+0x13d/0x180 >>> [ 13.673297] device_add+0xe3a/0x1670 >>> [ 13.673297] hid_add_device+0x31d/0xa40 >>> [...] >>> >>> Fixes: c8000deb6836 ("HID: multitouch: Add support for GT7868Q") >>> Cc: stable@vger.kernel.org >>> Signed-off-by: Qasim Ijaz >>> Reviewed-by: Dmitry Savin >>> --- >>> drivers/hid/hid-multitouch.c | 25 ++++++++++++++++--------- >>> 1 file changed, 16 insertions(+), 9 deletions(-) >>> >>> diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c >>> index 7ac8e16e6158..af4abe3ba410 100644 >>> --- a/drivers/hid/hid-multitouch.c >>> +++ b/drivers/hid/hid-multitouch.c >>> @@ -1461,18 +1461,25 @@ static const __u8 *mt_report_fixup(struct hid_device *hdev, __u8 *rdesc, >>> if (hdev->vendor == I2C_VENDOR_ID_GOODIX && >>> (hdev->product == I2C_DEVICE_ID_GOODIX_01E8 || >>> hdev->product == I2C_DEVICE_ID_GOODIX_01E9)) { >>> - if (rdesc[607] == 0x15) { >>> - rdesc[607] = 0x25; >>> - dev_info( >>> - &hdev->dev, >>> - "GT7868Q report descriptor fixup is applied.\n"); >>> + if (*size >= 608) { >>> + if (rdesc[607] == 0x15) { >>> + rdesc[607] = 0x25; >>> + dev_info( >>> + &hdev->dev, >>> + "GT7868Q report descriptor fixup is applied.\n"); >>> + } else { >>> + dev_info( >>> + &hdev->dev, >>> + "The byte is not expected for fixing the report descriptor. \ >>> + It's possible that the touchpad firmware is not suitable for applying the fix. \ >>> + got: %x\n", >> >> This is wrong. You have all the spaces/tabs in the string now. Drop all the >> backslashes, and open and close the string on every line. >> >>> + rdesc[607]); >>> + } >> >> As this is superlong and superindented, perhaps introduce a new function for >> these devices? >> >>> } else { >>> dev_info( >>> &hdev->dev, >>> - "The byte is not expected for fixing the report descriptor. \ >>> -It's possible that the touchpad firmware is not suitable for applying the fix. \ >>> -got: %x\n", >> >> This was horrid too, yeah. >> >>> - rdesc[607]); >>> + "GT7868Q fixup: report descriptor only %u bytes, skipping\n", >> >> A predicate missing. Eg. "has only", or "is only". >> > > Thanks for the feedback Jiri, I took the advice on board, is something > like this better? Definitely. > static const __u8 *mt_report_fixup(struct hid_device *hdev, __u8 *rdesc, > unsigned int *size) > { > if (hdev->vendor == I2C_VENDOR_ID_GOODIX && > (hdev->product == I2C_DEVICE_ID_GOODIX_01E8 || > hdev->product == I2C_DEVICE_ID_GOODIX_01E9)) { > if (*size < 608) { > dev_info( > &hdev->dev, > "GT7868Q fixup: report descriptor is only %u bytes, skipping\n", > *size); > return rdesc; > } > > if (rdesc[607] == 0x15) { > rdesc[607] = 0x25; > dev_info( > &hdev->dev, > "GT7868Q fixup: report descriptor fixup is applied.\n"); > } else { > dev_info(&hdev->dev, > "GT7868Q fixup: offset 607 is %x (expected 0x15), " > "descriptor may be malformed, skipping\n", > rdesc[607]); > } > } > > return rdesc; > } > > the key changes I made are: > > - Move size check to the top, this way the indentation level is decent > - get rid of message backslashes > - shorten the fixup failure message when rdesc[607] is not 0x15 and make > it a bit clearer since this message was the longest - just a minor > cleanup > - added "is only %u bytes" as you suggested > > if this is all good I can send v2. I would invert the conditions. So the code would look like: static bool goodix_needs_fixup(hdev) { if (hdev->vendor != I2C_VENDOR_ID_GOODIX) return false; return hdev->product == I2C_DEVICE_ID_GOODIX_01E8 || hdev->product == I2C_DEVICE_ID_GOODIX_01E9; } static const __u8 *mt_report_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *size) { if (!goodix_needs_fixup(hdev)) return rdesc; if (*size < 608) { dev_info(&hdev->dev, "GT7868Q fixup: report descriptor is only %u bytes, skipping\n", *size); return rdesc; } if (rdesc[607] != 0x15) { dev_info(&hdev->dev, "GT7868Q fixup: offset 607 is %x (expected 0x15), descriptor may be malformed, skipping\n", rdesc[607]); return rdesc; } rdesc[607] = 0x25; dev_info(&hdev->dev, "GT7868Q fixup: report descriptor fixup is applied.\n"); return rdesc; } thanks, -- js suse labs