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,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 EAB0BECE599 for ; Wed, 16 Oct 2019 21:53:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B18D821A49 for ; Wed, 16 Oct 2019 21:53:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571262815; bh=2/YXhLFdEXvDWwBgH8c0w48Z1nq/ZTRqxtt8A54n0uM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=2ByJg3+EUtNKD9qM30Xdks+cP7/u+P9+ag+wkfHJ6uUS++9jIE/zNJir7kqtUZLc4 qcHocCfFHO+lTQjphsUJImv+OpuaNNCzdURkDpQcJZVyYxHy6T0avtMdVSDpgO+jdt RrpkL0Gf00ytAz3bvu+lGNtKseypNhH1UAtqCW4c= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437540AbfJPVxe (ORCPT ); Wed, 16 Oct 2019 17:53:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:42278 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394855AbfJPVxZ (ORCPT ); Wed, 16 Oct 2019 17:53:25 -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 3392921A4C; Wed, 16 Oct 2019 21:53:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571262805; bh=2/YXhLFdEXvDWwBgH8c0w48Z1nq/ZTRqxtt8A54n0uM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xFNQttbw0rVIrBtfABdmCpIDuhME/EfiDx2x/YvERGRY2Oac4I99vGQOWI/XdwaC/ ZDebo9usvIyF32DxkyRXyY+DskXmog+rYKz5cwsV42dGa4+Lfxscfz5nf9Q9/HiYIa BCJtKPo6pMCikQyOIOegogMsXQNe8N7mVHYqyXEE= 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 4.4 39/79] USB: adutux: fix use-after-free on disconnect Date: Wed, 16 Oct 2019 14:50:14 -0700 Message-Id: <20191016214801.599309080@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214729.758892904@linuxfoundation.org> References: <20191016214729.758892904@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 @@ -803,14 +803,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);