Received: by 10.223.176.5 with SMTP id f5csp980619wra; Fri, 2 Feb 2018 09:11:50 -0800 (PST) X-Google-Smtp-Source: AH8x225nUSjEO59qOyPpasXANBEM/CZ0apDpfXjlVi+cTy0mJS3KErwZT8bvkNBJn0Up8bYSRJun X-Received: by 2002:a17:902:d904:: with SMTP id c4-v6mr15462215plz.125.1517591510514; Fri, 02 Feb 2018 09:11:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517591510; cv=none; d=google.com; s=arc-20160816; b=xaA2KHc0oIpW5WXCtPYDhyrYGDMurMVXi4Jb7ejgW1NJ/m5o4E9ke+6/RNk9j3nlHR fqfsaiq3NA9WtdN6i/Rm88MQOlvM0UynLiboXKfJnvS9H8UR2/nb8yyMeaF2r1nxO2T+ ebHZzknfskUhPmdrreU2NO7WmUswuh0IjOEoDbtEiUQDB6EP0xwyvbrViOeAmAH5lIRJ fD6yZyIxTzsc7YlRodjc+0JuRaUavRk79icZuRY0w/gvLqAKSZDdyciEUg3KCuu7c1TK gNmalFUlYYHaopiDOoSGGhULURbTfu3ecwD4lIeKbIax0Km5d/5wotgeJi19imYfopB8 ZjIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=yAjtyL89mOQF6iJV0KSWNhMiKSZcmX6WXZJNLc3umDY=; b=tfUlOCW5RDZJJj3o18a1Vt2TONDysoTpeOei6J22rVMPL0zNVCBPs04+jydYL9rpJ2 UK8dzfnnXm+pmmIgmI20w0VwyJ0AbWg9L3QGL1ob/EfM8duU6fkcn+CGFPVUMJOuxrDy aAmsc/ah4gmRQ2xH3VQMWv5oMjgfTEObk0F5CGcaqBRQWYtA2Auq5RD0ph0Gb6NpQANU 2lXifFgEzwWCDUWk9e/Xi/7EpwClNQ5N2py6TV7wbX4Dg742edMa6a5IsAOcL26vMTPr skJ9PN3HuKHfXU8h3uG9bgYbQusDrqBJ8CViZxey9LLGM7DASbwf35C2gkkKL0+58u1q 12xA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n6-v6si2157495plp.562.2018.02.02.09.11.35; Fri, 02 Feb 2018 09:11:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753269AbeBBRJ5 (ORCPT + 99 others); Fri, 2 Feb 2018 12:09:57 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:36384 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752773AbeBBRFH (ORCPT ); Fri, 2 Feb 2018 12:05:07 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 21CC6E3B; Fri, 2 Feb 2018 17:05:05 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aaron Armstrong Skomra , Jiri Kosina Subject: [PATCH 4.9 11/86] HID: wacom: EKR: ensure devres groups at higher indexes are released Date: Fri, 2 Feb 2018 17:57:31 +0100 Message-Id: <20180202140823.877348441@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140822.679101338@linuxfoundation.org> References: <20180202140822.679101338@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Aaron Armstrong Skomra commit 791ae273731fa85d3332e45064dab177ae663e80 upstream. Background: ExpressKey Remotes communicate their events via usb dongle. Each dongle can hold up to 5 pairings at one time and one EKR (identified by its serial number) can unfortunately be paired with its dongle more than once. The pairing takes place in a round-robin fashion. Input devices are only created once per EKR, when a new serial number is seen in the list of pairings. However, if a device is created for a "higher" paring index and subsequently a second pairing occurs at a lower pairing index, unpairing the remote with that serial number from any pairing index will currently cause a driver crash. This occurs infrequently, as two remotes are necessary to trigger this bug and most users have only one remote. As an illustration, to trigger the bug you need to have two remotes, and pair them in this order: 1. slot 0 -> remote 1 (input device created for remote 1) 2. slot 1 -> remote 1 (duplicate pairing - no device created) 3. slot 2 -> remote 1 (duplicate pairing - no device created) 4. slot 3 -> remote 1 (duplicate pairing - no device created) 5. slot 4 -> remote 2 (input device created for remote 2) 6. slot 0 -> remote 2 (1 destroyed and recreated at slot 1) 7. slot 1 -> remote 2 (1 destroyed and recreated at slot 2) 8. slot 2 -> remote 2 (1 destroyed and recreated at slot 3) 9. slot 3 -> remote 2 (1 destroyed and not recreated) 10. slot 4 -> remote 2 (2 was already in this slot so no changes) 11. slot 0 -> remote 1 (The current code sees remote 2 was paired over in one of the dongle slots it occupied and attempts to remove all information about remote 2 [1]. It calls wacom_remote_destroy_one for remote 2, but the destroy function assumes the lowest index is where the remote's input device was created. The code "cleans up" the other remote 2 pairings including the one which the input device was based on, assuming they were were just duplicate pairings. However, the cleanup doesn't call the devres release function for the input device that was created in slot 4). This issue is fixed by this commit. [1] Remote 2 should subsequently be re-created on the next packet from the EKR at the lowest numbered slot that it occupies (here slot 1). Fixes: f9036bd43602 ("HID: wacom: EKR: use devres groups to manage resources") Signed-off-by: Aaron Armstrong Skomra Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/wacom_sys.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -2192,23 +2192,23 @@ static void wacom_remote_destroy_one(str int i; unsigned long flags; - spin_lock_irqsave(&remote->remote_lock, flags); - remote->remotes[index].registered = false; - spin_unlock_irqrestore(&remote->remote_lock, flags); + for (i = 0; i < WACOM_MAX_REMOTES; i++) { + if (remote->remotes[i].serial == serial) { - if (remote->remotes[index].battery.battery) - devres_release_group(&wacom->hdev->dev, - &remote->remotes[index].battery.bat_desc); + spin_lock_irqsave(&remote->remote_lock, flags); + remote->remotes[i].registered = false; + spin_unlock_irqrestore(&remote->remote_lock, flags); - if (remote->remotes[index].group.name) - devres_release_group(&wacom->hdev->dev, - &remote->remotes[index]); + if (remote->remotes[i].battery.battery) + devres_release_group(&wacom->hdev->dev, + &remote->remotes[i].battery.bat_desc); + + if (remote->remotes[i].group.name) + devres_release_group(&wacom->hdev->dev, + &remote->remotes[i]); - for (i = 0; i < WACOM_MAX_REMOTES; i++) { - if (remote->remotes[i].serial == serial) { remote->remotes[i].serial = 0; remote->remotes[i].group.name = NULL; - remote->remotes[i].registered = false; remote->remotes[i].battery.battery = NULL; wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN; }