All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jinmo Yang" <jinmo44.yang@gmail.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v2 1/5] HID: wacom: check the input device in the shared report helpers
Date: Sun, 18 Oct 2026 11:00:15 +0000	[thread overview]
Message-ID: <sashiko-outbox-176065@kernel.org> (raw)
In-Reply-To: <20261018104617.743771-2-jinmo44.yang@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] hid: wacom: touch_input dereferenced before wacom_wac_finger_count_touches()
--

commit 44932063e701ad08bed9376ede6b9b3005174d4c
Author: Jinmo Yang <jinmo44.yang@gmail.com>

HID: wacom: check the input device in the shared report helpers

This commit adds NULL checks for the input device in
wacom_wac_finger_count_touches() and wacom_report_numbered_buttons() to
avoid NULL pointer dereferences when a device interface has no allocated
touch or pad input device.

> diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
> index c4cd87b781c45..567b01882eb1e 100644
> --- a/drivers/hid/wacom_wac.c
> +++ b/drivers/hid/wacom_wac.c
> @@ -1263,6 +1263,12 @@ static int wacom_wac_finger_count_touches(struct wacom_wac *wacom)
>  	int count = 0;
>  	int i;
>  
> +	if (!input) {
> +		dev_warn_once(&container_of(wacom, struct wacom, wacom_wac)->hdev->dev,
> +			      "%s: touch_input is NULL\n", __func__);
> +		return 0;
> +	}
> +
>  	if (!touch_max)
>  		return 0;
>  

[Severity: High]
Can this NULL check in wacom_wac_finger_count_touches() actually be
reached when wacom->touch_input is NULL?

Every caller of wacom_wac_finger_count_touches() in drivers/hid/wacom_wac.c
first passes wacom->touch_input to input_mt_sync_frame(), which
immediately dereferences dev->mt:

drivers/input/input-mt.c:input_mt_sync_frame() {
	struct input_mt *mt = dev->mt;
	bool use_count = false;

	if (!mt)
		return;
    ...
}

For example, while a later commit in this series ("HID: wacom: add NULL
input guards to Bamboo touch/button handlers") guards wacom_bpt_touch(),
wacom_24hdt_irq() remains unguarded when wacom->touch_input is NULL (such
as when a WACOM_24HDT or WACOM_27QHDT device probes with a report
descriptor that omits WACOM_FINGER_FIELD usages):

drivers/hid/wacom_wac.c:wacom_24hdt_irq() {
	struct input_dev *input = wacom->touch_input;
    ...
	for (i = 0; i < contacts_to_send; i++) {
		int offset = (byte_per_packet * i) + 1;
		bool touch = (data[offset] & 0x1) && report_touch_events(wacom);
		int slot = input_mt_get_slot_by_key(input, data[offset + 1]);
    ...
	}
	input_mt_sync_frame(input);

	wacom->num_contacts_left -= contacts_to_send;
	if (wacom->num_contacts_left <= 0) {
		wacom->num_contacts_left = 0;
		wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
	}
	return 1;
}

Wouldn't wacom_24hdt_irq() dereference a NULL input pointer in
input_mt_get_slot_by_key() and input_mt_sync_frame() before ever reaching
wacom_wac_finger_count_touches()?

Also, when input is non-NULL and touch_max > 1, input_mt_get_slot_by_key(),
input_mt_report_slot_state(), and input_mt_sync_frame() all check for a
NULL dev->mt, whereas wacom_wac_finger_count_touches() dereferences
input->mt->num_slots directly:

drivers/hid/wacom_wac.c:wacom_wac_finger_count_touches() {
    ...
	for (i = 0; i < input->mt->num_slots; i++) {
		struct input_mt_slot *ps = &input->mt->slots[i];
    ...
}

Should wacom_24hdt_irq() check for a NULL input at entry, and should
wacom_wac_finger_count_touches() also guard against input->mt being NULL
(for instance if touch_max > 1 is set via HID_DG_CONTACTMAX without
input_mt_init_slots() having been called)?

[ ... ]

>
>
>

[]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261018104617.743771-1-jinmo44.yang@gmail.com?part=1

  reply	other threads:[~2026-10-18 11:00 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-23 15:01 [PATCH] HID: wacom: fix NULL pointer dereference in wacom_intuos_pad() Jinmo Yang
2026-05-23 15:06 ` [PATCH v2] " Jinmo Yang
2026-05-23 15:50   ` sashiko-bot
2026-05-29 21:44   ` Dmitry Torokhov
2026-06-10 15:48     ` Jiri Kosina
2026-09-26 18:37       ` Jinmo Yang
2026-09-27  4:11       ` [PATCH 0/5] HID: wacom: check input devices in the report handlers Jinmo Yang
2026-09-27  4:11         ` [PATCH 1/5] HID: wacom: check the input device in the shared report helpers Jinmo Yang
2026-10-17  0:05           ` Jason Gerecke
2026-09-27  4:11         ` [PATCH 2/5] HID: wacom: check the input devices in the legacy irq handlers Jinmo Yang
2026-10-17  0:05           ` Jason Gerecke
2026-09-27  4:11         ` [PATCH 3/5] HID: wacom: check the input device in wacom_intuos_pad() Jinmo Yang
2026-09-27  4:24           ` sashiko-bot
2026-10-17  0:05           ` Jason Gerecke
2026-09-27  4:11         ` [PATCH 4/5] HID: wacom: check the input device in wacom_intuos_bt_irq() Jinmo Yang
2026-10-17  0:05           ` Jason Gerecke
2026-09-27  4:11         ` [PATCH 5/5] HID: wacom: check the input devices in the Bamboo handlers Jinmo Yang
2026-10-17  0:05           ` Jason Gerecke
2026-10-16  9:27         ` [PATCH 0/5] HID: wacom: check input devices in the report handlers Jiri Kosina
2026-10-17  0:05         ` Jason Gerecke
2026-10-18 10:46         ` [PATCH v2 0/5] HID: wacom: guard against NULL input devices on successful probe Jinmo Yang
2026-10-18 10:46           ` [PATCH v2 1/5] HID: wacom: check the input device in the shared report helpers Jinmo Yang
2026-10-18 11:00             ` sashiko-bot [this message]
2026-10-18 10:46           ` [PATCH v2 2/5] HID: wacom: check the input devices in the legacy irq handlers Jinmo Yang
2026-10-18 10:53             ` sashiko-bot
2026-10-18 10:46           ` [PATCH v2 3/5] HID: wacom: add NULL pad_input guard to wacom_intuos_pad() Jinmo Yang
2026-10-18 10:46           ` [PATCH v2 4/5] HID: wacom: add NULL input guards to wacom_intuos_bt_irq() Jinmo Yang
2026-10-18 10:46           ` [PATCH v2 5/5] HID: wacom: add NULL input guards to Bamboo touch/button handlers Jinmo Yang
2026-10-18 12:47         ` [PATCH v3 0/6] HID: wacom: guard against NULL input devices on successful probe Jinmo Yang
2026-10-18 12:47           ` [PATCH v3 1/6] HID: wacom: check the input device in the shared report helpers Jinmo Yang
2026-10-18 12:47           ` [PATCH v3 2/6] HID: wacom: check the input devices in the legacy irq handlers Jinmo Yang
2026-10-18 12:47           ` [PATCH v3 3/6] HID: wacom: add NULL pad_input guard to wacom_intuos_pad() Jinmo Yang
2026-10-18 12:47           ` [PATCH v3 4/6] HID: wacom: add NULL input guards to wacom_intuos_bt_irq() Jinmo Yang
2026-10-18 12:47           ` [PATCH v3 5/6] HID: wacom: add NULL input guards to Bamboo touch/button handlers Jinmo Yang
2026-10-18 12:47           ` [PATCH v3 6/6] HID: wacom: add NULL touch_input guards to remaining touch handlers Jinmo Yang
2026-05-23 15:45 ` [PATCH] HID: wacom: fix NULL pointer dereference in wacom_intuos_pad() sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-176065@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jinmo44.yang@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.