Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2252064ybg; Sun, 27 Oct 2019 14:25:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqz29r+fkWrxL9+1TnNjC2QZsEpW6FhCcAUx6QOSkfJjpdu37dCc1yb23mvPcEzdw3qUWkX9 X-Received: by 2002:aa7:d305:: with SMTP id p5mr16520827edq.80.1572211532100; Sun, 27 Oct 2019 14:25:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572211532; cv=none; d=google.com; s=arc-20160816; b=EG6EJqvcutgqRYX/e36GKHJhiYZmwbu/LiFrM2C0UWdpDiiA4lup1X9cT1CEBW5EiZ TpfRTqxIZw0hXCTQv/GxVq3mS5Pujknx+5sVxP8+EC1nvv8MBwllLsT7AD4juB7oAtSg JepvWz03ICgDlJsUT9wO2j7tHC8e2z4b36zXwwSYfe/CYF+n4QTtrXiYQfoAvPWv87i1 9RNpTCarhfCz3IrNXPI+y96Tg+N+mFEeihJ0TjFS5PvfScziRffxw0q+cOIma14+XOBh xN7v4e1mJEqz3amByTrpiDiuUT6kdNgiuqwpbtpz/IyKkHSr/8/L+708O0FoiaProuPM skgg== 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=wRoA6bI4GCC/ogioU2Z9qmXiDF1a3363tU2i3NPM3Ck=; b=A7Mwej0/19e6OkDD9D144FzEqkTb6i43vux6qjxYPQlcK48zvim2CTPEQhj/DQbczD R/qUYouN1Z5KfK5R6WjNA3AGdl+mdZKJ8pvT+qyCkqWdeQapS8B2ihWDU9QcRDr1ZHB2 Ywb4y/9wN1+INH/6t7l8SEMEP4wIHSzH946p3POFx6QAdCh/ks0vUEO8ZYYxM+poWOr0 kIl4J6jihNiKhqSer53ukwQGL7GxX/fLnTLkDF99FP+cNnrEBrWKvdXggcvbEg1pzuy6 2fHgVXL5lbvwGv06WfC2WVvpM7S6A+5Rido9psNCfYs2fzHsZosGRzo+pVMNWHJGI3DM xL7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jwsngnim; 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 k20si6761615edj.55.2019.10.27.14.25.08; Sun, 27 Oct 2019 14:25:32 -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=jwsngnim; 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 S1731965AbfJ0VVh (ORCPT + 99 others); Sun, 27 Oct 2019 17:21:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:42498 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731938AbfJ0VVg (ORCPT ); Sun, 27 Oct 2019 17:21:36 -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 398CD205C9; Sun, 27 Oct 2019 21:21:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572211295; bh=snwh3EKd/53QyFR5k10t0nDsAEQGi5MWIG+F2BMIzEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jwsngnimpoqV3Msu/DDMWAjQ6eIg6GZZlv2A97GXWhH9x8Rr6g63d0JVif5pj5dLL 1PabZPCNpQbxer6XV5Mjq1nHoR3FJl7Z6mf/UtXb7Zb3rS9POskVsmEYs2JhFo4aWx VRyoTbytlUOxiDAzEW1JDrbeeDvgGk/7CSvPKV7c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johan Hovold Subject: [PATCH 5.3 102/197] USB: serial: ti_usb_3410_5052: fix port-close races Date: Sun, 27 Oct 2019 22:00:20 +0100 Message-Id: <20191027203357.273938582@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203351.684916567@linuxfoundation.org> References: <20191027203351.684916567@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 @@ -776,7 +776,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); @@ -800,16 +799,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); }