linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] HID: wacom: Always increment hdev refcount within wacom_get_hdev_data
@ 2017-09-18 16:27 Jason Gerecke
  2017-09-18 21:03 ` Ping Cheng
  2017-10-02  9:45 ` Jiri Kosina
  0 siblings, 2 replies; 4+ messages in thread
From: Jason Gerecke @ 2017-09-18 16:27 UTC (permalink / raw)
  To: linux-input, Jiri Kosina
  Cc: Benjamin Tissoires, Ping Cheng, Aaron Skomra, Jason Gerecke,
	stable, Jason Gerecke

The wacom_get_hdev_data function is used to find and return a reference to
the "other half" of a Wacom device (i.e., the touch device associated with
a pen, or vice-versa). To ensure these references are properly accounted
for, the function is supposed to automatically increment the refcount before
returning. This was not done, however, for devices which have pen & touch
on different interfaces of the same USB device. This can lead to a WARNING
("refcount_t: underflow; use-after-free") when removing the module or device
as we call kref_put() more times than kref_get(). Triggering an "actual" use-
after-free would be difficult since both devices will disappear nearly-
simultaneously. To silence this warning and prevent the potential error, we
need to increment the refcount for all cases within wacom_get_hdev_data.

Fixes: 41372d5d40 ("HID: wacom: Augment 'oVid' and 'oPid' with heuristics for HID_GENERIC")
Cc: <stable@vger.kernel.org> # v4.9+
Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
---
 drivers/hid/wacom_sys.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index 735bfbbcaa82..906e654fb0ba 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -668,8 +668,10 @@ static struct wacom_hdev_data *wacom_get_hdev_data(struct hid_device *hdev)
 
 	/* Try to find an already-probed interface from the same device */
 	list_for_each_entry(data, &wacom_udev_list, list) {
-		if (compare_device_paths(hdev, data->dev, '/'))
+		if (compare_device_paths(hdev, data->dev, '/')) {
+			kref_get(&data->kref);
 			return data;
+		}
 	}
 
 	/* Fallback to finding devices that appear to be "siblings" */
-- 
2.14.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] HID: wacom: Always increment hdev refcount within wacom_get_hdev_data
  2017-09-18 16:27 [PATCH] HID: wacom: Always increment hdev refcount within wacom_get_hdev_data Jason Gerecke
@ 2017-09-18 21:03 ` Ping Cheng
       [not found]   ` <CANRwn3Ts2NGUWU-m62zXr54_gYDPbDRpWceVL08Ce9q7o0-mrQ@mail.gmail.com>
  2017-10-02  9:45 ` Jiri Kosina
  1 sibling, 1 reply; 4+ messages in thread
From: Ping Cheng @ 2017-09-18 21:03 UTC (permalink / raw)
  To: Jason Gerecke
  Cc: linux-input, Jiri Kosina, Benjamin Tissoires, Aaron Skomra,
	stable # v4 . 10, Jason Gerecke

On Mon, Sep 18, 2017 at 9:27 AM, Jason Gerecke <killertofu@gmail.com> wrote:
> The wacom_get_hdev_data function is used to find and return a reference to
> the "other half" of a Wacom device (i.e., the touch device associated with
> a pen, or vice-versa). To ensure these references are properly accounted
> for, the function is supposed to automatically increment the refcount before
> returning. This was not done, however, for devices which have pen & touch
> on different interfaces of the same USB device. This can lead to a WARNING
> ("refcount_t: underflow; use-after-free") when removing the module or device
> as we call kref_put() more times than kref_get(). Triggering an "actual" use-
> after-free would be difficult since both devices will disappear nearly-
> simultaneously. To silence this warning and prevent the potential error, we
> need to increment the refcount for all cases within wacom_get_hdev_data.
>
> Fixes: 41372d5d40 ("HID: wacom: Augment 'oVid' and 'oPid' with heuristics for HID_GENERIC")
> Cc: <stable@vger.kernel.org> # v4.9+
> Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>

Reviewed-by: Ping Cheng <ping.cheng@wacom.com>

Cheers,
Ping

> ---
>  drivers/hid/wacom_sys.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
> index 735bfbbcaa82..906e654fb0ba 100644
> --- a/drivers/hid/wacom_sys.c
> +++ b/drivers/hid/wacom_sys.c
> @@ -668,8 +668,10 @@ static struct wacom_hdev_data *wacom_get_hdev_data(struct hid_device *hdev)
>
>         /* Try to find an already-probed interface from the same device */
>         list_for_each_entry(data, &wacom_udev_list, list) {
> -               if (compare_device_paths(hdev, data->dev, '/'))
> +               if (compare_device_paths(hdev, data->dev, '/')) {
> +                       kref_get(&data->kref);
>                         return data;
> +               }
>         }
>
>         /* Fallback to finding devices that appear to be "siblings" */
> --
> 2.14.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] HID: wacom: Always increment hdev refcount within wacom_get_hdev_data
       [not found]   ` <CANRwn3Ts2NGUWU-m62zXr54_gYDPbDRpWceVL08Ce9q7o0-mrQ@mail.gmail.com>
@ 2017-10-02  8:56     ` Jiri Kosina
  0 siblings, 0 replies; 4+ messages in thread
From: Jiri Kosina @ 2017-10-02  8:56 UTC (permalink / raw)
  To: Jason Gerecke
  Cc: Ping Cheng, linux-input, Benjamin Tissoires, Aaron Skomra,
	stable # v4 . 10, Jason Gerecke

On Tue, 26 Sep 2017, Jason Gerecke wrote:

> Haven't seen any activity on this patch, so sending a reminder.

Yeah, I have been travelling for past 3 weeks and acumulated quite some 
backlog, sorry. Everything pending should be processed by the end of this 
week.

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] HID: wacom: Always increment hdev refcount within wacom_get_hdev_data
  2017-09-18 16:27 [PATCH] HID: wacom: Always increment hdev refcount within wacom_get_hdev_data Jason Gerecke
  2017-09-18 21:03 ` Ping Cheng
@ 2017-10-02  9:45 ` Jiri Kosina
  1 sibling, 0 replies; 4+ messages in thread
From: Jiri Kosina @ 2017-10-02  9:45 UTC (permalink / raw)
  To: Jason Gerecke
  Cc: linux-input, Benjamin Tissoires, Ping Cheng, Aaron Skomra, stable,
	Jason Gerecke

On Mon, 18 Sep 2017, Jason Gerecke wrote:

> The wacom_get_hdev_data function is used to find and return a reference to
> the "other half" of a Wacom device (i.e., the touch device associated with
> a pen, or vice-versa). To ensure these references are properly accounted
> for, the function is supposed to automatically increment the refcount before
> returning. This was not done, however, for devices which have pen & touch
> on different interfaces of the same USB device. This can lead to a WARNING
> ("refcount_t: underflow; use-after-free") when removing the module or device
> as we call kref_put() more times than kref_get(). Triggering an "actual" use-
> after-free would be difficult since both devices will disappear nearly-
> simultaneously. To silence this warning and prevent the potential error, we
> need to increment the refcount for all cases within wacom_get_hdev_data.
> 
> Fixes: 41372d5d40 ("HID: wacom: Augment 'oVid' and 'oPid' with heuristics for HID_GENERIC")
> Cc: <stable@vger.kernel.org> # v4.9+
> Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>

Applied to for-4.14/upstream-fixes.

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-10-02  9:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-18 16:27 [PATCH] HID: wacom: Always increment hdev refcount within wacom_get_hdev_data Jason Gerecke
2017-09-18 21:03 ` Ping Cheng
     [not found]   ` <CANRwn3Ts2NGUWU-m62zXr54_gYDPbDRpWceVL08Ce9q7o0-mrQ@mail.gmail.com>
2017-10-02  8:56     ` Jiri Kosina
2017-10-02  9:45 ` Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).