Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3564547pxb; Mon, 24 Jan 2022 12:19:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJw8/tYo2A3/awSL1Wxw9u4uqHv04GuUOHXnsopcXkwx4etPAyVKaDyZyXI5Pa47TXs9EsTm X-Received: by 2002:a17:902:c40d:b0:14a:96a4:1044 with SMTP id k13-20020a170902c40d00b0014a96a41044mr15971258plk.50.1643055474316; Mon, 24 Jan 2022 12:17:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643055474; cv=none; d=google.com; s=arc-20160816; b=zf02arvkzLxykP1jRqGav1ZKBDmJ16yFnaCMPbu4PXlKf6yr/9xJ1wCHO8pVsBV1LA buaUtRWkApf6J00PAyxK560YDdrtxqWJDqho3tf0xvrUW+QBeR/IPOx85iLM6XdOR+qD lkKBYfcd5h7P0bdcOsuZHrS9xIxF1uTPKs3RQUlV1Nbx/zFaBLMyHDyXAZodMIqEwBmv E5nZtLDx1HlzVgZfM0bFOsJSVaGEA7/T6hwbDpOiXlLrhlEo6Epo8KryuK4U0b5HPoGH 4KunPc+VAzx/UGImpwWSN6E3GB4An61r+yHZrTV9kf8cotzVfkIlrHLO0mRI64hvqIzp u1JA== 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=RQEXJ304qdraY6l+41VdhGS5W8Mb6rHIYNWw1dd7Cg4=; b=mcgilMh9l6jfPWe0aEtk45ghcPdKZ8NFwg2IuSNLTQxWQyGLNZocgjIbAFdtLU71AU zfvmrdJh8EFI4fd6CnSUZLtq/urEaq/KC1z3ehB9QUdUrP3ZIL+S++92ZPBDAUGYJSHn gWJSnldSP5qoziBDhxApXaTQxuu26/1WRwmKBMLOsX8+1awtFl6TCC0ZcQazQsKwvEba AySpVl+vAcSM424BwvULB8KxnlgCcSXDWpecU2M+awHXicdwIkyiMzuE/RXNnpjcwRpC TG0jhv8eV81r1+emjmwbqodnjXvpiZRu4GQHMIAQyvPV1L+gZfe2yt+rh0qRvzHsvSGk 4uaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="yt9/RG1z"; 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 q9si16301760plx.119.2022.01.24.12.17.42; Mon, 24 Jan 2022 12:17:54 -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="yt9/RG1z"; 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 S1343983AbiAXTVa (ORCPT + 99 others); Mon, 24 Jan 2022 14:21:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347528AbiAXTNP (ORCPT ); Mon, 24 Jan 2022 14:13:15 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12AB0C08EAD5; Mon, 24 Jan 2022 11:04:35 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CE99CB8121C; Mon, 24 Jan 2022 19:04:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E18FDC340E5; Mon, 24 Jan 2022 19:04:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643051072; bh=1mrzt70eK8Bpjwb9bz0Zpesg7wK3CuPqN4GrLE1sW2U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yt9/RG1zBXnpiHnxprVBg5m76cg8F51Qpluk7k2kIpgIAMbJGluc0AOgwAx+QBYNG 8zVrGIyUUWrGBgm5ozozobtGCI6CFrrETgertClfOO1l9iM2mYy1sStmIyBlVXr9e6 JeWXMomhFVqiS6rIu85fZ7y1FYzIsQMrtux7YYwQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhou Qingyang , Alex Deucher , Sasha Levin Subject: [PATCH 4.14 046/186] drm/amdgpu: Fix a NULL pointer dereference in amdgpu_connector_lcd_native_mode() Date: Mon, 24 Jan 2022 19:42:01 +0100 Message-Id: <20220124183938.612322753@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183937.101330125@linuxfoundation.org> References: <20220124183937.101330125@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: Zhou Qingyang [ Upstream commit b220110e4cd442156f36e1d9b4914bb9e87b0d00 ] In amdgpu_connector_lcd_native_mode(), the return value of drm_mode_duplicate() is assigned to mode, and there is a dereference of it in amdgpu_connector_lcd_native_mode(), which will lead to a NULL pointer dereference on failure of drm_mode_duplicate(). Fix this bug add a check of mode. This bug was found by a static analyzer. The analysis employs differential checking to identify inconsistent security operations (e.g., checks or kfrees) between two code paths and confirms that the inconsistent operations are not recovered in the current function or the callers, so they constitute bugs. Note that, as a bug found by static analysis, it can be a false positive or hard to trigger. Multiple researchers have cross-reviewed the bug. Builds with CONFIG_DRM_AMDGPU=m show no new warnings, and our static analyzer no longer warns about this code. Fixes: d38ceaf99ed0 ("drm/amdgpu: add core driver (v4)") Signed-off-by: Zhou Qingyang Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c index 54f414279037e..0894bb98dc517 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c @@ -404,6 +404,9 @@ amdgpu_connector_lcd_native_mode(struct drm_encoder *encoder) native_mode->vdisplay != 0 && native_mode->clock != 0) { mode = drm_mode_duplicate(dev, native_mode); + if (!mode) + return NULL; + mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER; drm_mode_set_name(mode); @@ -418,6 +421,9 @@ amdgpu_connector_lcd_native_mode(struct drm_encoder *encoder) * simpler. */ mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false); + if (!mode) + return NULL; + mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER; DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name); } -- 2.34.1