Skip to contentSkip to conversation

HID: wacom: fix memory leak on size mismatch in wacom_wac_queue_flush()

PATCH RESEND Applied Qasim Ijaz 3 participants 3 messages Apr 14, 2025 – Apr 24, 2025

Subsystems (2)
lore
Share & tools
lore

Qasim Ijaz

author
#0 lore raw

PATCH RESEND 1/1 HID: wacom: fix memory leak on size mismatch in wacom_wac_queue_flush()

In wacom_wac_queue_flush() the code allocates zero initialised buffer which it uses as a storage buffer for copying data from a fifo via kfifo_out(). The kfifo_out() function returns the number of elements it has copied. The code checks if the number of copied elements does not equal the size of the fifo record, if it does not it simply skips the entry and continues to the next iteration. However it does not release the storage buffer leading to a memory leak.

Fix the memory leak by freeing the buffer on size mismatch.

Fixes 5e013ad20689 ("HID: wacom: Remove static WACOM_PKGLEN_MAX limit")
---
 drivers/hid/wacom_sys.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hid/wacom_sys.c +1 -0
index 666b7eb0fdfe..3e4f823f8ee8 100644
@@ -87,6 +87,7 @@ static void wacom_wac_queue_flush(struct hid_device *hdev,
 			// to flush seems reasonable enough, however.
 			hid_warn(hdev, "%s: removed fifo entry with unexpected size\n",
 				 __func__);
+			kfree(buf);
 			continue;
 		}
 		err = hid_report_raw_event(hdev, HID_INPUT_REPORT, buf, size, false);
Signature · 1 line
2.39.5
#1 lore raw

…

Quoted 2 lines

number of elements it has copied. The code checks if the number of copied elements does not equal the size of the fifo record,

…

                     is?

Under which circumstances would you dare to use text lines which would be longer than 63 characters?

Can a patch series be more appropriate for the affected software module?

Regards,
Markus

maintainer Applied
#2 lore raw
In reply to Qasim Ijaz
Quoted 23 lines · Qasim Ijaz

In wacom_wac_queue_flush() the code allocates zero initialised buffer which it uses as a storage buffer for copying data from a fifo via kfifo_out(). The kfifo_out() function returns the number of elements it has copied. The code checks if the number of copied elements does not equal the size of the fifo record, if it does not it simply skips the entry and continues to the next iteration. However it does not release the storage buffer leading to a memory leak.

Fix the memory leak by freeing the buffer on size mismatch.

Fixes 5e013ad20689 ("HID: wacom: Remove static WACOM_PKGLEN_MAX limit")
---
 drivers/hid/wacom_sys.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hid/wacom_sys.c +0 -0
index 666b7eb0fdfe..3e4f823f8ee8 100644

drivers/hid/wacom_sys.c static void wacom_wac_queue_flush(struct hid_device *hdev, · line 93

Quoted 7 lines
drivers/hid/wacom_sys.c +1 -0
@@ -87,6 +87,7 @@ static void wacom_wac_queue_flush(struct hid_device *hdev,
 			// to flush seems reasonable enough, however.
 			hid_warn(hdev, "%s: removed fifo entry with unexpected size\n",
 				 __func__);
+			kfree(buf);
 			continue;
 		}
 		err = hid_report_raw_event(hdev, HID_INPUT_REPORT, buf, size, false);

Applied, thanks.

Signature · 2 lines
Jiri Kosina
SUSE Labs