Received: by 10.223.185.116 with SMTP id b49csp818016wrg; Sat, 10 Feb 2018 21:04:38 -0800 (PST) X-Google-Smtp-Source: AH8x224anWp4s1Tg8wsFmxQHmgtltwAZqyKLxfVg7ZqgHLF1NpZ6DUY3OXx8nPkVvPgwMY0ZG/KX X-Received: by 10.101.96.14 with SMTP id m14mr6470893pgu.118.1518325478007; Sat, 10 Feb 2018 21:04:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518325477; cv=none; d=google.com; s=arc-20160816; b=Y1c9agkVd9sJp/Hf7m40JUF/B5Vdj3d/IcsWgECAQ/05BeSHkiIsmWkcrOQyFqtNJn nAfHpuxNJjrQGSbAnCl6Vh2DlkMPG7QjdytbVGmW/AYPweW6yyGEPz+bL8YBOxQttuhN A3P73XrqfUfZDWC6O+GTLmZLOiXd31/T7qOvXKlpSu9k6Rtiu7HXsux44VzYB4EcMVut g3h2JjRKxiE60N8G2jimix7H5N8q2SwLeltQMOHQidqSTuLlae5WcfakD7EQgJhr6I0B NxR9PYbZHm6EGG422gc+efx6ofZzh1cFYJF1BRFT+c0SAYPBfqGItHwDXHuyEvGLX408 LY/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=ESc50BGBtr1c/t0z4vRGV0Q3OppW1+TQiU8GaotPTMI=; b=N31CV9J55LnULYz4vSpSQT0kMsDACe2t+j9Y9k+J0fe4XNC4BqXWyt+jwYR1JZJvSx e9XPSjuUmz5Rh4mDakmGphLqbTU4evl8oyZHcfyYvHAoa6XABGUEBk6VCFLw/5Gq6Rfv FtQZ+h7qCTV3Cps7TgGGXv1FmWOduFKdIhd8kyRfx0Ym2iC/aYkeH3C9AwCLfvs+qLz5 L+NYUbo/RM5ePxbBBC/WF/agjxFc+LHxCTg+A+SrQfmbUIJll8B1sbkTFauhmTEuE/P/ zYFRMn0Igy3CAOLSvhLl3EaT06LoMzmBQWtVE18Ql6K1hIklMw6Exile7Z66qx7gTCyN xsXQ== ARC-Authentication-Results: i=1; mx.google.com; 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 e14si603079pfj.86.2018.02.10.21.04.24; Sat, 10 Feb 2018 21:04:37 -0800 (PST) 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; 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 S1752727AbeBKEdo (ORCPT + 99 others); Sat, 10 Feb 2018 23:33:44 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41320 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752446AbeBKEdk (ORCPT ); Sat, 10 Feb 2018 23:33:40 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ekjKc-0002hF-7c; Sun, 11 Feb 2018 04:33:38 +0000 Received: from ben by deadeye with local (Exim 4.90) (envelope-from ) id 1ekjKX-0004Rp-2c; Sun, 11 Feb 2018 04:33:33 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Greg Kroah-Hartman" , "Johan Hovold" Date: Sun, 11 Feb 2018 04:20:06 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.2 05/79] USB: serial: garmin_gps: fix I/O after failed probe and remove In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.2.99-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Johan Hovold commit 19a565d9af6e0d828bd0d521d3bafd5017f4ce52 upstream. Make sure to stop any submitted interrupt and bulk-out URBs before returning after failed probe and when the port is being unbound to avoid later NULL-pointer dereferences in the completion callbacks. Also fix up the related and broken I/O cancellation on failed open and on close. (Note that port->write_urb was never submitted.) Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reviewed-by: Greg Kroah-Hartman Signed-off-by: Johan Hovold Signed-off-by: Ben Hutchings --- drivers/usb/serial/garmin_gps.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) --- a/drivers/usb/serial/garmin_gps.c +++ b/drivers/usb/serial/garmin_gps.c @@ -142,6 +142,7 @@ struct garmin_data { __u8 privpkt[4*6]; spinlock_t lock; struct list_head pktlist; + struct usb_anchor write_urbs; }; @@ -923,7 +924,7 @@ static int garmin_init_session(struct us sizeof(GARMIN_START_SESSION_REQ), 0); if (status < 0) - break; + goto err_kill_urbs; } if (status > 0) @@ -931,6 +932,12 @@ static int garmin_init_session(struct us } return status; + +err_kill_urbs: + usb_kill_anchored_urbs(&garmin_data_p->write_urbs); + usb_kill_urb(port->interrupt_in_urb); + + return status; } @@ -950,7 +957,6 @@ static int garmin_open(struct tty_struct spin_unlock_irqrestore(&garmin_data_p->lock, flags); /* shutdown any bulk reads that might be going on */ - usb_kill_urb(port->write_urb); usb_kill_urb(port->read_urb); if (garmin_data_p->state == STATE_RESET) @@ -977,7 +983,7 @@ static void garmin_close(struct usb_seri /* shutdown our urbs */ usb_kill_urb(port->read_urb); - usb_kill_urb(port->write_urb); + usb_kill_anchored_urbs(&garmin_data_p->write_urbs); /* keep reset state so we know that we must start a new session */ if (garmin_data_p->state != STATE_RESET) @@ -1069,12 +1075,14 @@ static int garmin_write_bulk(struct usb_ } /* send it down the pipe */ + usb_anchor_urb(urb, &garmin_data_p->write_urbs); status = usb_submit_urb(urb, GFP_ATOMIC); if (status) { dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n", __func__, status); count = status; + usb_unanchor_urb(urb); kfree(buffer); } @@ -1464,6 +1472,7 @@ static int garmin_attach(struct usb_seri garmin_data_p->state = 0; garmin_data_p->flags = 0; garmin_data_p->count = 0; + init_usb_anchor(&garmin_data_p->write_urbs); usb_set_serial_port_data(port, garmin_data_p); status = garmin_init_session(port); @@ -1479,6 +1488,7 @@ static void garmin_disconnect(struct usb dbg("%s", __func__); + usb_kill_anchored_urbs(&garmin_data_p->write_urbs); usb_kill_urb(port->interrupt_in_urb); del_timer_sync(&garmin_data_p->timer); }