Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1355252ybp; Thu, 17 Oct 2019 11:31:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqzE66HGGUJVJEoBRcat/DalsmqFXG/h3B85wDqWESkS6gKcfebj4yjzY1xXXOAGCKrS2b+s X-Received: by 2002:a50:b5e3:: with SMTP id a90mr5190585ede.201.1571337102419; Thu, 17 Oct 2019 11:31:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571337102; cv=none; d=google.com; s=arc-20160816; b=h9Vtsd/UIn+4NgX49NnVypx0uCqkUzTpv1ky/fitwYO+k8xDQWvrTEniWepLfea6EV 7DK00spG6kpwWqAh7zcUb7KWxZGO0Zq8wN+cSxpl/fdKyoVY7UH4kyPZCbnr1Wl2cHAD EBlQO2Fd5fCtVA7KV4YyRZXyiXo3ZnkLd4FRYVte1oVOr0ytbFGTgiVQ+VI2sYxOa6aF 5vU0t5fEjzJkN/AjlhTDTc+Q1yCBJLFRb++bbTVYECqs/DBQM3zNnTvovslXyg/ntiLI s50iYGpNYS4IBIWDDFuHIANMgTitkCrpCvQwL5ei1GdAe6v+mNtFWFI4EY881yp7RGiy 3sIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OKvyH3N1VC65ya5QcObHDVPM/oD483Cg04hEIUILcGA=; b=RxDHwtiXZuJpcKnICF0EyCWrRPqzBRCVgteNZmB/PPDqYgATFgkB6VlRH+BdLhC2gv Pmi2EHuMriMuQpd8QSeN0FDC9oTM+fl5ea52H7WUspkMAiyKNdadpe4/jZn7HY81MnyZ hGJkJpht76MDFnIPFadPtxth7uePeXMa+QuzMPlOtoVXqd54WAPsXFyrNMFZ2wfSdBp6 FxtkVWTYDzpieR+IjpJ8PWDiQk7XmCyVrX+PASu4RAxVpIAa+py7JIAEXbbYDvody4IC O6uF/uqENYkkUP6ham0pJmYZroxLPndE6EJldXPyP4V0DwCqQUKKRFzNmCAoUMm3Lveu HKUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kr5pdc+o; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z14si1869414ejw.396.2019.10.17.11.31.18; Thu, 17 Oct 2019 11:31:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kr5pdc+o; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404813AbfJPWHB (ORCPT + 99 others); Wed, 16 Oct 2019 18:07:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:51796 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438128AbfJPV6T (ORCPT ); Wed, 16 Oct 2019 17:58:19 -0400 Received: from localhost (unknown [192.55.54.58]) (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 E001D21928; Wed, 16 Oct 2019 21:58:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571263099; bh=nDFW/KXTTRLxhK+S/6xxs6fJH57zdvFinbc4C0dY+u8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kr5pdc+oBaa3sQ1dKjGZ4ecSYFkkF7GfQqZeeCLCHbrVbHDsoypj6MAXobJ+PZcH8 1zF6okPkA/CJfIBWrr7tAoqFVGtQ/6KUHPK+Osal/YtN0Q1VF0kUlw1zkYByTDFva7 n8PkD0LOq6FUhMIV0Gqm4l4HCePlfxEsegvPruMU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johan Hovold Subject: [PATCH 5.3 020/112] USB: iowarrior: fix use-after-free after driver unbind Date: Wed, 16 Oct 2019 14:50:12 -0700 Message-Id: <20191016214849.604722565@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214844.038848564@linuxfoundation.org> References: <20191016214844.038848564@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johan Hovold commit b5f8d46867ca233d773408ffbe691a8062ed718f upstream. Make sure to stop also the asynchronous write URBs on disconnect() to avoid use-after-free in the completion handler after driver unbind. Fixes: 946b960d13c1 ("USB: add driver for iowarrior devices.") Cc: stable # 2.6.21: 51a2f077c44e ("USB: introduce usb_anchor") Signed-off-by: Johan Hovold Link: https://lore.kernel.org/r/20191009104846.5925-4-johan@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/iowarrior.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/usb/misc/iowarrior.c +++ b/drivers/usb/misc/iowarrior.c @@ -87,6 +87,7 @@ struct iowarrior { char chip_serial[9]; /* the serial number string of the chip connected */ int report_size; /* number of bytes in a report */ u16 product_id; + struct usb_anchor submitted; }; /*--------------*/ @@ -425,11 +426,13 @@ static ssize_t iowarrior_write(struct fi retval = -EFAULT; goto error; } + usb_anchor_urb(int_out_urb, &dev->submitted); retval = usb_submit_urb(int_out_urb, GFP_KERNEL); if (retval) { dev_dbg(&dev->interface->dev, "submit error %d for urb nr.%d\n", retval, atomic_read(&dev->write_busy)); + usb_unanchor_urb(int_out_urb); goto error; } /* submit was ok */ @@ -770,6 +773,8 @@ static int iowarrior_probe(struct usb_in iface_desc = interface->cur_altsetting; dev->product_id = le16_to_cpu(udev->descriptor.idProduct); + init_usb_anchor(&dev->submitted); + res = usb_find_last_int_in_endpoint(iface_desc, &dev->int_in_endpoint); if (res) { dev_err(&interface->dev, "no interrupt-in endpoint found\n"); @@ -885,6 +890,7 @@ static void iowarrior_disconnect(struct Deleting the device is postponed until close() was called. */ usb_kill_urb(dev->int_in_urb); + usb_kill_anchored_urbs(&dev->submitted); wake_up_interruptible(&dev->read_wait); wake_up_interruptible(&dev->write_wait); mutex_unlock(&dev->mutex);