From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2A2AFA3728 for ; Wed, 16 Oct 2019 22:07:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AD5D12168B for ; Wed, 16 Oct 2019 22:07:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571263643; bh=PAYf8s8/30odfXMIUrZmJ6XX6OBvHvz49VyVtIGCtdo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=CSTe7Xl4QeVZGupsmyn8dbp8TIoRIq4l3EwQ46hDy3nZ4kWJz7LeCiYAekn1r7H50 F4jf57PadjJzs79c4kt7Hwy5HeVrpsN5FMWqAiNNjEUqM+ce8wd9xbiX/juD1SkxMD BwubLZRFX148JFC6otWPMCB+fs769XrIIoll5XFo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407052AbfJPWHW (ORCPT ); Wed, 16 Oct 2019 18:07:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:51626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406693AbfJPV6O (ORCPT ); Wed, 16 Oct 2019 17:58:14 -0400 Received: from localhost (unknown [192.55.54.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 861DE20872; Wed, 16 Oct 2019 21:58:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571263093; bh=PAYf8s8/30odfXMIUrZmJ6XX6OBvHvz49VyVtIGCtdo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TFFzxXbegIxodqr3DU9JeIuYu+zi7IvEaTa5fZY4LYiewBOVr5k/EHPNqLu1uourA q9rj4AutjpiGWJLl2m0N3CwQYr6u0cltZHBdrW45KZ2ERjqOuTnVplhUVFQVWtKVk7 +d7TGs7MuOHgHfmB1Tz0CTHCgyynV7I9/2OMq3NE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+0243cb250a51eeefb8cc@syzkaller.appspotmail.com, Johan Hovold Subject: [PATCH 5.3 015/112] USB: adutux: fix use-after-free on disconnect Date: Wed, 16 Oct 2019 14:50:07 -0700 Message-Id: <20191016214847.953154975@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214844.038848564@linuxfoundation.org> References: <20191016214844.038848564@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johan Hovold commit 44efc269db7929f6275a1fa927ef082e533ecde0 upstream. The driver was clearing its struct usb_device pointer, which it used as an inverted disconnected flag, before deregistering the character device and without serialising against racing release(). This could lead to a use-after-free if a racing release() callback observes the cleared pointer and frees the driver data before disconnect() is finished with it. This could also lead to NULL-pointer dereferences in a racing open(). Fixes: f08812d5eb8f ("USB: FIx locks and urb->status in adutux (updated)") Cc: stable # 2.6.24 Reported-by: syzbot+0243cb250a51eeefb8cc@syzkaller.appspotmail.com Tested-by: syzbot+0243cb250a51eeefb8cc@syzkaller.appspotmail.com Signed-off-by: Johan Hovold Link: https://lore.kernel.org/r/20190925092913.8608-1-johan@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/adutux.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/drivers/usb/misc/adutux.c +++ b/drivers/usb/misc/adutux.c @@ -762,14 +762,15 @@ static void adu_disconnect(struct usb_in dev = usb_get_intfdata(interface); - mutex_lock(&dev->mtx); /* not interruptible */ - dev->udev = NULL; /* poison */ usb_deregister_dev(interface, &adu_class); - mutex_unlock(&dev->mtx); mutex_lock(&adutux_mutex); usb_set_intfdata(interface, NULL); + mutex_lock(&dev->mtx); /* not interruptible */ + dev->udev = NULL; /* poison */ + mutex_unlock(&dev->mtx); + /* if the device is not opened, then we clean up right now */ if (!dev->open_count) adu_delete(dev);