Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp53497lfv; Tue, 12 Apr 2022 17:01:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXHqFiNRu2gLfXi/Bpw7dMUP9UvbbqFeEwZiQYWG/hdlIUfEvyYmTSDom9Rio70MiNv6H4 X-Received: by 2002:a63:ad45:0:b0:382:2459:5bc6 with SMTP id y5-20020a63ad45000000b0038224595bc6mr33473868pgo.474.1649808087170; Tue, 12 Apr 2022 17:01:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649808087; cv=none; d=google.com; s=arc-20160816; b=HtZUNubNjEI+7ojAAUrqFnJBorb9QjXd0kdDf9UlBrp4Qg53wGu8ee7lf6E8QlTv3/ 3W/o10YLInyFnf8hkPi39PKyKdPBipizlWj42ZPzwXV+o0rlsYf2u7NBGca0hCGozNYv p1g87Yvutm1spaig77kY3KCX6OxvnbLFe1BaxFE2rV4RIL/+furSsgeVJ7qYJ7btiLvN yMAxK2TrV2ywmRiZMvuMGS/Q3NyQ7uyWlHNhWWwptIZM+XUF4BKZGvB/MZ+qdyPPbMrd arm1Rj5V/FiByYF7Y+lYeB2feQLOHvRWcVpUJDzq+lJVsmaOb9fShzAhdYX8QaGKF7S9 1rBw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=OSPq/f1fzEIxN+j0n/fpdsesVfU3t6cZSqHyG+8nEUw=; b=a1v0ZZ2lyCIf5VNzpI8vkdl/BEqzssv4TSKfgMXP162e1sGi5OO7YvVvBCThFZA9wK FWAm1ZRvknpw8hw7UDJbR39Xy4OcKdGmFCEajGFiP1OGgdiA637H/n+MaE9fib3WwNEQ PuGnu+1JfVM9wc8pbIocvItrgjIiNt+O+Ayu1ymBNHO6ONCkgkboR/05g7liJlICUVa5 SJ4H2dxOwog6yEpjgVwqixsaVdMmXuHl4qfpY4ZMFlwLe9gu9bKBmoWt1y4VKxahF++t XoS97qyPaKD4CPqCrCSeSqpoxwngSeIdz2W/ya0yShizFGX5bPlRg4kRJhi6twvnp6YX 0BCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RcYztbCb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id o4-20020a654584000000b00398a2b708c9si4098438pgq.211.2022.04.12.17.01.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 17:01:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RcYztbCb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5A282213522; Tue, 12 Apr 2022 14:57:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240438AbiDLCFf (ORCPT + 99 others); Mon, 11 Apr 2022 22:05:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231782AbiDLCFa (ORCPT ); Mon, 11 Apr 2022 22:05:30 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3128C31507; Mon, 11 Apr 2022 19:03:15 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id f3so16188349pfe.2; Mon, 11 Apr 2022 19:03:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=OSPq/f1fzEIxN+j0n/fpdsesVfU3t6cZSqHyG+8nEUw=; b=RcYztbCbPhBXbYovGgjFPRLBCJsHH6c1flVWzZH88rkHm/9Umin1lcC94mtpi/dFVC lr4yHI9oOQaWDTh5B3RIr6rjyTjIC0aKPjai6XDzubcYDW/HZWagEyrh+bx1UcF+yV14 /VKQYxNnqiEblRGFI0TozfNnoUVE5oYX1AFsJjOfnbEZCil1NZnG/IUqZVSXbV5N/luq EzSk65bCPW0iQsIcTTWDgYGLx4nLsRrrdS/yTA5pXgmYTwP5LC52j+UvFaFImT7KFzEK TCxpXMM1gu7J/XtWEkw60AhuD/tb+GibGf1V91voqg6M5zxXF3DhmZFFOPbaXFIBJ6IX P1tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=OSPq/f1fzEIxN+j0n/fpdsesVfU3t6cZSqHyG+8nEUw=; b=yFHQ8vJ7J77WMeaFiSyREtKVh7a/Bc86NbGMq02AIFFaN5L5IqHnRpq0zwk5FtIuts 0Ucmr3bRc78XAApPMxHsJfD0HokpGr2SPUQO/Uy060B9hcymJDlsrYQwWb0gtYHFen0b DKRSPQUxHNThAeds/pUa/7sK2oh9H8citV2MBs0cgl6jmqOjqK4o/dsZSajljb9BEA1j +wWRZOdo3siT9PGpUOMKrtkAfDKI0UX9AgCTt5XugOv+eNrPzlKvFn2uoUEdU2VlI16d pYFg9g0yb2troqnYSYs20z+a0RvsKrwH9OrKyV9UHcEZTl2znjUnb8IzaMwDRZaM9MyG tqHw== X-Gm-Message-State: AOAM530/ytmguP7F+b49jR5m8WLh04RhPLxzl25jOdMIVkCxC9KjNRHe KcF2ZbSPM8aW+qvE3qj4Q2o= X-Received: by 2002:a05:6a00:891:b0:4fe:1262:9b4e with SMTP id q17-20020a056a00089100b004fe12629b4emr2204928pfj.21.1649728994725; Mon, 11 Apr 2022 19:03:14 -0700 (PDT) Received: from slim.das-security.cn ([103.84.139.54]) by smtp.gmail.com with ESMTPSA id m21-20020a17090a7f9500b001c97c6bcaf4sm749289pjl.39.2022.04.11.19.03.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 19:03:14 -0700 (PDT) From: Hangyu Hua To: valentina.manea.m@gmail.com, shuah@kernel.org, gregkh@linuxfoundation.org, khoroshilov@ispras.ru, skhan@linuxfoundation.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Hangyu Hua Subject: [PATCH v3] usb: usbip: fix a refcount leak in stub_probe() Date: Tue, 12 Apr 2022 10:02:57 +0800 Message-Id: <20220412020257.9767-1-hbh25y@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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()") Signed-off-by: Hangyu Hua Reviewed-by: Shuah Khan --- v2: add more description of this patch. v3: add how to find the problem. 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.25.1