Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2921670ybg; Mon, 28 Oct 2019 04:41:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqzChCkYkaoXqZdvvdIWCeFaQutA/dOw4QNkyFkeZonoscNnRX+JUKUl2WSxRq8/Buy/8Upn X-Received: by 2002:a05:6402:60c:: with SMTP id n12mr8423019edv.242.1572262882320; Mon, 28 Oct 2019 04:41:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572262882; cv=none; d=google.com; s=arc-20160816; b=YuS3+MYD7fQGV4pvLXmp2aomJUOF65XM/dsZXSAfcgPzf7ifaDJrdlJOJu4NXyqWBL vaLgKKuXSaNsKk4Ucb8lzmBpnuf/xyZvfRCvXKubO95d0iX5+ShH9HDSa9i8pkgLoJNu Gzwgebsu1wGdnt491ShMFiM8v172B7S9l+hBSbcw3Dw6xHDQbVfQHptySAF9sMaKaADH z2ZQY0MCu3VNEA50L9bFnTEads+1tcepWpMkI2OHwwAbrrV0owG9w6+GqBPGLwhgEHUU ey33tGu2mpkifDuP2GiUHNJi9+O5eKPJUpZQWIO6eZUFWqNSdCTBZaoDJKvUQR4qj7R2 LN8A== 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=12ovB3EMm0bUitzsaxBGpRjXT59YMroA2iYL9Ng4VVc=; b=AOlOhcvauHT28/wnVk8O2SvZDA4FkVUidMxzHakO/YZe2ZmIN7yfbtxSmqLm2RRF3S 4CoM1aHR6wVjbnPNJMD94UBzu8gb2xIhc1T1QPsxeqioNzlEwYiHxAotLo7iAhUmOmo3 KevXcp7Gv2RNsaGotxrk4nPbKw1YVjOGRAWPwijSmEqjtLMQGF1EZo5yP4m9y++qogPw ckWCi7oY4C1ZTQxVQLWpbMNVQZhFMQW/Rm1cJ0YkdH/4hvSYzfWZO2PHwasoaOMbg5bw 0+mfVgdhv24B5erB2FCyZ0SRLsispLr0SVcilCt0VgftfY4jd4d/pMVAJg5u2XcVnlwa 9Dhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=S5Q5hBXD; 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 l23si1019108edc.185.2019.10.28.04.40.58; Mon, 28 Oct 2019 04:41:22 -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=S5Q5hBXD; 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 S1729851AbfJ0VhX (ORCPT + 99 others); Sun, 27 Oct 2019 17:37:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:51254 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728826AbfJ0VF1 (ORCPT ); Sun, 27 Oct 2019 17:05:27 -0400 Received: from localhost (100.50.158.77.rev.sfr.net [77.158.50.100]) (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 1C256208C0; Sun, 27 Oct 2019 21:05:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572210326; bh=jaFWRWvDjERps60GVLlTLwEplN6HE8jKwC+u84gwQCo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S5Q5hBXDSPdrK9yZGmDqNVuHZdlzLUIeLh3Ggp1HXWqtH0FHipObs4B43N2f08FXp 2+4LuvGRShhNlWrklpXUUZDf3c6w8XhchvyXnBtCSyCutGqQCiaCi3iAv2wuiXt2Mm ZEsgov/8DNIE5TwMTLRoEMU8x5Dnlq+Qn58kLt5o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johan Hovold Subject: [PATCH 4.9 26/49] USB: serial: ti_usb_3410_5052: fix port-close races Date: Sun, 27 Oct 2019 22:01:04 +0100 Message-Id: <20191027203139.262412564@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203119.468466356@linuxfoundation.org> References: <20191027203119.468466356@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 6f1d1dc8d540a9aa6e39b9cb86d3a67bbc1c8d8d upstream. Fix races between closing a port and opening or closing another port on the same device which could lead to a failure to start or stop the shared interrupt URB. The latter could potentially cause a use-after-free or worse in the completion handler on driver unbind. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable Signed-off-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/ti_usb_3410_5052.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) --- a/drivers/usb/serial/ti_usb_3410_5052.c +++ b/drivers/usb/serial/ti_usb_3410_5052.c @@ -778,7 +778,6 @@ static void ti_close(struct usb_serial_p struct ti_port *tport; int port_number; int status; - int do_unlock; unsigned long flags; tdev = usb_get_serial_data(port->serial); @@ -802,16 +801,13 @@ static void ti_close(struct usb_serial_p "%s - cannot send close port command, %d\n" , __func__, status); - /* if mutex_lock is interrupted, continue anyway */ - do_unlock = !mutex_lock_interruptible(&tdev->td_open_close_lock); + mutex_lock(&tdev->td_open_close_lock); --tport->tp_tdev->td_open_port_count; - if (tport->tp_tdev->td_open_port_count <= 0) { + if (tport->tp_tdev->td_open_port_count == 0) { /* last port is closed, shut down interrupt urb */ usb_kill_urb(port->serial->port[0]->interrupt_in_urb); - tport->tp_tdev->td_open_port_count = 0; } - if (do_unlock) - mutex_unlock(&tdev->td_open_close_lock); + mutex_unlock(&tdev->td_open_close_lock); }