Re: [PATCH 1/5] HID: wacom: check the input device in the shared report helpers
From: Jason Gerecke
Date: Fri Oct 16 2026 - 20:06:27 EST
On Sat, Sep 26, 2026 at 9:12 PM Jinmo Yang <jinmo44.yang@xxxxxxxxx> wrote:
>
> wacom_report_numbered_buttons() and wacom_wac_finger_count_touches() are
> reached from several report handlers and use the input device they are
> given without checking it.
>
> Both can see a NULL input device on a fully successful probe. The report
> handler is selected by features.type from the id table, while the three
> input devices are allocated from what the report descriptor declares.
> When wacom_setup_{pen,touch,pad}_input_capabilities() returns -ENODEV,
> wacom_setup_inputs() frees that input device, sets the pointer to NULL
> and still returns 0 - the "no pen in use on this interface" case.
> wacom_wac_irq() then still routes reports to a handler that passes the
> NULL pointer down.
>
> Reproduced on linux-next 20260925 (x86_64, KASAN) from one /dev/uhid
> device plus a single UHID_INPUT2 write:
>
> BUG: KASAN: null-ptr-deref in range [0x290-0x297]
> RIP: 0010:wacom_report_numbered_buttons+0x37/0x210
> wacom_intuos_irq+0x29e/0x3300
> wacom_wac_irq+0x1b59/0xb3f0
> wacom_raw_event+0x68f/0xb60
> __hid_input_report+0x398/0x4d0
> uhid_char_write+0xa99/0xfc0
>
> Check the pointer in both helpers, following the convention the driver
> already uses in wacom_tpc_irq() and wacom_wac_pad_event().
>
> Fixes: 10059cdc0ad0 ("Input: wacom - split out the pad device for Intuos/Cintiq")
> Fixes: 2a6cdbdd4cc0 ("HID: wacom: Introduce new 'touch_input' device")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Jinmo Yang <jinmo44.yang@xxxxxxxxx>
> ---
> drivers/hid/wacom_wac.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
> index c4cd87b781c4..177a1e09fd05 100644
> --- a/drivers/hid/wacom_wac.c
> +++ b/drivers/hid/wacom_wac.c
> @@ -1263,6 +1263,9 @@ static int wacom_wac_finger_count_touches(struct wacom_wac *wacom)
> int count = 0;
> int i;
>
> + if (!input)
> + return 0;
> +
Checks like this are for an unusual error condition so a dev_warn_once
or hid_warn_once before returning is suggested. I could even see an
argument for removing the device if these conditions are encountered,
but that's probably too extreme. In general, each of the places that
you perform this check should be updated with such a warning (in this
and other patches).
Jason (she/they)
---
Now instead of four in the eights place /
you’ve got three, ‘Cause you added one /
(That is to say, eight) to the two, /
But you can’t take seven from three, /
So you look at the sixty-fours....
> if (!touch_max)
> return 0;
>
> @@ -4226,9 +4229,14 @@ static void wacom_update_led(struct wacom *wacom, int button_count, int mask,
> static void wacom_report_numbered_buttons(struct input_dev *input_dev,
> int button_count, int mask)
> {
> - struct wacom *wacom = input_get_drvdata(input_dev);
> + struct wacom *wacom;
> int i;
>
> + if (!input_dev)
> + return;
> +
> + wacom = input_get_drvdata(input_dev);
> +
> for (i = 0; i < wacom->led.count; i++)
> wacom_update_led(wacom, button_count, mask, i);
>
> --
> 2.53.0
>
>