From patchwork Mon Sep 18 16:27:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 9957143 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7604D60385 for ; Mon, 18 Sep 2017 16:28:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6652228550 for ; Mon, 18 Sep 2017 16:28:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B1242873E; Mon, 18 Sep 2017 16:28:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF73A28550 for ; Mon, 18 Sep 2017 16:28:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756083AbdIRQ2R (ORCPT ); Mon, 18 Sep 2017 12:28:17 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:36381 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756025AbdIRQ2O (ORCPT ); Mon, 18 Sep 2017 12:28:14 -0400 Received: by mail-qk0-f196.google.com with SMTP id i14so650835qke.3; Mon, 18 Sep 2017 09:28:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=LppNSycIyHNr/10A2XD4l1bXfyoIVDC7QcyFn1DEFCk=; b=GfTWLBHbL7+A4TiOGoeAl66f0gvXV6C1RwubegWtn4g9ORFCpyQqiar/r0ThYjA2hO UW9CbWTWL0ezMSIihtSApSu6DW46rFEH+jcomjRjctNJs4B/L3AJAscD1ijSnisL4URp WR2UL2/lGACzE47g/LWo1fZ/rOSbKU+4n8/M3QHv7X3tKFKRMMUdUNMZb4wbJQJeShkP bo/qUAkqY30qBExKfEDxylSWBluEerM9wJtTNH6sGWOTdL8/LmF8RcOqvnqvxIMPd6gO jCyGBG53vjCDs5rQzVp5yYUR33lhQaBjaerETN1GArCErqggl8J9AujKml+f22Jkzz1y SFvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=LppNSycIyHNr/10A2XD4l1bXfyoIVDC7QcyFn1DEFCk=; b=HkSb45mwS0Vhka/tiqE30YKtV/XS1JRe+bJnbhq2ukGfkDJdgFSwTH/w/olrb3SA3x N8f7qIqokgL6qbVyGXLCONH8Opwoicd26mGAECpCaARkwuQuzmKtwpssp+5xpbgoaOkH ppq8rmfh7PYC/VixaYA9XsetM8/1AIAuBiHZs5LOy52FFu+54MX+ecNbAyzErAWSAbju c5O+Mp2AbXnuVvPWOFX2QUPVkRpAP5ujNqVlKhXtQpHuIugahJhMpET1UeDhgJjegzkn i9QDQlp6J2h2M0irDpzqLIVxe4keeaIOZHfBvkdxqw4lupBMX0Hb93PSgi3UxeaO8rQg jhBw== X-Gm-Message-State: AHPjjUjC2NSDOWxO2TAOnt3w/uxpjHhpeIAoCvKYGUmU/MsAeGr17N0Y shJELGnST8OihAPPXsQ= X-Google-Smtp-Source: AOwi7QAN5aY1tQRWrYawn2NiwheyQTyQJi9yon/p/hyTVInGiaBHTUTXHMRrQL77KWmHeZkbpwlNkw== X-Received: by 10.233.244.72 with SMTP id z8mr19654028qkl.148.1505752092929; Mon, 18 Sep 2017 09:28:12 -0700 (PDT) Received: from wacom-arch2.corp.onewacom.com ([50.225.60.4]) by smtp.gmail.com with ESMTPSA id l11sm5340177qke.19.2017.09.18.09.28.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Sep 2017 09:28:12 -0700 (PDT) From: Jason Gerecke To: linux-input@vger.kernel.org, Jiri Kosina Cc: Benjamin Tissoires , Ping Cheng , Aaron Skomra , Jason Gerecke , stable@vger.kernel.org, Jason Gerecke Subject: [PATCH] HID: wacom: Always increment hdev refcount within wacom_get_hdev_data Date: Mon, 18 Sep 2017 09:27:42 -0700 Message-Id: <20170918162742.10717-1-killertofu@gmail.com> X-Mailer: git-send-email 2.14.1 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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: # v4.9+ Signed-off-by: Jason Gerecke Reviewed-by: Ping Cheng --- 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" */