From patchwork Fri Oct 11 09:57:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11185163 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D4FF112B for ; Fri, 11 Oct 2019 09:57:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3EAD321D7D for ; Fri, 11 Oct 2019 09:57:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570787858; bh=yx8ifwUZYZq1RLAsZeiK/FKVlrZb4VgkRKBgiv3F5XI=; h=From:To:Cc:Subject:Date:List-ID:From; b=FAiJ/KROAGE1eeeuLk8c1bvF8I6QriAYsY/lcSaCeeeaSYrA4i0lDQBNZcML9jkcl wvyylc+zpfIQ4gwWGClzQfuvxQLcpgX7/uiSu3rf/8NjVrkSp6SuekBNu8s6mosl/2 oxl/O7Eg297oDp/nTQRIDYwCPbeP1/VNg9rq6uaQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727860AbfJKJ5h (ORCPT ); Fri, 11 Oct 2019 05:57:37 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:32800 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727314AbfJKJ5h (ORCPT ); Fri, 11 Oct 2019 05:57:37 -0400 Received: by mail-lj1-f193.google.com with SMTP id a22so9238770ljd.0; Fri, 11 Oct 2019 02:57:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=dH0s3WOPr05pqAHfLs+B1HY8TrR6zssGtSYDR0ZvkL0=; b=gCiljLRnbrWCrLQebDE8g1w1pIjZFfLf93TIo6XBDSUcmBcLysOQuQSEtPXW1gGOkQ MdQiWgsBxPdMm+9eceQ4/fvU/C5CWT5qD9aE+TuZ8YEbzzlc/G9Dt9YFXnPFCUYNlHb7 wkpgqa+WtS7f/xVCCcfRGkbf60JEk9r/ebA+kCvuG02t9l67h+jTJY6tgLdMeOjuerx6 /tUBsp0FBSdxzsM9BZe/lSCf1eKQNbCN3H7LSVmeoSTPmW4aTviMgxhRXTR9lJe7WTUg Fz3bsmj4LXnr2tQWX/TO9QSy/LuEoYMja2/QkWbjoUzmj8aFiw1BFXPhWgysiwy4WYCi 6NvQ== X-Gm-Message-State: APjAAAWwnEhZPPFlJLbqUKPFmA4jmv6SDWAycQLXTGSnri/XUM2ckrmH ZzzeQPBlW3RXQVkxQNRil5HQSaPw X-Google-Smtp-Source: APXvYqwa6hs09EiixUNhumSPAMCltdoyS47Wf0Dp+SR+kJixHm5WjHO+wNImZ8ovThi8kQRU8wByBg== X-Received: by 2002:a2e:658f:: with SMTP id e15mr8914409ljf.254.1570787854372; Fri, 11 Oct 2019 02:57:34 -0700 (PDT) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id z14sm1867142lfh.30.2019.10.11.02.57.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Oct 2019 02:57:33 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.92.2) (envelope-from ) id 1iIrg7-0005iW-B2; Fri, 11 Oct 2019 11:57:44 +0200 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Greg Kroah-Hartman , Johan Hovold , stable Subject: [PATCH 1/2] USB: serial: ti_usb_3410_5052: fix port-close races Date: Fri, 11 Oct 2019 11:57:35 +0200 Message-Id: <20191011095736.21934-1-johan@kernel.org> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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 --- drivers/usb/serial/ti_usb_3410_5052.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c index dd0ad67aa71e..9174ba2e06da 100644 --- 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_port *port) 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_port *port) "%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); } From patchwork Fri Oct 11 09:57:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11185165 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E2A41709 for ; Fri, 11 Oct 2019 09:57:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 65D9021D7D for ; Fri, 11 Oct 2019 09:57:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570787858; bh=1But3RogdAWh2rm1p+4HlSr5KWA38uzCfjsMTa0nyrM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=BnusiRrkpYfSnRzyHzvAQBGumSm5MzcXr9OhcS16RQDr+XJwGBDRgn1zVtCJAS/ca ZMbeWHhY6ai8lClMXobdE28iCSgiUweahWge49Bl1a4F8098yLC/acHabI2y01nEMm /WBdAU1WCsDUbBuG+zhlZwmtG2yrEI8785MC7COM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727865AbfJKJ5h (ORCPT ); Fri, 11 Oct 2019 05:57:37 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:46089 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727628AbfJKJ5h (ORCPT ); Fri, 11 Oct 2019 05:57:37 -0400 Received: by mail-lf1-f65.google.com with SMTP id t8so6562509lfc.13 for ; Fri, 11 Oct 2019 02:57:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0K5HwfEj/jodL29/ZVixU945Hf1+hbADNv7D78KDiHA=; b=meEPIPc/dggYkRWkSIm5oKqniBK1i6gYG6KHhUwflO/T+0DCdZ+80JPdbSnv/XPwk8 mco9A5Xzwj/HGxg5FMIqLXJXeawA3SloAtVdTiJQaEq0M5EAUfUVZY/Jx19F1JuXVChO mUb1Tjau37ctGZl5ZOhuwy00USAsPpye5ZzQnHLE29LzricgV1icTFiXdiyZiqAiOlXe /6FF9Qfl4w5Wgww7Dlnf4u8YmEFzFcgCyJvRIVQdu8GAUb80/pais4gQrfiX2MydO6UF PB6ZZKaDBsNBgmzHW/r4nJxWXYqqsu9AQPt5yeQSarAFOB/i9qlwr86Ww/xtwVhNh+9z p0tg== X-Gm-Message-State: APjAAAUSR6yZsWKctJhdbh0o4o0pIgMAQyOT2EfSUlJ92tfJSr9myMSz eLuYXcQUyf7or7qeLXIYileyP9Kt X-Google-Smtp-Source: APXvYqzavRrUf9eVYpnMnuDANF8KNxNyEy/ZL6Rmqn8bG+JAZuPSGw9qQea9c3iQzL3+Bnuc+V4i6A== X-Received: by 2002:a19:7404:: with SMTP id v4mr3398299lfe.129.1570787854975; Fri, 11 Oct 2019 02:57:34 -0700 (PDT) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id r6sm1865761lfn.29.2019.10.11.02.57.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Oct 2019 02:57:34 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.92.2) (envelope-from ) id 1iIrg8-0005iZ-5L; Fri, 11 Oct 2019 11:57:44 +0200 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Greg Kroah-Hartman , Johan Hovold Subject: [PATCH 2/2] USB: serial: ti_usb_3410_5052: clean up serial data access Date: Fri, 11 Oct 2019 11:57:36 +0200 Message-Id: <20191011095736.21934-2-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191011095736.21934-1-johan@kernel.org> References: <20191011095736.21934-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use the tdev pointer directly instead of going through the port data when accessing the serial data in open(). Signed-off-by: Johan Hovold --- drivers/usb/serial/ti_usb_3410_5052.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c index 9174ba2e06da..ef23acc9b9ce 100644 --- a/drivers/usb/serial/ti_usb_3410_5052.c +++ b/drivers/usb/serial/ti_usb_3410_5052.c @@ -800,8 +800,8 @@ static void ti_close(struct usb_serial_port *port) , __func__, status); mutex_lock(&tdev->td_open_close_lock); - --tport->tp_tdev->td_open_port_count; - if (tport->tp_tdev->td_open_port_count == 0) { + --tdev->td_open_port_count; + if (tdev->td_open_port_count == 0) { /* last port is closed, shut down interrupt urb */ usb_kill_urb(port->serial->port[0]->interrupt_in_urb); }