From patchwork Mon Oct 26 08:25:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 290214 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=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,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 683B2C2D0A3 for ; Mon, 26 Oct 2020 08:26:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 07939223FD for ; Mon, 26 Oct 2020 08:26:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603700766; bh=IDnPApR9xiBc/DAx4wsSxvO92uDVNx/gaDt4+0p6xy4=; h=From:To:Cc:Subject:Date:List-ID:From; b=aL1kBHC2Dg775KpmcjLiZWzqSbn4nJRX2lamdk4JwYzuNE1diwCMcy/Tl9xMtEwLT OSLXO/VQmkVO/F0XkJGuP4Jp59r6Fzk6Z8yV0yB43Cy48eJRkVwcPzT3bpyJV4f4Eq wqN0pQCXBWoKmEjpfb0sIzulnqgrCcVH6N7dokrk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728857AbgJZI0F (ORCPT ); Mon, 26 Oct 2020 04:26:05 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:38147 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1771667AbgJZI0F (ORCPT ); Mon, 26 Oct 2020 04:26:05 -0400 Received: by mail-lf1-f67.google.com with SMTP id c141so10628910lfg.5; Mon, 26 Oct 2020 01:26:03 -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=V+jakLBrl9A0QRy0ACCLn+POIM4wvTqpKbwiPWwLh/Q=; b=Dfikz2Q0gQx/n0L8u50e80xHJ1DI4lfCNXsOAbOuz6yJ04Cf5zKJ/7CfGt+WX7XlMr gCuJtnywsCz9+kdI8u/ihdefmdl9nK2yRbMlqkD9hKAQN6S+mKaYtUO3AE5zSVGc1wEf /ddHLEQxzmtSKXoNz3pLBk6mZb71Bd0CgqYYomxOs/BSxlrLNBmJnBU2UY1NscWr8wO5 Yx66TV3RotU+Gs1rH4TsC6yYDCGcbENydL8BZprAFonxHu4SynlKg7VMID/1xmpNN5nJ 489fEo5PCpVFztYGEUNf/ukpLQol/xfxgt2TrCNkIXY+oRd6k4koXcJX63xluIff8wxp 2Qpw== X-Gm-Message-State: AOAM533ftT0m+FfrZiFQR222D71Ao9jsUxu8CzSlfvTSlW+FfzEcxgmZ O9j6Wi0jgn+vEFfVcqlwUrJmisY5Y8oXWg== X-Google-Smtp-Source: ABdhPJyQ2uJccQ59KpQO+0fxZT6r2bgdyJeamwvsQXPtm53K89Gp7AGJVz29970BpKGYASjAYjZKuA== X-Received: by 2002:a19:8884:: with SMTP id k126mr5009463lfd.63.1603700762566; Mon, 26 Oct 2020 01:26:02 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id w18sm967685lfc.5.2020.10.26.01.26.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 01:26:01 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kWxpO-0004gc-Uf; Mon, 26 Oct 2020 09:26:07 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Johan Hovold , stable Subject: [PATCH] USB: serial: cyberjack: fix write-URB completion race Date: Mon, 26 Oct 2020 09:25:48 +0100 Message-Id: <20201026082548.17970-1-johan@kernel.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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 Signed-off-by: Johan Hovold Reviewed-by: Greg Kroah-Hartman --- drivers/usb/serial/cyberjack.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c index 821970609695..2e40908963da 100644 --- a/drivers/usb/serial/cyberjack.c +++ b/drivers/usb/serial/cyberjack.c @@ -357,11 +357,12 @@ static void cyberjack_write_bulk_callback(struct urb *urb) struct device *dev = &port->dev; int status = urb->status; unsigned long flags; + 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; } @@ -394,6 +395,8 @@ static void cyberjack_write_bulk_callback(struct urb *urb) 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); @@ -410,6 +413,8 @@ static void cyberjack_write_bulk_callback(struct urb *urb) exit: spin_unlock_irqrestore(&priv->lock, flags); + if (!resubmitted) + set_bit(0, &port->write_urbs_free); usb_serial_port_softint(port); }