From patchwork Mon Dec 26 18:10:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Zhandarovich X-Patchwork-Id: 13082877 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EAB9AC4332F for ; Wed, 28 Dec 2022 11:17:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B0ECB10E398; Wed, 28 Dec 2022 11:17:07 +0000 (UTC) X-Greylist: delayed 325 seconds by postgrey-1.36 at gabe; Mon, 26 Dec 2022 18:16:07 UTC Received: from exchange.fintech.ru (e10edge.fintech.ru [195.54.195.159]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3A8C510E0F3; Mon, 26 Dec 2022 18:16:07 +0000 (UTC) Received: from Ex16-01.fintech.ru (10.0.10.18) by exchange.fintech.ru (195.54.195.169) with Microsoft SMTP Server (TLS) id 14.3.498.0; Mon, 26 Dec 2022 21:10:28 +0300 Received: from localhost (10.0.253.157) by Ex16-01.fintech.ru (10.0.10.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Mon, 26 Dec 2022 21:10:28 +0300 From: Nikita Zhandarovich To: Alex Deucher Subject: [PATCH] drm/radeon: Fix potential null-ptr-deref Date: Mon, 26 Dec 2022 10:10:23 -0800 Message-ID: <20221226181023.86196-1-n.zhandarovich@fintech.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.0.253.157] X-ClientProxiedBy: Ex16-01.fintech.ru (10.0.10.18) To Ex16-01.fintech.ru (10.0.10.18) X-Mailman-Approved-At: Wed, 28 Dec 2022 11:16:34 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nikita Zhandarovich , "Pan, Xinhui" , linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, =?utf-8?q?C?= =?utf-8?q?hristian_K=C3=B6nig?= , lvc-project@linuxtesting.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" radeon_get_connector_for_encoder() assigns radeon_encoder->enc_priv to mst_enc which is dereferenced later without being checked for NULL beforehand. It is possible for radeon_encoder->enc_priv and therefore mst_enc, to be NULL due to potential lack of memory. This patch adds a sanity NULL-check to prevent the issue. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 9843ead08f18 ("drm/radeon: add DisplayPort MST support (v2)") Signed-off-by: Nikita Zhandarovich --- drivers/gpu/drm/radeon/radeon_encoders.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/radeon/radeon_encoders.c b/drivers/gpu/drm/radeon/radeon_encoders.c index 46549d5179ee..3f68f0af443a 100644 --- a/drivers/gpu/drm/radeon/radeon_encoders.c +++ b/drivers/gpu/drm/radeon/radeon_encoders.c @@ -251,6 +251,9 @@ radeon_get_connector_for_encoder(struct drm_encoder *encoder) continue; mst_enc = radeon_encoder->enc_priv; + if (!mst_enc) + return NULL; + if (mst_enc->connector == radeon_connector->mst_port) return connector; } else if (radeon_encoder->active_device & radeon_connector->devices)