Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3551761pxb; Mon, 24 Jan 2022 12:03:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJzAdH2Vp9k62G/iuOEf45mn8QeKjHKDJoRy4O2SvL2eFOu5x4N0njpzo8zffhlqikTRWY8E X-Received: by 2002:a17:90a:7604:: with SMTP id s4mr3411173pjk.69.1643054581982; Mon, 24 Jan 2022 12:03:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643054581; cv=none; d=google.com; s=arc-20160816; b=VU5BLjjrXdvounv/hoIDfG2DkIIw/VyjL5qJwwgxRe3j6eL4ESInbJUPBTSezOAKCX svCUqbTr6JjuTl9X3/+9U8VxKGRjQtznCxKXgnt2lZQDPdx1WYKc6Bf43fPKn9m45kJ5 JPE1Nqc0zdyuqzH2k/vnO4cNKUC9VmE26M7G08hhjFVWIF4P6D93XRQ+MkUCaPNQSnK8 0RyWWa9+OgSu5eDRbu2pTH+ZVJuT3pZ4Nz7cM0Em2dI8YJngeb/b2LRRQ6eZeCSL17tP kLvU5/QE9jMS0t/tMiZ3XVJWdnb/Ksoh8iJT20C73bpk6/ngx78a1kNsiKVddqGjNhaz DFzg== 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=14z5c2Bj/EL8V6CHkt/EqHqJ6ubaugU6V/v26DOcAdI=; b=zutoIFoc4d8izDYCB/ZKgbhNU0/ZT+XzovtqSStKxJdGEohutE+uFd3P7E8djp5fXB 01Poue0Vv5pfd+L155gU2CoarWIvP1pGNGEj+E76bO0/I27OLW7NVldUbRA+cccrXePx FakZZaUZGrmndp2NM+iWqfFsxqc3EKKeU63tHAIUeVUwdzHiI1ajs7+VbbJ2tVKZTQsR UHqDdeA/jCF9fEaPsqH+4d3tTutpe4Wn2Jwh0/sON4tI1HqWvPTOLTIy3xgWcY+r+grD bLR3+W3HIG7VPzeTZxKc5IrgzgpTYoJ8ntJKuznFvdubjdgqXOYHMuyBtisweR74WePR 6GEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=i+UM0CuJ; 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 v202si6389710pgb.401.2022.01.24.12.02.50; Mon, 24 Jan 2022 12:03:01 -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=i+UM0CuJ; 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 S1344897AbiAXTCT (ORCPT + 99 others); Mon, 24 Jan 2022 14:02:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344652AbiAXS6r (ORCPT ); Mon, 24 Jan 2022 13:58:47 -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 CC5FFC0613AA; Mon, 24 Jan 2022 10:55:58 -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 92211B81232; Mon, 24 Jan 2022 18:55:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6AC1C340E5; Mon, 24 Jan 2022 18:55:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643050556; bh=D7sd48NRqJ8w9AVxw+DsqmoMe7eXTNl0cdZocun+HFk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i+UM0CuJfWjU1W7h/xt62S/0ibSW8xkWTAnJVT2350Vs17PWdgaSYnjliFYo1ClQ9 +mh9lJsRZQ2xvG5y0aGagQZmSeASJWYPL7cmd6DfFNxGgfdSP1daOlcXuMiuECYqww MLTaqjteRc86rLkgZ+Sy4Oo41MDxgjQMwTK0SYic= 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.9 038/157] drm/amdgpu: Fix a NULL pointer dereference in amdgpu_connector_lcd_native_mode() Date: Mon, 24 Jan 2022 19:42:08 +0100 Message-Id: <20220124183934.010734423@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183932.787526760@linuxfoundation.org> References: <20220124183932.787526760@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 eb79d0d3d34f1..7264169d5f2a7 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