Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp628072pxv; Thu, 15 Jul 2021 11:55:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwC0zlNKfMntNcHVT4x/AVyn7oOtYyYw9ihSTKw0gxG6L4AiQPfiD1pQztWjyH+6IofHnzH X-Received: by 2002:a92:190e:: with SMTP id 14mr3503349ilz.70.1626375334606; Thu, 15 Jul 2021 11:55:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626375334; cv=none; d=google.com; s=arc-20160816; b=UXRl6Q5NpPybOg8qxh5RlNxsFv9M2wBgRQPAvmoTwNSCe+krWITWx5hHB8f1HOeeaf CV2aslY8WbBeskP6ZYotc3mGsBZVC0D7cL6nIpNgSYJuxpaI9v0zeQSH99PA2/2Vp5Oo udWWpkAZ0bmqy6ChweHeT42BdT1h1JNY8AW7Lpv6KDBi3CVOVxBquje18XW1oKdgkmLf Q0qRYPbOao4xU8uvHKNLBTSO47ESa3x21/+B3jPX276WGNTfmv3MlC596lwIARd/iv6q udQOnFYmyQVzHmIddCV4VuD+g2qZ2bqxY7aJCe1wGe4mZA0tpiLon0bX68g2VgM3De8w ABSg== 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=l8Z6dcdpK/kjRU+MymKfVDWWS82vc7B6lSTH4vnalf0=; b=VB52y6WzvxOnEASxINzhcb56nvB0Ykj8nLVXOE5G3Lpp1WHW7XX9RQwp3/g+WYyquN 8Tx3Oli39uD443Z/NKPMZSV2A8gjdeUSaOyPiQiDupjCOkUFDHGf1uJvrweG/jI5t547 r8PADrgqtt0bzXUeP/93ya4O1AfuD4G69eY80WlK8PZAjtCOI+FQHpkICx6kRSNW3+YJ MJR/gaiXKk2sUPlMaTImKtPFIkeMgzfm89wHp/6RIp6Xg3BMSDnbZV5kSshnddT6O3+Z 04V5HEFa19Oelx56/qquMeSNOsUOFBu/UFoVGcoddIXiPuVsKo+6MeiDRo9k/XMsa/mu CA9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xfeKKiAQ; 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 d1si5509523jak.77.2021.07.15.11.55.22; Thu, 15 Jul 2021 11:55:34 -0700 (PDT) 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=xfeKKiAQ; 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 S242055AbhGOS4q (ORCPT + 99 others); Thu, 15 Jul 2021 14:56:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:54496 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231390AbhGOSvV (ORCPT ); Thu, 15 Jul 2021 14:51:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 76D76613EB; Thu, 15 Jul 2021 18:48:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626374905; bh=sw1Mjaqo8v/gCUu1GMZxhFsM9wftk0TLQ674ix8g2fA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xfeKKiAQctwtsQuMghtALdan2JtIwIhlcnNlW/3c3n56SEjjpjm8OLDKroUbj6Z2n 1U8OuIosiRORc75ngBvcT0ctHMgqrjfmi2cPnNdk9EBop5Mlga1Jo4GoimT37AZgY3 1q4EEoy/XGxYhtfshcSXrpgjkUhHdBrOEO6K5z9Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Harry Wentland , Mark Yacoub , Alex Deucher , Sasha Levin Subject: [PATCH 5.10 076/215] drm/amd/display: Verify Gamma & Degamma LUT sizes in amdgpu_dm_atomic_check Date: Thu, 15 Jul 2021 20:37:28 +0200 Message-Id: <20210715182612.902107638@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182558.381078833@linuxfoundation.org> References: <20210715182558.381078833@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: Mark Yacoub [ Upstream commit 03fc4cf45d30533d54f0f4ebc02aacfa12f52ce2 ] For each CRTC state, check the size of Gamma and Degamma LUTs so unexpected and larger sizes wouldn't slip through. TEST: IGT:kms_color::pipe-invalid-gamma-lut-sizes v2: fix assignments in if clauses, Mark's email. Reviewed-by: Harry Wentland Signed-off-by: Mark Yacoub Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 ++ .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 1 + .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 41 ++++++++++++++++--- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index b413a7a2e92f..bdcec5b3f5e5 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -8745,6 +8745,10 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev, old_crtc_state->vrr_enabled == new_crtc_state->vrr_enabled) continue; + ret = amdgpu_dm_verify_lut_sizes(new_crtc_state); + if (ret) + goto fail; + if (!new_crtc_state->enable) continue; diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h index 1df7f1b18049..6c7235bb2f41 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h @@ -498,6 +498,7 @@ void amdgpu_dm_trigger_timing_sync(struct drm_device *dev); #define MAX_COLOR_LEGACY_LUT_ENTRIES 256 void amdgpu_dm_init_color_mod(void); +int amdgpu_dm_verify_lut_sizes(const struct drm_crtc_state *crtc_state); int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc); int amdgpu_dm_update_plane_color_mgmt(struct dm_crtc_state *crtc, struct dc_plane_state *dc_plane_state); diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c index 5df05f0d18bc..179ff4b42f20 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c @@ -284,6 +284,37 @@ static int __set_input_tf(struct dc_transfer_func *func, return res ? 0 : -ENOMEM; } +/** + * Verifies that the Degamma and Gamma LUTs attached to the |crtc_state| are of + * the expected size. + * Returns 0 on success. + */ +int amdgpu_dm_verify_lut_sizes(const struct drm_crtc_state *crtc_state) +{ + const struct drm_color_lut *lut = NULL; + uint32_t size = 0; + + lut = __extract_blob_lut(crtc_state->degamma_lut, &size); + if (lut && size != MAX_COLOR_LUT_ENTRIES) { + DRM_DEBUG_DRIVER( + "Invalid Degamma LUT size. Should be %u but got %u.\n", + MAX_COLOR_LUT_ENTRIES, size); + return -EINVAL; + } + + lut = __extract_blob_lut(crtc_state->gamma_lut, &size); + if (lut && size != MAX_COLOR_LUT_ENTRIES && + size != MAX_COLOR_LEGACY_LUT_ENTRIES) { + DRM_DEBUG_DRIVER( + "Invalid Gamma LUT size. Should be %u (or %u for legacy) but got %u.\n", + MAX_COLOR_LUT_ENTRIES, MAX_COLOR_LEGACY_LUT_ENTRIES, + size); + return -EINVAL; + } + + return 0; +} + /** * amdgpu_dm_update_crtc_color_mgmt: Maps DRM color management to DC stream. * @crtc: amdgpu_dm crtc state @@ -317,14 +348,12 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc) bool is_legacy; int r; - degamma_lut = __extract_blob_lut(crtc->base.degamma_lut, °amma_size); - if (degamma_lut && degamma_size != MAX_COLOR_LUT_ENTRIES) - return -EINVAL; + r = amdgpu_dm_verify_lut_sizes(&crtc->base); + if (r) + return r; + degamma_lut = __extract_blob_lut(crtc->base.degamma_lut, °amma_size); regamma_lut = __extract_blob_lut(crtc->base.gamma_lut, ®amma_size); - if (regamma_lut && regamma_size != MAX_COLOR_LUT_ENTRIES && - regamma_size != MAX_COLOR_LEGACY_LUT_ENTRIES) - return -EINVAL; has_degamma = degamma_lut && !__is_lut_linear(degamma_lut, degamma_size); -- 2.30.2