linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/edid: In connector_bad_edid() cap num_of_ext by num_blocks read
@ 2021-10-05 15:10 Douglas Anderson
  2021-10-05 15:46 ` Ville Syrjälä
  0 siblings, 1 reply; 3+ messages in thread
From: Douglas Anderson @ 2021-10-05 15:10 UTC (permalink / raw)
  To: dri-devel
  Cc: Rodrigo.Siqueira, ville.syrjala, Harry.Wentland, khsieh,
	Jerry.Zuo, alexander.deucher, Douglas Anderson, Daniel Vetter,
	David Airlie, Harry Wentland, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, linux-kernel

In commit e11f5bd8228f ("drm: Add support for DP 1.4 Compliance edid
corruption test") the function connector_bad_edid() started assuming
that the memory for the EDID passed to it was big enough to hold
`edid[0x7e] + 1` blocks of data (1 extra for the base block). It
completely ignored the fact that the function was passed `num_blocks`
which indicated how much memory had been allocated for the EDID.

Let's fix this by adding a bounds check.

This is important for handling the case where there's an error in the
first block of the EDID. In that case we will call
connector_bad_edid() without having re-allocated memory based on
`edid[0x7e]`.

Fixes: e11f5bd8228f ("drm: Add support for DP 1.4 Compliance edid corruption test")
Reported-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---
This problem report came up in the context of a patch I sent out [1]
and this is my attempt at a fix. The problem predates my patch,
though. I don't personally know anything about DP compliance testing
and what should be happening here, nor do I apparently have any
hardware that actually reports a bad EDID. Thus this is just compile
tested. I'm hoping that someone here can test this and make sure it
seems OK to them.

 drivers/gpu/drm/drm_edid.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 9b19eee0e1b4..ccfa08631c57 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -1843,8 +1843,9 @@ static void connector_bad_edid(struct drm_connector *connector,
 	u8 num_of_ext = edid[0x7e];
 
 	/* Calculate real checksum for the last edid extension block data */
-	connector->real_edid_checksum =
-		drm_edid_block_checksum(edid + num_of_ext * EDID_LENGTH);
+	if (num_of_ext <= num_blocks - 1)
+		connector->real_edid_checksum =
+			drm_edid_block_checksum(edid + num_of_ext * EDID_LENGTH);
 
 	if (connector->bad_edid_counter++ && !drm_debug_enabled(DRM_UT_KMS))
 		return;
-- 
2.33.0.800.g4c38ced690-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/edid: In connector_bad_edid() cap num_of_ext by num_blocks read
  2021-10-05 15:10 [PATCH] drm/edid: In connector_bad_edid() cap num_of_ext by num_blocks read Douglas Anderson
@ 2021-10-05 15:46 ` Ville Syrjälä
  2021-10-06  2:30   ` Doug Anderson
  0 siblings, 1 reply; 3+ messages in thread
From: Ville Syrjälä @ 2021-10-05 15:46 UTC (permalink / raw)
  To: Douglas Anderson
  Cc: dri-devel, Rodrigo.Siqueira, Harry.Wentland, khsieh, Jerry.Zuo,
	alexander.deucher, Daniel Vetter, David Airlie,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	linux-kernel

On Tue, Oct 05, 2021 at 08:10:28AM -0700, Douglas Anderson wrote:
> In commit e11f5bd8228f ("drm: Add support for DP 1.4 Compliance edid
> corruption test") the function connector_bad_edid() started assuming
> that the memory for the EDID passed to it was big enough to hold
> `edid[0x7e] + 1` blocks of data (1 extra for the base block). It
> completely ignored the fact that the function was passed `num_blocks`
> which indicated how much memory had been allocated for the EDID.
> 
> Let's fix this by adding a bounds check.
> 
> This is important for handling the case where there's an error in the
> first block of the EDID. In that case we will call
> connector_bad_edid() without having re-allocated memory based on
> `edid[0x7e]`.
> 
> Fixes: e11f5bd8228f ("drm: Add support for DP 1.4 Compliance edid corruption test")
> Reported-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> ---
> This problem report came up in the context of a patch I sent out [1]
> and this is my attempt at a fix. The problem predates my patch,
> though. I don't personally know anything about DP compliance testing
> and what should be happening here, nor do I apparently have any
> hardware that actually reports a bad EDID. Thus this is just compile
> tested. I'm hoping that someone here can test this and make sure it
> seems OK to them.
> 
>  drivers/gpu/drm/drm_edid.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> index 9b19eee0e1b4..ccfa08631c57 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -1843,8 +1843,9 @@ static void connector_bad_edid(struct drm_connector *connector,
>  	u8 num_of_ext = edid[0x7e];
>  
>  	/* Calculate real checksum for the last edid extension block data */
> -	connector->real_edid_checksum =
> -		drm_edid_block_checksum(edid + num_of_ext * EDID_LENGTH);
> +	if (num_of_ext <= num_blocks - 1)

Something about that doesn't really agree with my brain.
It's correct but when I read it I can't immediately see it.

I guess what I'd like to see is something like:
last_block = edid[0x7e];
if (last_block < num_blocks)
	connector->real_edid_checksum =
		drm_edid_block_checksum(edid + last_block * EDID_LENGTH);

Techically exactly the same thing, but I don't have to read
the comparison twice to convince myself that it's correct.

Anyways, this is
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
either way.

> +		connector->real_edid_checksum =
> +			drm_edid_block_checksum(edid + num_of_ext * EDID_LENGTH);
>  
>  	if (connector->bad_edid_counter++ && !drm_debug_enabled(DRM_UT_KMS))
>  		return;
> -- 
> 2.33.0.800.g4c38ced690-goog

-- 
Ville Syrjälä
Intel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/edid: In connector_bad_edid() cap num_of_ext by num_blocks read
  2021-10-05 15:46 ` Ville Syrjälä
@ 2021-10-06  2:30   ` Doug Anderson
  0 siblings, 0 replies; 3+ messages in thread
From: Doug Anderson @ 2021-10-06  2:30 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: dri-devel, Siqueira, Rodrigo, Wentland, Harry, Kuogee Hsieh, Zuo,
	Jerry, alexander.deucher, Daniel Vetter, David Airlie,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, LKML

Hi,

On Tue, Oct 5, 2021 at 8:46 AM Ville Syrjälä
<ville.syrjala@linux.intel.com> wrote:
>
> On Tue, Oct 05, 2021 at 08:10:28AM -0700, Douglas Anderson wrote:
> > In commit e11f5bd8228f ("drm: Add support for DP 1.4 Compliance edid
> > corruption test") the function connector_bad_edid() started assuming
> > that the memory for the EDID passed to it was big enough to hold
> > `edid[0x7e] + 1` blocks of data (1 extra for the base block). It
> > completely ignored the fact that the function was passed `num_blocks`
> > which indicated how much memory had been allocated for the EDID.
> >
> > Let's fix this by adding a bounds check.
> >
> > This is important for handling the case where there's an error in the
> > first block of the EDID. In that case we will call
> > connector_bad_edid() without having re-allocated memory based on
> > `edid[0x7e]`.
> >
> > Fixes: e11f5bd8228f ("drm: Add support for DP 1.4 Compliance edid corruption test")
> > Reported-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > Signed-off-by: Douglas Anderson <dianders@chromium.org>
> > ---
> > This problem report came up in the context of a patch I sent out [1]
> > and this is my attempt at a fix. The problem predates my patch,
> > though. I don't personally know anything about DP compliance testing
> > and what should be happening here, nor do I apparently have any
> > hardware that actually reports a bad EDID. Thus this is just compile
> > tested. I'm hoping that someone here can test this and make sure it
> > seems OK to them.
> >
> >  drivers/gpu/drm/drm_edid.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> > index 9b19eee0e1b4..ccfa08631c57 100644
> > --- a/drivers/gpu/drm/drm_edid.c
> > +++ b/drivers/gpu/drm/drm_edid.c
> > @@ -1843,8 +1843,9 @@ static void connector_bad_edid(struct drm_connector *connector,
> >       u8 num_of_ext = edid[0x7e];
> >
> >       /* Calculate real checksum for the last edid extension block data */
> > -     connector->real_edid_checksum =
> > -             drm_edid_block_checksum(edid + num_of_ext * EDID_LENGTH);
> > +     if (num_of_ext <= num_blocks - 1)
>
> Something about that doesn't really agree with my brain.
> It's correct but when I read it I can't immediately see it.
>
> I guess what I'd like to see is something like:
> last_block = edid[0x7e];
> if (last_block < num_blocks)
>         connector->real_edid_checksum =
>                 drm_edid_block_checksum(edid + last_block * EDID_LENGTH);
>
> Techically exactly the same thing, but I don't have to read
> the comparison twice to convince myself that it's correct.
>
> Anyways, this is
> Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> either way.

Yeah, my brain had to work way too hard when I read over my patch too.
I've changed to your math _plus_ a big comment explaining it. I added
your review tag. I'll give this another day or so and then land.

https://lore.kernel.org/r/20211005192905.v2.1.Ib059f9c23c2611cb5a9d760e7d0a700c1295928d@changeid

-Doug

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-06  2:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-05 15:10 [PATCH] drm/edid: In connector_bad_edid() cap num_of_ext by num_blocks read Douglas Anderson
2021-10-05 15:46 ` Ville Syrjälä
2021-10-06  2:30   ` Doug Anderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).