Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2680804ybz; Sun, 19 Apr 2020 07:11:08 -0700 (PDT) X-Google-Smtp-Source: APiQypLJJVIzbC/RMQKPyLX/UdCqkCizl9pW3wu7FzFjG2jZmMOifoR7YbQ15HYzizl6HQj1ZIyG X-Received: by 2002:a17:907:a89:: with SMTP id by9mr11433421ejc.289.1587305467995; Sun, 19 Apr 2020 07:11:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587305467; cv=none; d=google.com; s=arc-20160816; b=JCGTWbj23j/NmPCd1raSldMvAtxWoNqyWm7nelkTpQxgwkvrQKlgATWanNiA7FkgI7 lQPV6StUkhC71h7zuy+mY85bq1J/lk8zq2WbFJ1/g6mKu55NlUmpgBs7m1ItwJt5CE7V hMdeykanS6OmM1mq2WffmMm/ys/Oo3b1lCIPP8MBedxUuljzAQnaLo6jix/fHTMb0ocY Bwri3y8mo71kUXpWjqdlJpmieU78uAuOOHVt3ipjqJdfpwIyTR7RaVTVHBgzyKyvvKQ4 5bp8GYfhlAnOZxpwmNEBn3rKGV7OK73zmaHtr3pqIodMJjbKYrBoSTDUTyirqIh1bm1Q Uetw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=/qDfhcOslcy37uGE9XwEx7vgxtmdJw0pSznJM5bub3M=; b=dRpvVvUbun6IpzxMEDDWrWfDZcMUH4NNhKqnS14pCAZe2cgion22APngKixhwFvhad W2lUv5yfKS1gInrrbNv//3JO8G3Lfv79q7R4vDmGGr3nfyHANoZJOJoLsuOwWQH6/X2i oQUgNAaUZBGQIPanihpIPjvgt1n94GDq//sU2UXaGCWMA91WcFpyfVxzRU4HT5Ei/NQq GaX5x2AlN56UDp13jk/y4l/zrVMEJYs8jD5IIH56Eo16RLfop0aTasBSdYX+z0uR6fWE UtF58/toXRlYUSS1JECObShiIglCN/HOO6iQy5oTvH8mTTS/QFF1Rr6+C759liXdAVgT 6CGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 24si17596334ejv.109.2020.04.19.07.10.44; Sun, 19 Apr 2020 07:11:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726083AbgDSOHg (ORCPT + 99 others); Sun, 19 Apr 2020 10:07:36 -0400 Received: from netrider.rowland.org ([192.131.102.5]:45079 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1725949AbgDSOHf (ORCPT ); Sun, 19 Apr 2020 10:07:35 -0400 Received: (qmail 30013 invoked by uid 500); 19 Apr 2020 10:07:34 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 19 Apr 2020 10:07:34 -0400 Date: Sun, 19 Apr 2020 10:07:34 -0400 (EDT) From: Alan Stern X-X-Sender: stern@netrider.rowland.org To: Dmitry Torokhov cc: Julian Squires , Hans de Goede , Jiri Kosina , Benjamin Tissoires , syzbot , , , , , Kernel development list , USB list , , Ping Cheng , , Subject: Re: KASAN: use-after-free Read in usbhid_close (3) In-Reply-To: <20200419041344.GC166864@dtor-ws> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 18 Apr 2020, Dmitry Torokhov wrote: > On Sat, Apr 18, 2020 at 09:09:44PM -0700, Dmitry Torokhov wrote: > > Hi Alan, > > > > On Sat, Apr 18, 2020 at 10:16:32PM -0400, Alan Stern wrote: > > > linux-input people: > > > > > > syzbot has found a bug related to USB/HID/input, and I have narrowed it > > > down to the wacom driver. As far as I can tell, the problem is caused > > > the fact that drivers/hid/wacom_sys.c calls input_register_device() > > > in several places, but it never calls input_unregister_device(). > > > > > > I know very little about the input subsystem, but this certainly seems > > > like a bug. > > > > Wacom driver uses devm_input_allocate_device(), so unregister should > > happen automatically on device removal once we exit wacom_probe(). > > > > > > > > When the device is unplugged, the disconnect pathway doesn't call > > > hid_hw_close(). That routine doesn't get called until the user closes > > > the device file (which can be long after the device is gone and > > > hid_hw_stop() has run). Then usbhid_close() gets a use-after-free > > > error when it tries to access data structures that were deallocated by > > > usbhid_stop(). No doubt there are other problems too, but this is > > > the one that syzbot found. > > > > Unregistering the input device should result in calling wacom_close() > > (if device was previously opened), which, as far as I can tell, calls > > hid_hw_close(). > > > > I wonder if it is valid to call hid_hw_stop() before hid_hw_close()? No, it isn't. If it were, for example, why would evdev_disconnect() -> evdev_cleanup() need to call input_close_device()? And why would usbhid_disconnect() deallocate the usbhid structure which usbhid_stop() accesses? > > It could be that we again get confused by the "easiness" of devm APIs > > and completely screwing up unwind order. That's probably what happened. Alan Stern > Let's also add Ping and Jason to the conversation...