From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68DBB1E7C2D; Wed, 17 Sep 2025 12:40:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758112808; cv=none; b=JjCaSYubkF6rjs1R2OP2KTmsGkfgCba8uxyV+peKgIfP2vpc08k8B7Sn4vdkPDoRSUuRBWc1tzF2IyHhplBcKe4Purzb1omiY6AXoVj1jE8VA+jg8zZe3A5fJw0HdNeXusfULuaS8z3SKiQB4Q8GCjw1WOq0UgCIBwt8IGH3mX4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758112808; c=relaxed/simple; bh=PilOcc9dPZ8a17J1F2XKqT0AwcNNH79aOYUo3uYEkbQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oMzaLSpnwnEgtmsq3ibvA2I4NmbPitQwk9JbME/M1G2/TVBtD15u2qO+Qa54s4bqn2ZEE8h+FqHkrOUkUDUXAVm+x4t7rJdRdHBppykm3veWPEGeRqfi2siC3wel5ywuffRKVwnY61dnwSWqILfMVoib9ncJvFagykn/Wrq7Ax8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=dPdB204h; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="dPdB204h" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB825C4CEF0; Wed, 17 Sep 2025 12:40:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1758112808; bh=PilOcc9dPZ8a17J1F2XKqT0AwcNNH79aOYUo3uYEkbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dPdB204hENH/wAJhfPFQ17SFQEYoISBWX/qrBYLPyLN6PbkrdSAZ6hYHDwDOjzlNT wV2i/UWq7HAbhlMKifsR+UItcoSsT+CztCLtQWqncwWwer/sXjJa4KLYs0mfPjQjr+ KBlomCZOJs9DSkUOKNEXdi9Tn+05EJTAM8KlUFec= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ma Ke , Johan Hovold , CK Hu , AngeloGioacchino Del Regno , Chun-Kuang Hu Subject: [PATCH 6.16 083/189] drm/mediatek: fix potential OF node use-after-free Date: Wed, 17 Sep 2025 14:33:13 +0200 Message-ID: <20250917123353.890368733@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250917123351.839989757@linuxfoundation.org> References: <20250917123351.839989757@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Johan Hovold commit 4de37a48b6b58faaded9eb765047cf0d8785ea18 upstream. The for_each_child_of_node() helper drops the reference it takes to each node as it iterates over children and an explicit of_node_put() is only needed when exiting the loop early. Drop the recently introduced bogus additional reference count decrement at each iteration that could potentially lead to a use-after-free. Fixes: 1f403699c40f ("drm/mediatek: Fix device/node reference count leaks in mtk_drm_get_all_drm_priv") Cc: Ma Ke Cc: stable@vger.kernel.org Signed-off-by: Johan Hovold Reviewed-by: CK Hu Reviewed-by: AngeloGioacchino Del Regno Link: https://patchwork.kernel.org/project/dri-devel/patch/20250829090345.21075-2-johan@kernel.org/ Signed-off-by: Chun-Kuang Hu Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c @@ -388,11 +388,11 @@ static bool mtk_drm_get_all_drm_priv(str of_id = of_match_node(mtk_drm_of_ids, node); if (!of_id) - goto next_put_node; + continue; pdev = of_find_device_by_node(node); if (!pdev) - goto next_put_node; + continue; drm_dev = device_find_child(&pdev->dev, NULL, mtk_drm_match); if (!drm_dev) @@ -418,11 +418,10 @@ next_put_device_drm_dev: next_put_device_pdev_dev: put_device(&pdev->dev); -next_put_node: - of_node_put(node); - - if (cnt == MAX_CRTC) + if (cnt == MAX_CRTC) { + of_node_put(node); break; + } } if (drm_priv->data->mmsys_dev_num == cnt) {