Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1051102ybp; Thu, 17 Oct 2019 07:22:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqxhvca4eFgx3V9Hq5g/ErK7EP4//EUNcuCXQfGbyyX1mOWKzSrZ079sYJi8AgDYL5KFroMI X-Received: by 2002:a17:906:b2d3:: with SMTP id cf19mr3755265ejb.118.1571322135763; Thu, 17 Oct 2019 07:22:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571322135; cv=none; d=google.com; s=arc-20160816; b=MM2Vzu9N9qHYNg8raIs6ZczQPeFEGUkyIBE+Bceul6NWGVy6HCcwv+JHzzAqoXDkNB evHaYelE/mxOlVEYfWKIPdM5B4NzMbYVSrHD0z0WicDXD/YGuz7LhBMAR60V/+0ZRuCV 8p8aiauMFwafal16WhmXCPrs0qDs9XBk1wpmPLzADXkbRCetiGAa63OY1hStysJDPfYd 32c4IpiFJgVHq1EaY1E2qkb/0DsgB4j3OrPwU4WLfotqsntxAugf4ADCcHR7JLJ5eWOz +xSLUfUqFJOSAdLjNU9yA8NjRWQDRrbVbahpQARn6fnusqEWrjbV2xqa2rvWNyH/UYAa ymrA== 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=4Y2RAw9fVTP50PJm8vS3N0Q2xBBBTDpFuvjyi/j3AFQ=; b=ZxGWoH2ZdUXv/IjoQCPBQFX8DSf8AmdhRdpGmcQMoJndeVAJ9p+E67TRqKHa2QASIX /LfneubdyX4y8YU7P3+NIpMgmdDmpnqCAHubSp2hJTYBIAVFdYHEPl9q6y+a148I6znF DkwhtUqnX9d6WVZAdnQ1bzAXqMk6xpD9JtgXdy9wT1YgoYv6vTz05onrmZhfMEa5QAfT jfcFHvuqMknZ9Rr94wnebmDTiwDJOAdac97NZBdWBaJ2bZl0yuMWKPc3zGtx8iYct0/M jIEIkfYYUSdW4M4k6mpLVA/WrSh7tEvTIImzvJ6h6qRmXxwJDZa7ibDM/f8jx4nIf2Ld +ZMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Q2xPGQv7; 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 r10si1645244edh.358.2019.10.17.07.21.53; Thu, 17 Oct 2019 07:22:15 -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=Q2xPGQv7; 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 S2437742AbfJPVzP (ORCPT + 99 others); Wed, 16 Oct 2019 17:55:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:45534 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395195AbfJPVzJ (ORCPT ); Wed, 16 Oct 2019 17:55:09 -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 CD0AA21925; Wed, 16 Oct 2019 21:55:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571262909; bh=0rVRR0CbBTVHtEv8LVBhHuawCNnGDu3ml+NkzVi1Ro8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q2xPGQv73SIIzVQYJt3D633IaF95NDj5yrFMqOQLpGZThZySHS+h4RTQf/iC/cD9M I0XTd4cfLc6sYSx1gccqQjGirN5vJReXy2p4xPLJSfNnGK6TkXx1aZ8ksKOHUrKP25 1ZWqapCw28JAdg49WaC+DhDPO2ivK3TzsG3wUhRg= 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.9 69/92] USB: legousbtower: fix deadlock on disconnect Date: Wed, 16 Oct 2019 14:50:42 -0700 Message-Id: <20191016214843.701774402@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 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; } @@ -932,7 +921,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; @@ -964,16 +952,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) {