<div dir="ltr">Ignore this patch, in favor of (<a href="https://patchwork.freedesktop.org/series/91023/">https://patchwork.freedesktop.org/series/91023/</a>), which appends the commit title with drm/amd/display.</div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jun 4, 2021 at 12:59 PM Mark Yacoub <<a href="mailto:markyacoub@chromium.org">markyacoub@chromium.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">From: Mark Yacoub <<a href="mailto:markyacoub@google.com" target="_blank">markyacoub@google.com</a>><br>
<br>
For each CRTC state, check the size of Gamma and Degamma LUTs  so<br>
unexpected and larger sizes wouldn't slip through.<br>
<br>
TEST: IGT:kms_color::pipe-invalid-gamma-lut-sizes<br>
<br>
Signed-off-by: Mark Yacoub <<a href="mailto:markyacoub@chromium.org" target="_blank">markyacoub@chromium.org</a>><br>
---<br>
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  3 ++<br>
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  1 +<br>
 .../amd/display/amdgpu_dm/amdgpu_dm_color.c   | 40 ++++++++++++++++---<br>
 3 files changed, 38 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c<br>
index 38d497d30dba8..f6cd522b42a80 100644<br>
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c<br>
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c<br>
@@ -9402,6 +9402,9 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,<br>
                        dm_old_crtc_state->dsc_force_changed == false)<br>
                        continue;<br>
<br>
+               if ((ret = amdgpu_dm_verify_lut_sizes(new_crtc_state)))<br>
+                       goto fail;<br>
+<br>
                if (!new_crtc_state->enable)<br>
                        continue;<br>
<br>
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h<br>
index 8bfe901cf2374..1b77cd2612691 100644<br>
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h<br>
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h<br>
@@ -541,6 +541,7 @@ void amdgpu_dm_trigger_timing_sync(struct drm_device *dev);<br>
 #define MAX_COLOR_LEGACY_LUT_ENTRIES 256<br>
<br>
 void amdgpu_dm_init_color_mod(void);<br>
+int amdgpu_dm_verify_lut_sizes(const struct drm_crtc_state *crtc_state);<br>
 int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc);<br>
 int amdgpu_dm_update_plane_color_mgmt(struct dm_crtc_state *crtc,<br>
                                      struct dc_plane_state *dc_plane_state);<br>
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<br>
index 157fe4efbb599..da6f9fcc0b415 100644<br>
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c<br>
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c<br>
@@ -284,6 +284,37 @@ static int __set_input_tf(struct dc_transfer_func *func,<br>
        return res ? 0 : -ENOMEM;<br>
 }<br>
<br>
+/**<br>
+ * Verifies that the Degamma and Gamma LUTs attached to the |crtc_state| are of<br>
+ * the expected size.<br>
+ * Returns 0 on success.<br>
+ */<br>
+int amdgpu_dm_verify_lut_sizes(const struct drm_crtc_state *crtc_state)<br>
+{<br>
+       const struct drm_color_lut *lut = NULL;<br>
+       uint32_t size = 0;<br>
+<br>
+       lut = __extract_blob_lut(crtc_state->degamma_lut, &size);<br>
+       if (lut && size != MAX_COLOR_LUT_ENTRIES) {<br>
+               DRM_DEBUG_DRIVER(<br>
+                       "Invalid Degamma LUT size. Should be %u but got %u.\n",<br>
+                       MAX_COLOR_LUT_ENTRIES, size);<br>
+               return -EINVAL;<br>
+       }<br>
+<br>
+       lut = __extract_blob_lut(crtc_state->gamma_lut, &size);<br>
+       if (lut && size != MAX_COLOR_LUT_ENTRIES &&<br>
+           size != MAX_COLOR_LEGACY_LUT_ENTRIES) {<br>
+               DRM_DEBUG_DRIVER(<br>
+                       "Invalid Gamma LUT size. Should be %u (or %u for legacy) but got %u.\n",<br>
+                       MAX_COLOR_LUT_ENTRIES, MAX_COLOR_LEGACY_LUT_ENTRIES,<br>
+                       size);<br>
+               return -EINVAL;<br>
+       }<br>
+<br>
+       return 0;<br>
+}<br>
+<br>
 /**<br>
  * amdgpu_dm_update_crtc_color_mgmt: Maps DRM color management to DC stream.<br>
  * @crtc: amdgpu_dm crtc state<br>
@@ -317,14 +348,11 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc)<br>
        bool is_legacy;<br>
        int r;<br>
<br>
-       degamma_lut = __extract_blob_lut(crtc->base.degamma_lut, &degamma_size);<br>
-       if (degamma_lut && degamma_size != MAX_COLOR_LUT_ENTRIES)<br>
-               return -EINVAL;<br>
+       if ((r = amdgpu_dm_verify_lut_sizes(&crtc->base)))<br>
+               return r;<br>
<br>
+       degamma_lut = __extract_blob_lut(crtc->base.degamma_lut, &degamma_size);<br>
        regamma_lut = __extract_blob_lut(crtc->base.gamma_lut, &regamma_size);<br>
-       if (regamma_lut && regamma_size != MAX_COLOR_LUT_ENTRIES &&<br>
-           regamma_size != MAX_COLOR_LEGACY_LUT_ENTRIES)<br>
-               return -EINVAL;<br>
<br>
        has_degamma =<br>
                degamma_lut && !__is_lut_linear(degamma_lut, degamma_size);<br>
-- <br>
2.32.0.rc1.229.g3e70b5a671-goog<br>
<br>
</blockquote></div>