Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3583812pxb; Mon, 24 Jan 2022 12:49:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJxwbRzFoSlbpCZxCdmWUyjL+SZ14kT+lQEcW+zgyoIt0ueTfnV99fQO1yg0jjPXSA0pPYdi X-Received: by 2002:a63:40c5:: with SMTP id n188mr13083767pga.118.1643057359125; Mon, 24 Jan 2022 12:49:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643057359; cv=none; d=google.com; s=arc-20160816; b=PmO9iZrW6puWWzBt40yCYCNKRdeX23bu+oo90lE/XrHP3NIMIOMknjgW8LPKxlphml nJFcWzOx4d4mn/ocKL83xsVFga9K8unubl87qJLe9uiGoMAFJO9NjbwWy4KBVZKkcGeB Cz4UvhyCYT3wWXyLzBMRSo4Xs14f8ZHK5Wk1Uz4AL3mUZYzOoqG4OvsMH/JYRlOapymv zo41BP8m4vRSm6AdFcGOOJNTXqi6uVp1U+kNIUIpufBk5G380NBMtISGb33pgYLVgyxP sWQPuapLhkCNH8jY5Tk8wiGpCombH+OK91kBFLQvqqP1rFDP3fm5TXRleyDC5zRr5ARv zOAg== 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=1J4rN8mG/NYV7Nm2y2nxp6oxr9Cx0Zty8K0+gDWXITSEh5f9LxbIWXiq+irooqNmRg PK4BW1sK3FDmA9FrU58EOaTL+GK+Gt+I41vpqqBLNExls8fPWm1o43q4fJ3qT8rtcqnB H57DfEkPosjttue/FxH8sw5D1G7OL/fMtk7PFj0M96aFhZ+WoZUEetptNKLx+q2jaKjL +cXANmyA3TgI3S1TcvqOiC49HkAfy1cjwEOowF8MTn8cNYI1CgUWA4XCFxWlD8ur8F3N nIlTP3fVM17EusT8t+iUHV3JcDKICITsrWocFZ9ZKBq1mprcdv88qtX3Q7Xz4dmJ93vY LQLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=i4eWQ5Uz; 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 z4si13842470pge.854.2022.01.24.12.49.07; Mon, 24 Jan 2022 12:49:19 -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=i4eWQ5Uz; 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 S1377021AbiAXUEs (ORCPT + 99 others); Mon, 24 Jan 2022 15:04:48 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:44236 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356679AbiAXTrC (ORCPT ); Mon, 24 Jan 2022 14:47:02 -0500 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 dfw.source.kernel.org (Postfix) with ESMTPS id 7F1196154E; Mon, 24 Jan 2022 19:47:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58F1EC340E5; Mon, 24 Jan 2022 19:47:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643053620; bh=FCtfFY34iZEwAr7Qu9zfh7qbShfAkumL+e4sa31RBqc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i4eWQ5Uzipr0o2KXi+umApYeWrZQQozPShsC/iTD1jhjzm5n1KpX92u1+8vS9y0kc c2XaLwKYTDVYlduJI92zKqwz/RW3vlpds/UFzqcePD3wJW4wQ4Vy/sgDWrNA9VHGge /mxM1aZq82t19UHlKUZtFKD+PVZ3kL7nm2eMfJjk= 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.10 123/563] drm/amdgpu: Fix a NULL pointer dereference in amdgpu_connector_lcd_native_mode() Date: Mon, 24 Jan 2022 19:38:08 +0100 Message-Id: <20220124184028.654486911@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184024.407936072@linuxfoundation.org> References: <20220124184024.407936072@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