Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2295627ybz; Sat, 18 Apr 2020 21:17:38 -0700 (PDT) X-Google-Smtp-Source: APiQypJXFE/eKj1On4P1IVgFvmVirslE51k5R6QKwQivgf+q42Y8zjLlV3lCjvcLV7KtHUN7pdDP X-Received: by 2002:a17:906:2f03:: with SMTP id v3mr10045176eji.105.1587269858183; Sat, 18 Apr 2020 21:17:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587269858; cv=none; d=google.com; s=arc-20160816; b=v3PPMyqvPdkzMEpvCslaKi8h7iDLviCPGyE6O8DgcxOf83wbjqiVpzLMKx6nyahurl TwJgZ99NY46vqHGWtMxF7ZTSGNs6iSYxG4k29tXJdgLsmcQr+bY9TdzIeVrBKH7WPJFL xj8nEKqqDE305wFwFEoktKgDecazXiOCkW5V8kKKMMWKabXWLP2+F7AKmHKBc06zuDjj lkm5TfNOIkFfqBqwEm9e1YNfxDXNJPfoxQrWxaULSnDHqylsaxdjDaHijnNeJZFSN8pW ODl971T02wCokMs2oCBCk4rVCyxfn2ZcRBB+NKXfveGGMo+mzJ0HxoVO1o7gGIooXuz/ l+Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=3s5cKFQ7XPNe0wu0jQrVSX2Ly/Khgn/8amiFN2ieLnw=; b=ciPkQpF3960UHUV5NlIqEdWZeKhgwuLriwled17LPolnQOHxvpkBBkV2kGwkHcZhM+ xWP9YN/viSijIZ+wXSgthEqHR9bWkqy8D0qEkCFWqwUhvCmeEa3YSbXfm7AIHV/8NEjt nX85RK30VR/OUCVEXmhPc7RdDY48hDvZ1GuJ5zuVypvF48Nlz1T15HQFyIUJF2WsZcVp VobXbkt+6U12YmS4WB/v9oJ0EX9R+OdxLgeQcR4AZ0yhUfODfa+JCpLAao/i+saBZ1Ri k5Y12cSqd2TCzSf+iegAdna4xB/zVC1sVL5yK8lxrvfPFyZu4dtwmkarvgGgFExhhnW0 VVdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nc7C4dtP; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k7si18599160ejq.480.2020.04.18.21.17.14; Sat, 18 Apr 2020 21:17:38 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nc7C4dtP; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726007AbgDSENs (ORCPT + 99 others); Sun, 19 Apr 2020 00:13:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725802AbgDSENs (ORCPT ); Sun, 19 Apr 2020 00:13:48 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F826C061A0C; Sat, 18 Apr 2020 21:13:48 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id o185so2802709pgo.3; Sat, 18 Apr 2020 21:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=3s5cKFQ7XPNe0wu0jQrVSX2Ly/Khgn/8amiFN2ieLnw=; b=nc7C4dtP5jWEPmI/augCn+uFPjAAh138K7yvfwh8oXVE+ZYZqIpHa+07/oyFlmAWSE 8ko6vN4BtMRK2fWqQFms4VjhA9BcA02OcsEUn1RTESHhD6tFFcuv8PYg9/Fehy9Y4zuB urcq4LYm8rKvhwGDzOrLIiiLKhY2lD2Ni6uOi5+uwnMb6Cj+HjFiZFmnPtpvy+4IzKXB G5jR7t+6ydWF8geHkbLrCLXKOvB7juzZNNXzB2Pu0gtpRTsFKp0ZysekCeBQPQgTZCBX a8rSk7OnTSs5oGA3rnpV26xLIjuPMi9rBIWgxbkOGZ/0JReIvrzCKr4R6Hk/WK6PvN/g v+lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=3s5cKFQ7XPNe0wu0jQrVSX2Ly/Khgn/8amiFN2ieLnw=; b=MAQXFPvdPzNXqIcugQLhp/+xjt17snxt4O4xm2hDkFvuano8dNZ8SK7PFLk0kU8zNZ /YrZFAxDPL3Q86WJgMGj1ZSBwjE9TokGGqs8+9RHhqSOj6YX0yYXkV0eIQWxImM3kJ33 umLguihBYptWsP2ZVdLucSlDLRwCjOJ5j/MfIFqh2kz5RC+mkt2tfWtwXJQCo5Vmxkyt 0nHCMBk+SbFeeroaKnYExSkYDNlkqWFyao18OF6k38p11HpwqYfQsIgcdPJRKsi+Tv/E PUut/DtN1HmNsPTCjhx8bMANiI6wBKf2mLFxZshljyapBScgKS5OUQSeT6lttuSgXZsJ uRuQ== X-Gm-Message-State: AGi0PuZJhibf4Dg1FDMlwDqm8Cd/7pF0dZYfy3ewxFHw0xcLRp2S6Zhw XXrEYcz7L4zyQNoMs0iUWrE= X-Received: by 2002:aa7:9575:: with SMTP id x21mr6722659pfq.324.1587269627673; Sat, 18 Apr 2020 21:13:47 -0700 (PDT) Received: from dtor-ws ([2620:15c:202:201:3c2a:73a9:c2cf:7f45]) by smtp.gmail.com with ESMTPSA id x26sm15331040pfo.218.2020.04.18.21.13.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Apr 2020 21:13:47 -0700 (PDT) Date: Sat, 18 Apr 2020 21:13:44 -0700 From: Dmitry Torokhov To: Alan Stern Cc: Julian Squires , Hans de Goede , Jiri Kosina , Benjamin Tissoires , syzbot , linux-input@vger.kernel.org, andreyknvl@google.com, gregkh@linuxfoundation.org, ingrassia@epigenesys.com, Kernel development list , USB list , syzkaller-bugs@googlegroups.com, Ping Cheng , pinglinux@gmail.com, killertofu@gmail.com Subject: Re: KASAN: use-after-free Read in usbhid_close (3) Message-ID: <20200419041344.GC166864@dtor-ws> References: <000000000000f610e805a39af1d0@google.com> <20200419040944.GB166864@dtor-ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200419040944.GB166864@dtor-ws> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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()? > > It could be that we again get confused by the "easiness" of devm APIs > and completely screwing up unwind order. Let's also add Ping and Jason to the conversation... -- Dmitry