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: 36683 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1037116wrt; Mon, 26 Dec 2022 10:20:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXvbrREJh6eTSHU1q04FKecWu+FyzQpXh+z027k47LBHE24u9oYnUeg+dLYI1nxKr689q7/4 X-Received: by 2002:aa7:c69a:0:b0:461:aeeb:9ce1 with SMTP id n26-20020aa7c69a000000b00461aeeb9ce1mr15625320edq.32.1672078817941; Mon, 26 Dec 2022 10:20:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672078817; cv=none; d=google.com; s=arc-20160816; b=nH8R5pnsaI2AZgm8linCsrW1RuRD+6z0M27uLOmrT48v1MaV3XZMmH8NwPteua65AF OfweEmZNwEmSW4WVgert6SJWxy5aiil21d4vGTilyMkSMqP7h2HE1fSUqqvaWrHyDdYe qZ+tTcMd9rY30q7sRgt3ere3DiZOaRxH/vmF1lew8J8kTrJEvH5m4Mozs31YwZO891+v TjyRCHKaNqrcPYJAXkBlNDt5mVWhmuMx7l5O5zHI2RdRlctNgPX7N+vVDDIYw6ZIk2xM Y56/MKiB30v63F/+RinaY+c7LWAOxiMbXbRx2bqCJyx/1pgGz4Bbm31iA/4b1pJJ233B 7IrQ== 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 :message-id:date:subject:cc:to:from; bh=AqDPoQWvbaQSGLfrVkqG7P++8l+M1le+ZTLpG7rbL+A=; b=LFOieVMU+jg707wXYakE0Gq/KBCtwtb5MMFwm7UdfWiViLxCpMtU2PZOCQ7r6FGI0V aJ3YbKMSQMqAJ7AIrARwOk0gj0lVhspvGmIT08PVzr1XdPKxObqgJSt5rMr/Q9ByEJNF IeniE95zCHIFLtH4IlfKBTj1qW0qQzTMq3T2orvyjvKhnU7MyIqXU7USTM8m05rHaf/O 5S+If1PHkNCr0+LlvIWB+i7KIbjeO8/lVdWdso6+PCMxYhWwRNNOSO96/3ZJDO3OCEYg nPzShTGyfaoJIAszsd45Ior5cXB40c2qLY4XM/mtSC3EWSLvIa1Bl29MPATAi4bncYGo ZTcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v18-20020a056402349200b0047b405e7746si10018297edc.1.2022.12.26.10.19.54; Mon, 26 Dec 2022 10:20:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232238AbiLZSMD (ORCPT + 99 others); Mon, 26 Dec 2022 13:12:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231422AbiLZSLk (ORCPT ); Mon, 26 Dec 2022 13:11:40 -0500 Received: from exchange.fintech.ru (e10edge.fintech.ru [195.54.195.159]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C582218B for ; Mon, 26 Dec 2022 10:11:35 -0800 (PST) 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 CC: Nikita Zhandarovich , =?utf-8?q?Christian_K?= =?utf-8?q?=C3=B6nig?= , "Pan, Xinhui" , Daniel Vetter , , , , 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753301718972093171?= X-GMAIL-MSGID: =?utf-8?q?1753301718972093171?= 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)