Skip to content

Commit 2bad24c

Browse files
gnoackBenjamin Tissoires
authored andcommitted
HID: asus: avoid memory leak in asus_report_fixup()
The asus_report_fixup() function was returning a newly allocated kmemdup()-allocated buffer, but never freeing it. Switch to devm_kzalloc() to ensure the memory is managed and freed automatically when the device is removed. The caller of report_fixup() does not take ownership of the returned pointer, but it is permitted to return a pointer whose lifetime is at least that of the input buffer. Also fix a harmless out-of-bounds read by copying only the original descriptor size. Assisted-by: Gemini-CLI:Google Gemini 3 Signed-off-by: Günther Noack <gnoack@google.com> Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
1 parent 91e8c6e commit 2bad24c

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

drivers/hid/hid-asus.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,14 +1399,21 @@ static const __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc,
13991399
*/
14001400
if (*rsize == rsize_orig &&
14011401
rdesc[offs] == 0x09 && rdesc[offs + 1] == 0x76) {
1402-
*rsize = rsize_orig + 1;
1403-
rdesc = kmemdup(rdesc, *rsize, GFP_KERNEL);
1404-
if (!rdesc)
1405-
return NULL;
1402+
__u8 *new_rdesc;
1403+
1404+
new_rdesc = devm_kzalloc(&hdev->dev, rsize_orig + 1,
1405+
GFP_KERNEL);
1406+
if (!new_rdesc)
1407+
return rdesc;
14061408

14071409
hid_info(hdev, "Fixing up %s keyb report descriptor\n",
14081410
drvdata->quirks & QUIRK_T100CHI ?
14091411
"T100CHI" : "T90CHI");
1412+
1413+
memcpy(new_rdesc, rdesc, rsize_orig);
1414+
*rsize = rsize_orig + 1;
1415+
rdesc = new_rdesc;
1416+
14101417
memmove(rdesc + offs + 4, rdesc + offs + 2, 12);
14111418
rdesc[offs] = 0x19;
14121419
rdesc[offs + 1] = 0x00;

0 commit comments

Comments
 (0)