Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp652414pxv; Thu, 15 Jul 2021 12:31:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztQDOler+kZogwbDC2pOu6Fm8n8uOUSOlFtxaIuO3UQ3C+BrpvrcgkzDRX4qAx7VrJzTS4 X-Received: by 2002:a05:6402:14d4:: with SMTP id f20mr9355536edx.316.1626377517222; Thu, 15 Jul 2021 12:31:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626377517; cv=none; d=google.com; s=arc-20160816; b=ONhGJCZbSJM4U1HJ+OqFY0IEGjBb0HSQ/1oqz5Yi5BYbjGRWnWgtPsvIuU/fLfBLNX HbTUFeAjxc6X9iU0ZSkYM4iW8yMCvxMoGkaWQoi8kuK46SoN5pHqMHSMRpJMQEhAVVMq qB4Zb4RjdWiU3MQ/MXgYxNkIuMCCHu/H0HA8y4ZhyeVayZIzekxUamOySy6Eu0T/HBiw FJcbFx54yAah6a/L0AsWM8Ii8+2P+aEkcc8tOSACGCOE5fRw9Kbgrsr2OWnorpvLheOi 2QZOj++5A7PUlxuUBRlC7nnLgLHCOECYo4u8kTntOkWjZP5fHfxzpsHmBTrQgdB9x2gc VgYg== 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=H/xyx3bBW5/kLhoQCa8iAlKHfV4vgrHQkIOXetSKjRY=; b=izFTb7TzL05P4PHxyyiaGEtGNuRlVYe5cAwhiIAWHlVkCS4bcPCe6aIkv8kPp2vEFY y+jLXnRD59sMDzojmMlDpFDv6HGTS9zgB14EwUYdGn34bWrSmJno9VOAe6Z8xy/O8Q17 Q9TIkrPp3oMo0HRuMEQAd/fHdlLJRQf5t4Fpn0wBVp+UVMmu7x7T7TZsPNytr5AqBFxp 3g4bUhZ/KxtRCTyeMYa0vMb/ZyPZSP2e6sMuceq2CBtcRGdLCIjy0zXLofQXRc94PFKJ /DINLPFUdL09PUTUDg1OQkGdSJog4jIRzhLc48SB51IoHl1wOkXXMM+ACcyk2RB1saxF rcsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KUIGBwWJ; 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 h3si5904508ede.293.2021.07.15.12.31.34; Thu, 15 Jul 2021 12:31:57 -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=KUIGBwWJ; 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 S243791AbhGOTcH (ORCPT + 99 others); Thu, 15 Jul 2021 15:32:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:46432 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243892AbhGOTKL (ORCPT ); Thu, 15 Jul 2021 15:10:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C498B613D3; Thu, 15 Jul 2021 19:07:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626376031; bh=36scWzxnOhleVw0nlD7brhnNhM6GRAFZzLUvFN94PkQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KUIGBwWJXNKdJYoE3gg2sgkob+exvr7qW71eM4A1cpiOl1SBbrp0bkHknp0FABe6q zsFRB2p0wV0Z/hqCE1GgI3fARpjsNhbw/wsES8WIeywmUYOVmPJwloLtVIVfJBJUOi J9K5YcJsRhq/QocJTdoSOrvEDGyZQw/zwvc1M+SY= 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.13 097/266] drm/amd/display: Verify Gamma & Degamma LUT sizes in amdgpu_dm_atomic_check Date: Thu, 15 Jul 2021 20:37:32 +0200 Message-Id: <20210715182631.206095251@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182613.933608881@linuxfoundation.org> References: <20210715182613.933608881@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 b11d90ea8c37..f2866a625f80 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -10049,6 +10049,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 b2f2ccfc20bb..c8e5bbbb8bce 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h @@ -591,6 +591,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