Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1234796pxk; Fri, 2 Oct 2020 04:47:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNeoWseKFmeHRUkAjXH+kTp8QGUgmK1WcV8AONElYv458730EEnY+Emsejk7J1zzEqVY8l X-Received: by 2002:a17:906:454e:: with SMTP id s14mr1895079ejq.137.1601639231152; Fri, 02 Oct 2020 04:47:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601639231; cv=none; d=google.com; s=arc-20160816; b=ovpRQTVHDs4C0n2s7wPCVbyUDXdKiN2GIuOY+PQJFCKMZ/qtedYGVBSvUxMbi93Lir 6bLmz36zOc60PNydaNUPvZqRJNG4JtmViF0i7FVMCDTDnMsUVG7OgnE9/3B5q6+sEiV7 MviG9BRQTCexs87SzW3uLnb036JbNg2P6RPDK+c/e9qBkbM13wbTCGfdreW6IcsIGFug PhN3NbHYDg569lrTbtySOFSh3xT652F+uq33p1CtDFuLE4vLmVu4xcbp0QS5sCNPU8s5 YUty7PUrRHPfcoqNe1tpAn9uK4u68VGe5Q7usyUz8BFUX2Drf7haUzFa8kA6cKWuzagC Aqvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=sfZ9p9p0urJ+aQzHdZ5CWEuLONKbFBEGRJPf7vKX3js=; b=SzMeuAWWoaDAWiND+wY36kflHpzVaIce2PpB/9fb4pXkt9O8sUKhZaeRXinIekaYnV Ob8rjUvmAJY+wJQBGqC3rZq8r16XQeyRh4HCj/4yRGyll34z8ybf6WtThVeAPq8cR8TD hawqraNznm4RbJ9LxSht+DsLJu+UTVoF8GSkfTAl0n36ut8nF9V+TITqmthdHoRpbQZ4 56s9U5BUaey4dZ+eQANo9SJRvWAXb7Ph/CtSzQJLC8XSIVWY25kLeih6MKIEccuU5rwn c+gMGjq3PDH8YlXSijtH4tmgdzwW3x2tJc7MaWmKCWucj3S0Yl4IGGXZBHQoJkAsprjV hN0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=H017jt+A; 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 g12si861792edy.479.2020.10.02.04.46.48; Fri, 02 Oct 2020 04:47:11 -0700 (PDT) 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=H017jt+A; 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 S2387783AbgJBLn0 (ORCPT + 99 others); Fri, 2 Oct 2020 07:43:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:39850 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725964AbgJBLn0 (ORCPT ); Fri, 2 Oct 2020 07:43:26 -0400 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 E810D206E3; Fri, 2 Oct 2020 11:43:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601639004; bh=Um0ftaims7pCV0EgtbpdXAsPSGzpFNfGBGqMRGVKZDk=; h=Date:From:To:Cc:Subject:From; b=H017jt+AENqlGNPFcbs3k6i35nY2cX3xdETy+xt4hgTl/ENbHnxT2819pviiNxPny rOSe1grXkX5H33e0dFYd29v8z3K4uS/4vUKif55N4lqt/X31ds6JC/QHQgGzdLBBei bReBhEINXuK54Sa82lKc4iwK9cB3pPlRfBRaroXA= Date: Fri, 2 Oct 2020 13:43:23 +0200 From: Greg KH To: netdev@vger.kernel.org Cc: Tuba Yavuz , "David S. Miller" , Jakub Kicinski , Oliver Neukum , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v2] net: hso: do not call unregister if not registered Message-ID: <20201002114323.GA3296553@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tuba Yavuz On an error path inside the hso_create_net_device function of the hso driver, hso_free_net_device gets called. This causes a use-after-free and a double-free if register_netdev has not been called yet as hso_free_net_device calls unregister_netdev regardless. I think the driver should distinguish these cases and call unregister_netdev only if register_netdev has been called. Signed-off-by: Tuba Yavuz Signed-off-by: Greg Kroah-Hartman --- v2: format cleaned up based on feedback from previous review Forward to Greg to submit due to email problems on Tuba's side diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c index 2bb28db89432..e6b56bdf691d 100644 --- a/drivers/net/usb/hso.c +++ b/drivers/net/usb/hso.c @@ -2366,7 +2366,8 @@ static void hso_free_net_device(struct hso_device *hso_dev, bool bailout) remove_net_device(hso_net->parent); - if (hso_net->net) + if (hso_net->net && + hso_net->net->reg_state == NETREG_REGISTERED) unregister_netdev(hso_net->net); /* start freeing */