Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp227810ybg; Thu, 17 Oct 2019 21:59:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvbgr4ncTsgLngcaZGKoypMwxUtSu3/6CYg/+gr3QwUlwE4Sq/BWwGJ8T3A+Q8bvThg4Uo X-Received: by 2002:a17:906:2584:: with SMTP id m4mr6985491ejb.287.1571374752772; Thu, 17 Oct 2019 21:59:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571374752; cv=none; d=google.com; s=arc-20160816; b=Hz282kNtI5+B3fHhbQL5K4uRE2qkkQDvtTlHgXgv7zQ0n8AHMhRTm7ELzNdkuy0KUF EOaxnMWmQnpY3p4CXMiIRbOv20YIn65HXqM4EXqMUq3FT4AS4opeMCKkig+UT5dwqCm8 HU0YuHgLIpb9eEt57bgunXGy4yNUtaC+UmN+7ZJuqCjA1Cq1vA3k9NBZyI2HRNPGuNMg k3cDJK3RzChCpcj7udkqag572xhwmAmmEf9hLDaPXKz8ls83zQnA0See73m5MwuCHmMC x578b9A8fOxDFmYAngANOcy/QKZU5+stCpr5ERC03q4BuZvXaYvUTe5rEd1axlRVLfYf A9gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ASCr94nZ6XDxG8+wF4Wt7p3ZAz0VUTXZXOGi82P4iZY=; b=e/FJhQPYwdRu4tQFqovn4koqbaTRKCXfDQCu80o3b9S8BlEdTTibvE29WoCcdzKm31 fJVXF2dpyfLGS+V8YF/rhcrd7FY6aVG0SGYhldoTD5K7wu42REJHpWtDk9HUrD4avBPr FiwtxsbG8J3iHdHKV4MmgXxHlSnEajR2esRSdkSiKZbLDkif78aa+m6tYoFgk2/m702u dojIaFbxkXrKWcqDYXRJUR5eHDFysqF5VjwJLk2H8mmLl/0rMIN2vQoU83E39Jdl8tSN uPocITFDxWCHHbZhI3uCyLSJMJagrvZAqwMT7P7lOsFAS44ZFXmm5NeLD86j6bkbOeJ/ E+Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AGWOv+RX; 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 l12si3691151edk.444.2019.10.17.21.58.46; Thu, 17 Oct 2019 21:59:12 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=AGWOv+RX; 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 S2387495AbfJPWQx (ORCPT + 99 others); Wed, 16 Oct 2019 18:16:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:45228 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395138AbfJPVzA (ORCPT ); Wed, 16 Oct 2019 17:55:00 -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 74A2821925; Wed, 16 Oct 2019 21:54:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571262899; bh=iy/VHMV6omP+D7+GJiS4gHZtt5audKdVEHGdn++DeGI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AGWOv+RXhs/+8XGfsr0krPbYKRE/Cpyn8J7KBk2hJRHwJGlWUjFb88HQS1Q0QHgFj ExhsicyExwxTJTMRsfh/B1PRlmUps/IGBsyHQcQOl7HbNapKS6tLUJucWmL3tZq8Zb sHyAlfoFDIKaqPDxeQBEqgfhbuioM9HWBgAIHboU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+0761012cebf7bdb38137@syzkaller.appspotmail.com, Johan Hovold Subject: [PATCH 4.9 51/92] USB: iowarrior: fix use-after-free on disconnect Date: Wed, 16 Oct 2019 14:50:24 -0700 Message-Id: <20191016214836.824956867@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214759.600329427@linuxfoundation.org> References: <20191016214759.600329427@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 edc4746f253d907d048de680a621e121517f484b upstream. A recent fix addressing a deadlock on disconnect introduced a new bug by moving the present flag out of the critical section protected by the driver-data mutex. This could lead to a racing release() freeing the driver data before disconnect() is done with it. Due to insufficient locking a related use-after-free could be triggered also before the above mentioned commit. Specifically, the driver needs to hold the driver-data mutex also while checking the opened flag at disconnect(). Fixes: c468a8aa790e ("usb: iowarrior: fix deadlock on disconnect") Fixes: 946b960d13c1 ("USB: add driver for iowarrior devices.") Cc: stable # 2.6.21 Reported-by: syzbot+0761012cebf7bdb38137@syzkaller.appspotmail.com Signed-off-by: Johan Hovold Link: https://lore.kernel.org/r/20191009104846.5925-2-johan@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/iowarrior.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/drivers/usb/misc/iowarrior.c +++ b/drivers/usb/misc/iowarrior.c @@ -886,8 +886,6 @@ static void iowarrior_disconnect(struct dev = usb_get_intfdata(interface); mutex_lock(&iowarrior_open_disc_lock); usb_set_intfdata(interface, NULL); - /* prevent device read, write and ioctl */ - dev->present = 0; minor = dev->minor; mutex_unlock(&iowarrior_open_disc_lock); @@ -898,8 +896,7 @@ static void iowarrior_disconnect(struct mutex_lock(&dev->mutex); /* prevent device read, write and ioctl */ - - mutex_unlock(&dev->mutex); + dev->present = 0; if (dev->opened) { /* There is a process that holds a filedescriptor to the device , @@ -909,8 +906,10 @@ static void iowarrior_disconnect(struct usb_kill_urb(dev->int_in_urb); wake_up_interruptible(&dev->read_wait); wake_up_interruptible(&dev->write_wait); + mutex_unlock(&dev->mutex); } else { /* no process is using the device, cleanup now */ + mutex_unlock(&dev->mutex); iowarrior_delete(dev); }