Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1333976imm; Tue, 2 Oct 2018 06:41:30 -0700 (PDT) X-Google-Smtp-Source: ACcGV60lHIhWMQx/WaBHA9RxPWtA4vVsTX61Hw7tYkOSx3i6VWDg+BLxhcGgWfp8Su7zWeND/+3h X-Received: by 2002:a62:b604:: with SMTP id j4-v6mr16422745pff.199.1538487690868; Tue, 02 Oct 2018 06:41:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538487690; cv=none; d=google.com; s=arc-20160816; b=r9FhF84HkI8f8DqtApXx2ErTgR/PfTyZwlDsUPym9VwZt92bFruB0jyz/Vt08vJYSy gaCaMubcxhJggwQLaG5PK+1tna9L3xXqiiV6eYdxjF6elUXqMzxfnZdbthfYeLyMMD4g hEqtKR+xs//KxMFGDmF4J1LaeGz2BJKgSX2ry06Kzd68AO2fbgzSdC8/v5jxaWGcUE1n ZMotCsZS+cA35BP+ufkAOwMCbzWeWiZJvbt1nn7qr+nSdc6jawDrUwiQlv41fd03COGV f2TSJTIejUGlMgIUzooU9VtukANTrEBw/jLgqKhOaOPb6vBI87ioOhmbJFRZ/63i/ltb Dbdg== 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; bh=SHgYzE+5b/77NeeyndP2AVExj67T0IuQtonU97cv4nU=; b=USj+zl93XaB596ta/QFUsYafJT4I0SJwIr+ZVu/5uL7OOYCMl9vZV29ZpQlET3/Y1o 7zNkDmapRCDyHi6wYkTNYhlMSNokd6DF6xran3/nD3lCwEHXQt75VgWKDd9DmITwXl24 fjNriHuwmNDW2matYmj1jVgjcTA06/qe6sqHfaA/iPqBNHMZZali4XmHoKNX28HVS9Af 87hfL1/OygqpZjF2enkUOewevnL/MFOL5vWNf4Ibxq08fDRz52WeicmLf9uAwCe/1iHm nvXSTeKb8CqayxCerZnsRrNfonvJ4ED6LdLxiAeyWD39AtCPgFO/8c/O5jPNGkoAczHX iGzA== 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 f62-v6si16524791plf.164.2018.10.02.06.41.16; Tue, 02 Oct 2018 06:41:30 -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; 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 S1733241AbeJBUUA (ORCPT + 99 others); Tue, 2 Oct 2018 16:20:00 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:36332 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731715AbeJBUT7 (ORCPT ); Tue, 2 Oct 2018 16:19:59 -0400 Received: from localhost (24-104-73-23-ip-static.hfc.comcastbusiness.net [24.104.73.23]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BF3A0C47; Tue, 2 Oct 2018 13:36:34 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Stern , syzbot+f84aa7209ccec829536f@syzkaller.appspotmail.com Subject: [PATCH 4.9 64/94] USB: fix error handling in usb_driver_claim_interface() Date: Tue, 2 Oct 2018 06:25:18 -0700 Message-Id: <20181002132504.938991548@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181002132500.494838053@linuxfoundation.org> References: <20181002132500.494838053@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alan Stern commit bd729f9d67aa9a303d8925bb8c4f06af25f407d1 upstream. The syzbot fuzzing project found a use-after-free bug in the USB core. The bug was caused by usbfs not unbinding from an interface when the USB device file was closed, which led another process to attempt the unbind later on, after the private data structure had been deallocated. The reason usbfs did not unbind the interface at the appropriate time was because it thought the interface had never been claimed in the first place. This was caused by the fact that usb_driver_claim_interface() does not clean up properly when device_bind_driver() returns an error. Although the error code gets passed back to the caller, the iface->dev.driver pointer remains set and iface->condition remains equal to USB_INTERFACE_BOUND. This patch adds proper error handling to usb_driver_claim_interface(). Signed-off-by: Alan Stern Reported-by: syzbot+f84aa7209ccec829536f@syzkaller.appspotmail.com CC: Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/driver.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -562,6 +562,21 @@ int usb_driver_claim_interface(struct us if (!lpm_disable_error) usb_unlocked_enable_lpm(udev); + if (retval) { + dev->driver = NULL; + usb_set_intfdata(iface, NULL); + iface->needs_remote_wakeup = 0; + iface->condition = USB_INTERFACE_UNBOUND; + + /* + * Unbound interfaces are always runtime-PM-disabled + * and runtime-PM-suspended + */ + if (driver->supports_autosuspend) + pm_runtime_disable(dev); + pm_runtime_set_suspended(dev); + } + return retval; } EXPORT_SYMBOL_GPL(usb_driver_claim_interface);