Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp639030pxv; Thu, 15 Jul 2021 12:10:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCkHv8/xmvrtlf4g9UtM/hG69evoAg0waMvFE+LwxF8eAKfZQkaMS2miJdowxCHfG5JCmj X-Received: by 2002:a05:6638:248d:: with SMTP id x13mr5369299jat.78.1626376235554; Thu, 15 Jul 2021 12:10:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626376235; cv=none; d=google.com; s=arc-20160816; b=Dtgd/CLz7mG2HJdIhdV2j6RhYouAzH4wb5uOwN24VASB5ksn/e2K0WcYs35/3EI3vs KXAfOp9k8MNI1q7YOyYi2fgzxMHhhgPvI89WcUjQcOcgE9XbwvaVLySP9Iyf85Uhinh2 lDI8u4trQRc9n6rNUK1mv4Uxrjito8G8/QHTRbLBHU4h+suotJNDiiPAwut/iZxRWilq 5CZOtxMr3CNh3ul6914bDh4INAnMgotT0yxUbCEgWyS8BhEZgC3962MvYAFzeUvcZ8ag vOJN49cazFe84TGJBGN+gSXBM1sT1ylq730ff6Cae81D/2RvNjxmnYfLQ2kn5KKSqG4L ET/Q== 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=zuCe6KWP7udXJs65ZAU+DHI6UyRoVYm4hakFrd+tRY8=; b=wzGICWKbh3ZbTU0Pdi3XzUyrMoGp3krYHe3v5tqMUPcIjgy1y/fla4A6UAh4mNAOHw sj8A/2kFzfBv/YWA5rnzowvABz8ws8u6wUyPRIjpHbQDZNlEn9j+YRR4Ue+vBqKD07qs iKUG70hRsvOmNw1TUTbnXRI8ALeT8ATYYAJbmCrw4EVadino4Jpzav7xgmeFfxeoiMKk ltSMJpWN51EYdGU8vr+FEqDueLzurcxQdTUlcPCwn7XDfBkg2ydR8dyBsAFeBzgBpSHV a5254mmWwQtf3cHPqgTxOxubgG2p29uuv/JpiJ7+/BFAcWtRSrZoA/ODZUVElv1TmCC8 zM1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="otqL3BW/"; 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 l3si7638978iln.80.2021.07.15.12.10.22; Thu, 15 Jul 2021 12:10:35 -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="otqL3BW/"; 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 S243744AbhGOTLw (ORCPT + 99 others); Thu, 15 Jul 2021 15:11:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:34728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242810AbhGOTAA (ORCPT ); Thu, 15 Jul 2021 15:00:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E3025613CA; Thu, 15 Jul 2021 18:57:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375426; bh=THI9QLUWClfatIo+BfkGyKGMgv1jPdvoSd4hdNxOijY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=otqL3BW/kevWTjQhHmduE2UXOqmLMEW/+a+19OyfwunHdAfDDMlLGmYRg2rkovK/0 d5ZO0xU7weFTcOVHW6fI3OGMtQ/FivUdB8fPl2yGaUN99lrgtUTZ64W29EJWFOp+eg vXEouPEQaxFZ8dGs44inex2Wtbu8aEnD3sGyot90= 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.12 083/242] drm/amd/display: Verify Gamma & Degamma LUT sizes in amdgpu_dm_atomic_check Date: Thu, 15 Jul 2021 20:37:25 +0200 Message-Id: <20210715182607.622353924@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@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 74e74971df74..817d701a9857 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -9499,6 +9499,10 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev, dm_old_crtc_state->dsc_force_changed == false) 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 52cc81705280..250adc92dfd0 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h @@ -529,6 +529,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 157fe4efbb59..a022e5bb30a5 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