From patchwork Fri Jan 24 09:30:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 233173 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=ham 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 6AC57C2D0DB for ; Fri, 24 Jan 2020 09:58:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 426C8214DB for ; Fri, 24 Jan 2020 09:58:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579859905; bh=bS3BpH1jsiAl5BZqxsk4NeHi/IKq3LT4SMF9wXBNaoU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=NXSYmA+QyNC73cMRN5p+Sy/t2gjS142NXiNNmhmKLHODMMn0lr5NN/qW0jRC++Tb1 /WMFWUpo8QxUT5pmeyOgnRPAYpRnbf6yXvQJe7D4FLuJ8jybKex+MwioH3hRwyT2yc PV1KRxD831iUHaDqHc0UZmfpZutw2G8O/i5hThz8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733275AbgAXJ6Y (ORCPT ); Fri, 24 Jan 2020 04:58:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:33938 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725821AbgAXJ6Y (ORCPT ); Fri, 24 Jan 2020 04:58:24 -0500 Received: from localhost (unknown [145.15.244.15]) (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 949AD20718; Fri, 24 Jan 2020 09:58:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579859903; bh=bS3BpH1jsiAl5BZqxsk4NeHi/IKq3LT4SMF9wXBNaoU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tkgmu2i8Ly6X3me6SrO4MhSleakmEVwXZuv1SahmA1p6837yQBBrWt0Z8AISfaaWB xZYHrzjM4xIeHLLpDS+kXYD7/nBQ+b6v77ExnSMq0eLd7FSVU6DKxdc+kOKCib/tZP uRTGgsP3n0ABq6se92fNzmJnC7oKc8FaahnmdzfA= 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.14 196/343] vfio/mdev: Avoid release parent reference during error path Date: Fri, 24 Jan 2020 10:30:14 +0100 Message-Id: <20200124092945.761803829@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124092919.490687572@linuxfoundation.org> References: <20200124092919.490687572@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; }