From patchwork Tue Jun 23 19:56:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 223238 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8224C433DF for ; Tue, 23 Jun 2020 21:14:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E52920706 for ; Tue, 23 Jun 2020 21:14:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592946849; bh=nYC6zV5cB3CqsqUoi8Se6DDAWTT7b6VGwCCfLbThw9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ML5VxKVPvv58ILPK31i3q80uihkDRvtRRx8S2lzz2ns4Mx/lBEKzX7rGxxj0ur3jQ Ra2P8LUpkXwOwsjlq3oQHq+q82KsMySVPVsdYklsI59zNJyeSPwC1lC16B85yDNz6T Amz2N4HKUSbXQoBNTg2lNEukoi8qufsPRB68cn6c= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390524AbgFWU3k (ORCPT ); Tue, 23 Jun 2020 16:29:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:49724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391009AbgFWU3i (ORCPT ); Tue, 23 Jun 2020 16:29:38 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 800C02064B; Tue, 23 Jun 2020 20:29:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592944179; bh=nYC6zV5cB3CqsqUoi8Se6DDAWTT7b6VGwCCfLbThw9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xB0lZqfRrd7ukt9Ufz8Cd4/mBQjc05e50pSMm9ra1221DZy3Zi1IOVSrqMi6eZ28m 36+9W/qfjgz/1CwH7wsyZNCNIWUz+n1bEo6gkMVvRLIzxBupqrgGPuv7cjD6e8FZV1 w+eS7Cv7r/2Ib6LaqIxrWXA8IwNGh9KArABUQnY4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qiushi Wu , Cornelia Huck , Kirti Wankhede , Alex Williamson , Sasha Levin Subject: [PATCH 5.4 204/314] vfio/mdev: Fix reference count leak in add_mdev_supported_type Date: Tue, 23 Jun 2020 21:56:39 +0200 Message-Id: <20200623195348.653071300@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623195338.770401005@linuxfoundation.org> References: <20200623195338.770401005@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Qiushi Wu [ Upstream commit aa8ba13cae3134b8ef1c1b6879f66372531da738 ] kobject_init_and_add() takes reference even when it fails. If this function returns an error, kobject_put() must be called to properly clean up the memory associated with the object. Thus, replace kfree() by kobject_put() to fix this issue. Previous commit "b8eb718348b8" fixed a similar problem. Fixes: 7b96953bc640 ("vfio: Mediated device Core driver") Signed-off-by: Qiushi Wu Reviewed-by: Cornelia Huck Reviewed-by: Kirti Wankhede Signed-off-by: Alex Williamson Signed-off-by: Sasha Levin --- drivers/vfio/mdev/mdev_sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index 7570c7602ab40..f32c582611eb6 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -110,7 +110,7 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, "%s-%s", dev_driver_string(parent->dev), group->name); if (ret) { - kfree(type); + kobject_put(&type->kobj); return ERR_PTR(ret); }