From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BCE3C433EF for ; Mon, 13 Jun 2022 12:30:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354467AbiFMM2X (ORCPT ); Mon, 13 Jun 2022 08:28:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355482AbiFMMX4 (ORCPT ); Mon, 13 Jun 2022 08:23:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A056527B1C; Mon, 13 Jun 2022 04:05:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3BD68614A1; Mon, 13 Jun 2022 11:05:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49BA0C3411C; Mon, 13 Jun 2022 11:05:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655118303; bh=xZMuTpWursdJJdYloy8uMjAmfjbR/M9GPbci0Jb3eq4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dn1ayOHNR6q29BSUqutlCNWmd8NV2BweRtv6P763POj6qGoqDZUkGmGkabGG71m4w N7yVTyfdpcVhxo7yfBG84eclpMslAlnLU7CJ6rPoLbTAnwHSVTU9YuV5+lzZv+HWLO D06wp6dXCtfpbBWGDNSMQ1T4nrC67vWGLNXGWX2Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shuah Khan , Hangyu Hua , Sasha Levin Subject: [PATCH 5.10 009/172] usb: usbip: fix a refcount leak in stub_probe() Date: Mon, 13 Jun 2022 12:09:29 +0200 Message-Id: <20220613094852.630058915@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094850.166931805@linuxfoundation.org> References: <20220613094850.166931805@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: Hangyu Hua [ Upstream commit 9ec4cbf1cc55d126759051acfe328d489c5d6e60 ] usb_get_dev() is called in stub_device_alloc(). When stub_probe() fails after that, usb_put_dev() needs to be called to release the reference. Fix this by moving usb_put_dev() to sdev_free error path handling. Find this by code review. Fixes: 3ff67445750a ("usbip: fix error handling in stub_probe()") Reviewed-by: Shuah Khan Signed-off-by: Hangyu Hua Link: https://lore.kernel.org/r/20220412020257.9767-1-hbh25y@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/usbip/stub_dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/usbip/stub_dev.c b/drivers/usb/usbip/stub_dev.c index d8d3892e5a69..3c6d452e3bf4 100644 --- a/drivers/usb/usbip/stub_dev.c +++ b/drivers/usb/usbip/stub_dev.c @@ -393,7 +393,6 @@ static int stub_probe(struct usb_device *udev) err_port: dev_set_drvdata(&udev->dev, NULL); - usb_put_dev(udev); /* we already have busid_priv, just lock busid_lock */ spin_lock(&busid_priv->busid_lock); @@ -408,6 +407,7 @@ static int stub_probe(struct usb_device *udev) put_busid_priv(busid_priv); sdev_free: + usb_put_dev(udev); stub_device_free(sdev); return rc; -- 2.35.1