Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp235162ybg; Thu, 17 Oct 2019 22:06:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqzMwiIjymRk8f8YPG4kd2RiMCwhFkEFPJOfmeR3I5MPemZtMvX2QE6fd/DGFzEbON8QlPlr X-Received: by 2002:a17:906:181b:: with SMTP id v27mr7121786eje.117.1571375194634; Thu, 17 Oct 2019 22:06:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571375194; cv=none; d=google.com; s=arc-20160816; b=AJ/ONkIVPxwxaG9XarUlex7ARo+1WlhvMBh92s8OTe3LjZHBP4rgSflclPw2cbH2+5 6skSPp9Yqhq6oVLdTGAmqouxFve0z10VicFpDiYVtf6LkxkZ7XAdeZrEwmauJ6xWHPuI SBtzs8LM3J16SpJNy8wGFy3gpLXFnN3kYjLon9V7yeCwOWTQjsLwLi7oERwqd3R7Q+ki w4qtmjJhDdkMM/t99whcuFmyV76OUZQFLgEu+o8ca2E3uNhGdeUes+A76Bc33kBZibBq iaUUZoPpxsmb7h/5ZcAQEDGFYSAeb8EqLcPaimqnar199azez48sG0pq+wJv+O4006af g5Mg== 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=PcME+zmLXs9sopTn0DIoD2kxO/o/x7t85vLzZNhgCdc=; b=YwWAipYpvNuBujHzWMMuxsBVU+r4Erd1TjWh6I/AIut/K/RorXuejhygft4ef6y6Aq 8Q7EhD8fj7s7vEHCYgU5XnIxSg/zVyurpqyOaoAnqOOG8N4JTvPMUCipukR2Nkexz4EE H3Y8pTDicwaK7ZtKQ4HlbhnbKidxZMZm+dq7MOTqI3rxOsXuBgUe1CoyU/1cG+veaysU 1bsZ+vrt8qDztAmDUWRvpjYP6btg4u5YCkHDP6kItRw1FKco6X9i9VqqHv060uvCXBo4 P4JUyXo0o+6/acGNfzqbF0W86STwlpXB/u2tL0Trh7EbQibrnxW7GgCocQwXgEdH7k48 RkBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cgWsxYPV; 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 o32si3265723edb.63.2019.10.17.22.06.11; Thu, 17 Oct 2019 22:06:34 -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=cgWsxYPV; 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 S2407551AbfJPWVM (ORCPT + 99 others); Wed, 16 Oct 2019 18:21:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:42684 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437558AbfJPVxi (ORCPT ); Wed, 16 Oct 2019 17:53:38 -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 C5E6121925; Wed, 16 Oct 2019 21:53:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571262818; bh=eOzkQT98W/IYT6PiIG82ruPFZC0IMUbth5LIzdiklUE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cgWsxYPVNTvD9c3PqMfad/ObtuuvC5bKRAhnTWVFF+UEXp8sqIJxQcqUx1fcxxEWU F4oAEfWNnQ9ROnbKvUIhOJlgNK5gS7YD6qH6tSGG+tBCAuA8uUJOW9XNhRpClk4SYU t4YXgQc8FvGEUxnRVol9a5vigxxXsw7CILfKqrCE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+f9549f5ee8a5416f0b95@syzkaller.appspotmail.com, Johan Hovold Subject: [PATCH 4.4 60/79] USB: legousbtower: fix deadlock on disconnect Date: Wed, 16 Oct 2019 14:50:35 -0700 Message-Id: <20191016214822.646985725@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 33a7813219f208f4952ece60ee255fd983272dec upstream. Fix a potential deadlock if disconnect races with open. Since commit d4ead16f50f9 ("USB: prevent char device open/deregister race") core holds an rw-semaphore while open is called and when releasing the minor number during deregistration. This can lead to an ABBA deadlock if a driver takes a lock in open which it also holds during deregistration. This effectively reverts commit 78663ecc344b ("USB: disconnect open race in legousbtower") which needlessly introduced this issue after a generic fix for this race had been added to core by commit d4ead16f50f9 ("USB: prevent char device open/deregister race"). Fixes: 78663ecc344b ("USB: disconnect open race in legousbtower") Cc: stable # 2.6.24 Reported-by: syzbot+f9549f5ee8a5416f0b95@syzkaller.appspotmail.com Tested-by: syzbot+f9549f5ee8a5416f0b95@syzkaller.appspotmail.com Signed-off-by: Johan Hovold Link: https://lore.kernel.org/r/20190919083039.30898-3-johan@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/legousbtower.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) --- a/drivers/usb/misc/legousbtower.c +++ b/drivers/usb/misc/legousbtower.c @@ -185,7 +185,6 @@ static const struct usb_device_id tower_ }; MODULE_DEVICE_TABLE (usb, tower_table); -static DEFINE_MUTEX(open_disc_mutex); #define LEGO_USB_TOWER_MINOR_BASE 160 @@ -338,18 +337,14 @@ static int tower_open (struct inode *ino goto exit; } - mutex_lock(&open_disc_mutex); dev = usb_get_intfdata(interface); - if (!dev) { - mutex_unlock(&open_disc_mutex); retval = -ENODEV; goto exit; } /* lock this device */ if (mutex_lock_interruptible(&dev->lock)) { - mutex_unlock(&open_disc_mutex); retval = -ERESTARTSYS; goto exit; } @@ -357,12 +352,10 @@ static int tower_open (struct inode *ino /* allow opening only once */ if (dev->open_count) { - mutex_unlock(&open_disc_mutex); retval = -EBUSY; goto unlock_exit; } dev->open_count = 1; - mutex_unlock(&open_disc_mutex); /* reset the tower */ result = usb_control_msg (dev->udev, @@ -429,10 +422,9 @@ static int tower_release (struct inode * if (dev == NULL) { retval = -ENODEV; - goto exit_nolock; + goto exit; } - mutex_lock(&open_disc_mutex); if (mutex_lock_interruptible(&dev->lock)) { retval = -ERESTARTSYS; goto exit; @@ -462,10 +454,7 @@ static int tower_release (struct inode * unlock_exit: mutex_unlock(&dev->lock); - exit: - mutex_unlock(&open_disc_mutex); -exit_nolock: return retval; } @@ -944,7 +933,6 @@ static int tower_probe (struct usb_inter if (retval) { /* something prevented us from registering this driver */ dev_err(idev, "Not able to get a minor for this device.\n"); - usb_set_intfdata (interface, NULL); goto error; } dev->minor = interface->minor; @@ -976,16 +964,13 @@ static void tower_disconnect (struct usb int minor; dev = usb_get_intfdata (interface); - mutex_lock(&open_disc_mutex); - usb_set_intfdata (interface, NULL); minor = dev->minor; - /* give back our minor */ + /* give back our minor and prevent further open() */ usb_deregister_dev (interface, &tower_class); mutex_lock(&dev->lock); - mutex_unlock(&open_disc_mutex); /* if the device is not opened, then we clean up right now */ if (!dev->open_count) {