From patchwork Mon Nov 9 12:55:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 322637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE492C4741F for ; Mon, 9 Nov 2020 13:32:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7AD46206ED for ; Mon, 9 Nov 2020 13:32:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604928757; bh=6M8/Nor+vjyIdL9iwcVAhnMpVgxFsCFpmtniT6+i9Fk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=plRTdPKVROunf/5l+u97JF4qMz5VyHzt+GS1fxCsvR86dhX9Bv1ajglQzgn9YFmfs 55B93EgEdOYZh0a+B9Z0djG6PQtWK244SyLoPsdJESGv+G7h8yIr7G9dD9x0pWSs60 fKLKP4LH/KLqkQlcdZi4v7xVnZu1qbPO/NcO6ToU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731273AbgKINcg (ORCPT ); Mon, 9 Nov 2020 08:32:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:59940 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731279AbgKINHO (ORCPT ); Mon, 9 Nov 2020 08:07:14 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 EE84C20731; Mon, 9 Nov 2020 13:07:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927233; bh=6M8/Nor+vjyIdL9iwcVAhnMpVgxFsCFpmtniT6+i9Fk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K8FgLlWGSgL1uZCi65RDMIKDck/pXCU9WKaVsz+vlp3gjDUroK4rqtkCU00h+xUoO cOlayiTowjDQoVm4uWKLKVfTsrTqhE4bLn/o96CSoR7MJc014RT9V3qLBHMLB7YgSl y0uTbwpo2AMxdodEXpECNB5Q9uJnwgYgF85V3Ndk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johan Hovold Subject: [PATCH 4.14 39/48] USB: serial: cyberjack: fix write-URB completion race Date: Mon, 9 Nov 2020 13:55:48 +0100 Message-Id: <20201109125018.682376775@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125016.734107741@linuxfoundation.org> References: <20201109125016.734107741@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Johan Hovold commit 985616f0457d9f555fff417d0da56174f70cc14f upstream. The write-URB busy flag was being cleared before the completion handler was done with the URB, something which could lead to corrupt transfers due to a racing write request if the URB is resubmitted. Fixes: 507ca9bc0476 ("[PATCH] USB: add ability for usb-serial drivers to determine if their write urb is currently being used.") Cc: stable # 2.6.13 Reviewed-by: Greg Kroah-Hartman Signed-off-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/cyberjack.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/drivers/usb/serial/cyberjack.c +++ b/drivers/usb/serial/cyberjack.c @@ -358,11 +358,12 @@ static void cyberjack_write_bulk_callbac struct cyberjack_private *priv = usb_get_serial_port_data(port); struct device *dev = &port->dev; int status = urb->status; + bool resubmitted = false; - set_bit(0, &port->write_urbs_free); if (status) { dev_dbg(dev, "%s - nonzero write bulk status received: %d\n", __func__, status); + set_bit(0, &port->write_urbs_free); return; } @@ -395,6 +396,8 @@ static void cyberjack_write_bulk_callbac goto exit; } + resubmitted = true; + dev_dbg(dev, "%s - priv->wrsent=%d\n", __func__, priv->wrsent); dev_dbg(dev, "%s - priv->wrfilled=%d\n", __func__, priv->wrfilled); @@ -411,6 +414,8 @@ static void cyberjack_write_bulk_callbac exit: spin_unlock(&priv->lock); + if (!resubmitted) + set_bit(0, &port->write_urbs_free); usb_serial_port_softint(port); }