Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3194126pxb; Mon, 9 Nov 2020 05:18:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJx/VIwxK4yCUxTgWHSLrZV5WW7Q3W++Lny9UWfUPngs5PEcx/kzZqwxY3OUoEI01cMiboep X-Received: by 2002:aa7:c948:: with SMTP id h8mr14747279edt.171.1604927899751; Mon, 09 Nov 2020 05:18:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604927899; cv=none; d=google.com; s=arc-20160816; b=oJ9tP0M15wVO9ery6zt9ormcZ4nQfKCmTl0wraA/ft4N6I6I/67IkaqlQck+prXyPa kXPpu9kMBcNWtUABiHsVLlBqUCr8BNZQi8/sqQwu8wlshPGgW86bjlfQhgC/w55T7FG1 QjPkqbZCrB1fivlVqz4XyJW6oWrHrQhw7QDZWvkLRZglUmtHIlqmXUbZ1rE+vGR4OQIp nqauokLFhzgzrc5fjUFem0isE0J/1X5muWLfdeWajUWRe4vfOF48esoW0iWr2a25Pw1H Mm7IX0h4LVQlsnAXJF0jDNacU7YmAaRZxbx1oWOycnv/5+8/6KM/qaEIsHgJU+GAFS7D WjJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8+DykEB2RPaR8C/3OkeID9d9IiaPlkGyNAMaIQeDN+o=; b=bJu1si8wvB6j6KlKvOGv8DQhXiL9TvAgM6AwWdp3fmVePFMXU9/OH9KLu/pHOsrr1q CYNW+qsJoxE0fdYeU8z6vUljTM3+qz+NGBco7Ew1CO2Bm9CVhZuffSJu2rZgzlRaQeu/ Ec2YXSusFnXLX1wgVn9Q0sHePshAPC+9G/EmmLFv65dA+r2ecci+6I4fuSjZaFxCtbFW kR/N0uZPtKIbHLRCEXS4FIDusO9cxArc4iW6QZWSp3coJJiwTcFRZkhHge3Jkm8URckv pGpImTiDszOqAkbkBQm8DPKtudA8xmG4JUNbUiIbzY9rPmaH6gMKsyLR/mCKA8x97KC1 jLYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jrtsq87k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u23si7129578edv.499.2020.11.09.05.17.56; Mon, 09 Nov 2020 05:18:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jrtsq87k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733301AbgKINPs (ORCPT + 99 others); Mon, 9 Nov 2020 08:15:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:42590 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732122AbgKINPo (ORCPT ); Mon, 9 Nov 2020 08:15:44 -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 21ABD20789; Mon, 9 Nov 2020 13:15:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927743; bh=hsC/FcjwnIkkaHCSmTzFKRF6otCFQ+C6OZJCYFpWabQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jrtsq87km43MeerV/rP8YQ6FeJMaLHstJgRr+xv3CMmhqBl6M6iy4npvGg0K8Cl9Y FDdX/MeAOhYwia71KW9ZMGwzBpTgPlSTuD/sdyBpCHGvqzMHHiZH+ajY40f7MiCupR dnBG/GXYHXNK4q+A/6w/OklJCiXPuhmv0g/H4t3c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johan Hovold Subject: [PATCH 5.4 69/85] USB: serial: cyberjack: fix write-URB completion race Date: Mon, 9 Nov 2020 13:56:06 +0100 Message-Id: <20201109125025.886751519@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125022.614792961@linuxfoundation.org> References: <20201109125022.614792961@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 @@ -357,11 +357,12 @@ static void cyberjack_write_bulk_callbac 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_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); @@ -410,6 +413,8 @@ static void cyberjack_write_bulk_callbac exit: spin_unlock_irqrestore(&priv->lock, flags); + if (!resubmitted) + set_bit(0, &port->write_urbs_free); usb_serial_port_softint(port); }