Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3696187pxb; Mon, 24 Jan 2022 15:37:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJyXJt4aBGbXY28uw29jmdv+lT6yS69kMRbEdMf9n9gR3ddnEWovDSbSd8xLHLqqf4kScdTf X-Received: by 2002:a63:5c10:: with SMTP id q16mr12978004pgb.430.1643067452064; Mon, 24 Jan 2022 15:37:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643067452; cv=none; d=google.com; s=arc-20160816; b=wy1uDdkiWitvBHxvl3doepIH4A8B7Q1XReyXfHSxpvvHlVLeON6tuv1Vc0JnFtpon6 L4+0sc1Q0qF+9B0X6QkQACfsunvgGZOq4h19++SiB5CxF1d1cjFtMhSnMbBCZz9lKWH2 mqXCf2ff4R76nB6h9a8cXpRLq91sfcQl0wh8XfeoWyTxjqc/9VKkNkQNKpJBS0rFwn5k UrDhFTp9tHk9yeHcD8fV+NHPvVuDV7avcLTI9bDCwmIPzeoBXmUbmopLFFdpA4Uv8hO9 uPV4J2aZ2MO6YeO/+mbahBdXWsv1aGxzD/BUhlkMMpdCXjQHe8p6IrX6Rq4zwSdP/8fp opJA== 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=biVOBQPF33jrue+Fj1lsqe3XfVxKq+E8c65bzg1iWTc=; b=U4jJqaOqD/ysVDVs7g7ELF95k6B2GxU8rTH9wup8mPBbP1hav8RbH+m03agyY1E8+N Q/TQQjsmu1Fx40E+L9z7mVCIpJcrEWZzO9bUDeeboGvh3SD0DLTazA5DzjXkWizGoIQC Ii4kHDfblmBqpAs1l0WaeGezZWTMShSiZv1NPx5+w0YMoHw1BwbIUAVoGHIdtSlt70VP cRm2IZuipWQg7uw8pseAO/L1F+3txXNY3q1EnHi7saE/c5Km+a/7NMF3w6tzhWbxCjnq O7VeE501Cw8V0wl3mcGSgdOJ95pVXE+v+D0ZEwS/R3Sw7YMKZRAuMaK8pOzej4aHopCF /igg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PWNkcRAK; 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 d15si669336pjd.35.2022.01.24.15.37.19; Mon, 24 Jan 2022 15:37:32 -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=PWNkcRAK; 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 S2359555AbiAXXcw (ORCPT + 99 others); Mon, 24 Jan 2022 18:32:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353814AbiAXWjs (ORCPT ); Mon, 24 Jan 2022 17:39:48 -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 F1F45C055A89; Mon, 24 Jan 2022 13:03:27 -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 A726DB80FA3; Mon, 24 Jan 2022 21:03:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C70C9C340E5; Mon, 24 Jan 2022 21:03:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058205; bh=FCtfFY34iZEwAr7Qu9zfh7qbShfAkumL+e4sa31RBqc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PWNkcRAKYbjBtv1hch0EUCVCEF41O/GnF2p3DbHRUMdH9ofz+Qveyf+17pY/9rAoR 0lKiQE4U00MAOStlxXXMjEb6j7tvymLtoQdRy2c/jOC2gg9UoitSQAK7Syg4UYwkef 2rL8E+c0BtMqw+gmbMX4kyVdMFpMtaZH4VimxbsQ= 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 5.16 0213/1039] drm/amdgpu: Fix a NULL pointer dereference in amdgpu_connector_lcd_native_mode() Date: Mon, 24 Jan 2022 19:33:22 +0100 Message-Id: <20220124184132.500814873@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 0de66f59adb8a..df1f9b88a53f9 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c @@ -387,6 +387,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); @@ -401,6 +404,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