Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp636815iog; Mon, 13 Jun 2022 09:36:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzN5qlSNnHMiNhki8AydwyW5yUsmYY0AH0kuTGvM3y+ftGLlJs5jpNfnVT3namE0oXbz4mf X-Received: by 2002:a05:6402:3224:b0:42d:e68c:2fd with SMTP id g36-20020a056402322400b0042de68c02fdmr652514eda.282.1655138212454; Mon, 13 Jun 2022 09:36:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655138212; cv=none; d=google.com; s=arc-20160816; b=j3vn5n4Kq4ZjFu9WznX8WVQfjI1rkux0oQ7CoO8DM/fII3DuboK/oW//6+uS3BAAVh 1phMQyp4WaWp+Tbi3SFu2dYkulPU22qFnNn6xDLZMdxigAVZsIzX8abOWqal80AfnT8y EKN+o+i3Y8Ybw1HkEMSxvYIlkMhlYlVXUwziko0mbtQyBgXTYUkXpzmmmqGfQ9uMYaqq Npg4pVeJS7gaWbC5cr1dPOsWe/BYNZ3lugoT3y8OqKiBGbrhQxJq1brTEdjjGxnH7BJB HazFF1PEfus51c2SIYYwCH84Hb4xx+GruR0PpoGxo5+qyqZ9uIm4o8tIsxwNgeXeMwCD 1o3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ifvdblUVjIXrzg3NCTMsKdvBPHtOxWXnHXebpED5fFg=; b=0ywBqTmVT0Yj2XTNrK7y4gR7fOaIbsJ06a6oH9oRBDnE1d7znKOCzBAowbcnI4UgoT 6XwOJtylqi5U128n3WH3r+nnQUsYdaTjm0qUjDmE1J9RGFtfdgJkwOR/BrUpwgUWcYA3 mnVhFEpO/dY15dPJzLdLrSU+qZdkcLK5kHhC0NntVeKkZPZwUbiU5UHqOgPXOxAfMzgH uuHO3D2594GO27t/duCXyjXWD7aNqobiKIpQFbtZ4L7Sb1DtuiX+fFMS/Z6ipV1zABoi cNAh3Axo0rYLh0B3srLB3zbtK6z9ESn1MOhkhcUYbs8tG95ZE/y6ECNG4vAi+FvGw7Kk MSfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=X7KNwHob; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y23-20020a170906519700b007156bee9755si6707990ejk.917.2022.06.13.09.36.26; Mon, 13 Jun 2022 09:36:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=X7KNwHob; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377402AbiFMN0m (ORCPT + 99 others); Mon, 13 Jun 2022 09:26:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377116AbiFMNYY (ORCPT ); Mon, 13 Jun 2022 09:24:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A4CD6BFF8; Mon, 13 Jun 2022 04:24:06 -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 ams.source.kernel.org (Postfix) with ESMTPS id C1987B80EA7; Mon, 13 Jun 2022 11:24:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33222C34114; Mon, 13 Jun 2022 11:24:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655119443; bh=xZMuTpWursdJJdYloy8uMjAmfjbR/M9GPbci0Jb3eq4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X7KNwHobug5Oj/YX3TAjKBJfRWeeU+kLPQiB9L416p7Qdm9qLWDQjIVEHm7a6BkZY Iajv3eB1/gLNfyYkKLSRwzNIulERYJ74QeuhN4OVq7htTMAopGrdXmGCpsskAHN7P9 0vIwbzvoiQi4M0hiVxHInD+la8yU0f9HPrhOHhwM= 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.18 017/339] usb: usbip: fix a refcount leak in stub_probe() Date: Mon, 13 Jun 2022 12:07:22 +0200 Message-Id: <20220613094927.031372124@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094926.497929857@linuxfoundation.org> References: <20220613094926.497929857@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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