Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1237244pxa; Thu, 20 Aug 2020 06:25:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvAdgKXpv65i939AfEbONqaFCI61gldcDTM+vM8kPGDf4FiSViC2au+Z8XLuD8ihSK2uJ1 X-Received: by 2002:a50:8f44:: with SMTP id 62mr2855061edy.351.1597929957982; Thu, 20 Aug 2020 06:25:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597929957; cv=none; d=google.com; s=arc-20160816; b=A2xuOPEsyG3FtZw36Ju1fKP/Q93SHgdqKdTQMu4uDe0PF0RZW664ArL7EoPY9ZVFjW 089cDg7A0TkNIDAF8lnEtgs1LT8MW0IVFXA/MKAihbf2dFjzgdtg1F6Amkw7pTUPzPBt vBCaRf6OrKm41RQG3zsce2FA3SF5kYWWvuTIsbqLU82X6/OgmKg4UKj6iXzNG8PCj/iX 32oLdFkrPOH9X7pVj7DCngyh5TgTPgv6JKHf2zCrSrmFzPBvGdZ4COd66ZY8/Mp4kiCH 9/4tMEGh2weuNelp8FLkOHvK/0SLvcB/uEda3Yq1xga0snYsc5E0pDmb3SCfr+L+39FZ kogA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cTRimJWtTNbLGSH1px//B/29n608guQMzRnngOf+TjM=; b=Rxjwhof9VsIteTnPFPsEVeE+1lk3lFsqeCzMQ79/+WMDJhkRvile5qQqEm8fNWHxcJ N75A/clG01SVigxaVeb/zj6dsqnzcdIRQymGNIWCsi3QQ5brAqWGUnpnCr8ujIsWPH9j IzrlD6NfBfbWE6lwpnqQ+SlNs5XsWukpsdxBNGwVJPUX1XnMLmnWfqJDdglUOaMuuBlD QNGX4zVVeKAq6MmPnWyIS0HWLtiGda6tKq93ARGnzJjpirv8nP8z1j5hgehFCQsMtP2T FacLwaWrAlBroPGtwBKrcAzm11vfUSBgNmUzqPahoWI2/ZDekcfHSb6PAfXsEDToqn4v 7zFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VL2iHv3n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r28si1246745edc.150.2020.08.20.06.25.32; Thu, 20 Aug 2020 06:25:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VL2iHv3n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730808AbgHTNZC (ORCPT + 99 others); Thu, 20 Aug 2020 09:25:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:46354 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728301AbgHTJeR (ORCPT ); Thu, 20 Aug 2020 05:34:17 -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 B2B9C20724; Thu, 20 Aug 2020 09:34:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597916057; bh=G9O5B4bLDz3YgKLmYiE6G55P498/DsEZrzkcwiX6g2A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VL2iHv3n4M9ta9iUQIUeiARi3PDU3+MkGFi2yuGvISOn/cL/NELl5V85J4ApWMTTb F9gHl+nO8I5X7p8i63wD5XlwtboSRadPjTD5Asvk5Y7+nA0q3w4WZ0PvWiun6J69nK qdySxZg1WZQa5D6f85aHZhL98hayIXjWZE40gJDo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiyu Yang , Xin Tan , Xin Xiong , Lyude Paul Subject: [PATCH 5.8 229/232] drm: fix drm_dp_mst_port refcount leaks in drm_dp_mst_allocate_vcpi Date: Thu, 20 Aug 2020 11:21:20 +0200 Message-Id: <20200820091623.866683973@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xin Xiong commit a34a0a632dd991a371fec56431d73279f9c54029 upstream. drm_dp_mst_allocate_vcpi() invokes drm_dp_mst_topology_get_port_validated(), which increases the refcount of the "port". These reference counting issues take place in two exception handling paths separately. Either when “slots” is less than 0 or when drm_dp_init_vcpi() returns a negative value, the function forgets to reduce the refcnt increased drm_dp_mst_topology_get_port_validated(), which results in a refcount leak. Fix these issues by pulling up the error handling when "slots" is less than 0, and calling drm_dp_mst_topology_put_port() before termination when drm_dp_init_vcpi() returns a negative value. Fixes: 1e797f556c61 ("drm/dp: Split drm_dp_mst_allocate_vcpi") Cc: # v4.12+ Signed-off-by: Xiyu Yang Signed-off-by: Xin Tan Signed-off-by: Xin Xiong Reviewed-by: Lyude Paul Signed-off-by: Lyude Paul Link: https://patchwork.freedesktop.org/patch/msgid/20200719154545.GA41231@xin-virtual-machine Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/drm_dp_mst_topology.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/drivers/gpu/drm/drm_dp_mst_topology.c +++ b/drivers/gpu/drm/drm_dp_mst_topology.c @@ -4262,11 +4262,11 @@ bool drm_dp_mst_allocate_vcpi(struct drm { int ret; - port = drm_dp_mst_topology_get_port_validated(mgr, port); - if (!port) + if (slots < 0) return false; - if (slots < 0) + port = drm_dp_mst_topology_get_port_validated(mgr, port); + if (!port) return false; if (port->vcpi.vcpi > 0) { @@ -4282,6 +4282,7 @@ bool drm_dp_mst_allocate_vcpi(struct drm if (ret) { DRM_DEBUG_KMS("failed to init vcpi slots=%d max=63 ret=%d\n", DIV_ROUND_UP(pbn, mgr->pbn_div), ret); + drm_dp_mst_topology_put_port(port); goto out; } DRM_DEBUG_KMS("initing vcpi for pbn=%d slots=%d\n",