Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9235681pxu; Mon, 28 Dec 2020 10:03:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQggKg+FgkZlaTrNuOAFq3tf6h/JsjfGqTauZCoZu/8CexkDetDDedrw4WYa46vZBuCE6o X-Received: by 2002:a50:ed17:: with SMTP id j23mr43118270eds.218.1609178624862; Mon, 28 Dec 2020 10:03:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609178624; cv=none; d=google.com; s=arc-20160816; b=nQG9Q1YLqOrZBpu+hsBgZFJz9bEI0Gbv04VIqxFtxh2pZGAB6Q+yM1VuWHvlqvef49 n8SIhFVsnX5J3ujlrD84cJzE3MieTceSwkq8J9nQ7nOC7Vw6aGQ8lEF0IVbNMAF5RuiY W8RuQJuHQtH2jL+LXHHaI+fjsiOpombVpCMMkU2mYemkZaiFm0MCBWzErKs2kDhjFwH3 th0yeOPYgi1MhuxzqgVV7VhLgGF/Rp7ie+/8NZGR0uVQmcKCB0pihO2wjflEqlL+aNuY 1dF0jeG5wbmtjEtVdme5QgbnYu15naQa934dEhaoX5UKeJq14oYxAFnKoC3/6eE4W1Ym sZ6A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FJIajK91TqX9+dDmlNxITaXaWBMr347rs4dSsskFYJg=; b=BWZxI/9qirqHms1a2lr8IzfXtDfpVeh0Zbq7bkV2BtldXxxh3+wDdRN98C/5XF6Vpb iL+L+kAHdcK5awzkO0x0Y63azkBAVw5+IUyd87XVfbcEWwm/5JsNt5c4Ato4HIPvIfDX V3UQmNro1QkTRphS5wm8iVYrL83iLIIeL/zEm6ywx9VjGWt/J/rrvVv0Yr8WIxdfFtsp yhGIcBkkS3W240i4qP2ue7mx73dvQWgcBtTgXit9Td3VhdTh10FdEnbHd6ZisnUW++8V Qasvj8dYY502dvUq/KknKaHzi8lS73gzsrR3lM4oU+1u/oPrFOIwGCmOLpWWlrjFSE0r oZ1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TdQz37Cw; 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=pass (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 r24si20283552edc.286.2020.12.28.10.03.22; Mon, 28 Dec 2020 10:03:44 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=TdQz37Cw; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388204AbgL1NWB (ORCPT + 99 others); Mon, 28 Dec 2020 08:22:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:50398 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388140AbgL1NWB (ORCPT ); Mon, 28 Dec 2020 08:22:01 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9C98C2076D; Mon, 28 Dec 2020 13:21:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161680; bh=eg4fi6qKnB7mzX9PnPZ8OEhZzr/7dxH8YPQE19RtqU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TdQz37CwAumBTUb7eai6yjj1juUKvcW9+9In12wXL2RkpqHZzN6j5ZxXLCLEBF/8e 383jDYNP+4A/RN/boIYhab4PLTtB/mOCRk6bmQLluS4t+yO2apOFmKBKPDvIz29oWp yB/c9gMFRYjXgJz/aLeHZ9L/ir+Dl6D1qF4rtmwM= 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 , Sudip Mukherjee Subject: [PATCH 4.19 049/346] drm: fix drm_dp_mst_port refcount leaks in drm_dp_mst_allocate_vcpi Date: Mon, 28 Dec 2020 13:46:08 +0100 Message-Id: <20201228124922.160033040@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124919.745526410@linuxfoundation.org> References: <20201228124919.745526410@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 [sudip: use old functions before rename] Signed-off-by: Sudip Mukherjee 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 @@ -2706,11 +2706,11 @@ bool drm_dp_mst_allocate_vcpi(struct drm { int ret; - port = drm_dp_get_validated_port_ref(mgr, port); - if (!port) + if (slots < 0) return false; - if (slots < 0) + port = drm_dp_get_validated_port_ref(mgr, port); + if (!port) return false; if (port->vcpi.vcpi > 0) { @@ -2725,6 +2725,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_put_port(port); goto out; } DRM_DEBUG_KMS("initing vcpi for pbn=%d slots=%d\n",