Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3207079pxb; Mon, 9 Nov 2020 05:36:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyfXFHLSqeTtdlWgRHYTJe/LddYC7it/sgUHGMWbB7J7TpgtA8cgiJ2YyrTIV0Dq9P9aBD6 X-Received: by 2002:a17:906:8553:: with SMTP id h19mr14690975ejy.316.1604928977724; Mon, 09 Nov 2020 05:36:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604928977; cv=none; d=google.com; s=arc-20160816; b=GbmEur6TcxObd8Rj4kgOclkrDrYfXKu2a8ed9sVNyZnUA7fbTaX+mS8QyFZPkrr89I 0el1+egzp9HjdMN/DwZKmZxa0sbRTU0uIB/5uxZvdiIo5CbhLioWLX6Yng+IoH1jPYxA U1ZHzMj0bs0IxbS570b7+0j/NiJhttW07PeOOpaXQY+1ixZBuVCZvNaod1IXR0as5Cj+ bYL63YqQ/FUKmAZTQ5PTlab8mwSC//yS4UvEarwDM1x2FEin5iapEs+k79uE1iqcdQVE zxmLqVwUYFdrX+77tuZWVLUrbk9nm6UpnNOuwkoLApn4eeV50N89q6WFKoiBrwi5Ovcl tSIA== 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=qGIJu2HB/7Rm6dWL/iDZn+af2ETJZI/i8ml1qhIzWlc=; b=xxR2HI/SwIg9N6oi6w/H8k2aZNpI/x4PXIx87U58ON6Cyq2ISFsO5P6UXLEIqBonxV eBl+cfQc0Px5X47CKFsSsoVh+D4PRaMXAhzrKiUrZ060/dhQB/Vk2Rhtu20LIAq+XPG5 vDE4oNc6LjQLaCEKA0FE+WgkX7Fn8p1crPhtcNiVlRZDpbV+cuqWHG31WBXNXF5PvotZ ctv4YLA79VEdKcJCo3hTpARE8GYy3pqS+12JmdiFQH4hhOmuptjBXJJs6F6NwmXcUgSI fYXFjPR+t6qxSxMoBP/yWj2wThZeljjPKxwvH8tqcGL9VDTsjt7y4ldHC91R+AKy/M1u ++wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Bky1uDcK; 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 w25si7307524edt.600.2020.11.09.05.35.54; Mon, 09 Nov 2020 05:36:17 -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=Bky1uDcK; 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 S1730789AbgKINej (ORCPT + 99 others); Mon, 9 Nov 2020 08:34:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:58534 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730915AbgKINFo (ORCPT ); Mon, 9 Nov 2020 08:05: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 BA31F20789; Mon, 9 Nov 2020 13:05:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927143; bh=Q1sRCMBXDUGCSrwBBfw2+4HfaojHiRbvZygFs4rhdBg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bky1uDcKr9gUHyQsHP9aIBG+33fnkdFe09YWH8KlHi90gWWo7K+qCl1RfnpQ6hVmP zmIeR5C+SaoTh/jh3cBs4Ra9dyOrdsMMyakOc02mmtAoPvx7+e++mvFzIzpXkfocbz 9HKUwqBRxjIWAMBj80+DwF2MXAATSQ/qDC0ApXMU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johan Hovold Subject: [PATCH 4.9 112/117] USB: serial: cyberjack: fix write-URB completion race Date: Mon, 9 Nov 2020 13:55:38 +0100 Message-Id: <20201109125031.012382267@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125025.630721781@linuxfoundation.org> References: <20201109125025.630721781@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 @@ -367,11 +367,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; } @@ -404,6 +405,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); @@ -420,6 +423,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); }