From patchwork Fri Jan 24 09:28:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 232974 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=-9.8 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, 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 669D2C2D0DB for ; Fri, 24 Jan 2020 11:20:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 31E642087E for ; Fri, 24 Jan 2020 11:20:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579864803; bh=bS3BpH1jsiAl5BZqxsk4NeHi/IKq3LT4SMF9wXBNaoU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=VV8+8HmrWf4t4F2qUu71lwgcp+7I0UWIGeiXWxbyBmePU07Gcol/xHqO2yO/JYOJn 17zQoAEE59a8eP1D8Rthk6Ql9Mu9fpTL6IgyMHHGIXny5dK/qVC7ONHA70S1eWi1Sk 33WPhhjWxHbEoaV1ZuxxceqZ6wMX823Z6vdo1e5I= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390651AbgAXLT6 (ORCPT ); Fri, 24 Jan 2020 06:19:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:57370 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390640AbgAXLT5 (ORCPT ); Fri, 24 Jan 2020 06:19:57 -0500 Received: from localhost (ip-213-127-102-57.ip.prioritytelecom.net [213.127.102.57]) (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 AA1A320708; Fri, 24 Jan 2020 11:19:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579864797; bh=bS3BpH1jsiAl5BZqxsk4NeHi/IKq3LT4SMF9wXBNaoU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vL2DUOi8TO24hO69PiyWLf1sa5oNMWpcOODEEk/MqRcvW8gLTmc4X7K/GnODq0O3t Wd4w+mveGRrsN/TQPnXbnNp9jhbvnBFGyljTqsrKiIyTuu+KslZ42WmB5riO8LLolM gyZ8KBUilAc/8ON/wJ91S0XOeSDTRFHd+vFiirNo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Cornelia Huck , Kirti Wankhede , Maxim Levitsky , Parav Pandit , Alex Williamson , Sasha Levin Subject: [PATCH 4.19 355/639] vfio/mdev: Avoid release parent reference during error path Date: Fri, 24 Jan 2020 10:28:45 +0100 Message-Id: <20200124093131.575240489@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124093047.008739095@linuxfoundation.org> References: <20200124093047.008739095@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: Parav Pandit [ Upstream commit 60e7f2c3fe9919cee9534b422865eed49f4efb15 ] During mdev parent registration in mdev_register_device(), if parent device is duplicate, it releases the reference of existing parent device. This is incorrect. Existing parent device should not be touched. Fixes: 7b96953bc640 ("vfio: Mediated device Core driver") Reviewed-by: Cornelia Huck Reviewed-by: Kirti Wankhede Reviewed-by: Maxim Levitsky Signed-off-by: Parav Pandit Signed-off-by: Alex Williamson Signed-off-by: Sasha Levin --- drivers/vfio/mdev/mdev_core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 0212f0ee8aea7..8cfa712308773 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -182,6 +182,7 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops) /* Check for duplicate */ parent = __find_parent_device(dev); if (parent) { + parent = NULL; ret = -EEXIST; goto add_dev_err; }