dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/edid: Fix uninitialized variable in drm_cvt_modes()
@ 2020-10-22 16:54 Lyude Paul
  2020-10-22 18:04 ` Ilia Mirkin
  0 siblings, 1 reply; 5+ messages in thread
From: Lyude Paul @ 2020-10-22 16:54 UTC (permalink / raw)
  To: dri-devel
  Cc: Leon Romanovsky, David Airlie, Chao Yu, open list,
	Jason Gunthorpe, stable, Thomas Zimmermann, Kalle Valo,
	Kees Cook

Noticed this when trying to compile with -Wall on a kernel fork. We potentially
don't set width here, which causes the compiler to complain about width
potentially being uninitialized in drm_cvt_modes(). So, let's fix that.

Signed-off-by: Lyude Paul <lyude@redhat.com>

Cc: <stable@vger.kernel.org> # v5.9+
Fixes: 3f649ab728cd ("treewide: Remove uninitialized_var() usage")
Signed-off-by: Lyude Paul <lyude@redhat.com>
---
 drivers/gpu/drm/drm_edid.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 631125b46e04..2da158ffed8e 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -3094,6 +3094,7 @@ static int drm_cvt_modes(struct drm_connector *connector,
 
 	for (i = 0; i < 4; i++) {
 		int width, height;
+		u8 cvt_aspect_ratio;
 
 		cvt = &(timing->data.other_data.data.cvt[i]);
 
@@ -3101,7 +3102,8 @@ static int drm_cvt_modes(struct drm_connector *connector,
 			continue;
 
 		height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
-		switch (cvt->code[1] & 0x0c) {
+		cvt_aspect_ratio = cvt->code[1] & 0x0c;
+		switch (cvt_aspect_ratio) {
 		case 0x00:
 			width = height * 4 / 3;
 			break;
@@ -3114,6 +3116,10 @@ static int drm_cvt_modes(struct drm_connector *connector,
 		case 0x0c:
 			width = height * 15 / 9;
 			break;
+		default:
+			drm_dbg_kms(dev, "[CONNECTOR:%d:%s] unknown CVT aspect ratio %x\n",
+				    connector->base.id, connector->name, cvt_aspect_ratio);
+			continue;
 		}
 
 		for (j = 1; j < 5; j++) {
-- 
2.26.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drm/edid: Fix uninitialized variable in drm_cvt_modes()
  2020-10-22 16:54 [PATCH] drm/edid: Fix uninitialized variable in drm_cvt_modes() Lyude Paul
@ 2020-10-22 18:04 ` Ilia Mirkin
  2020-11-03 19:47   ` Lyude Paul
  0 siblings, 1 reply; 5+ messages in thread
From: Ilia Mirkin @ 2020-10-22 18:04 UTC (permalink / raw)
  To: Lyude Paul
  Cc: Kees Cook, Leon Romanovsky, David Airlie, Chao Yu, open list,
	dri-devel, Jason Gunthorpe, # 3.9+,
	Thomas Zimmermann, Kalle Valo

On Thu, Oct 22, 2020 at 12:55 PM Lyude Paul <lyude@redhat.com> wrote:
>
> Noticed this when trying to compile with -Wall on a kernel fork. We potentially
> don't set width here, which causes the compiler to complain about width
> potentially being uninitialized in drm_cvt_modes(). So, let's fix that.
>
> Signed-off-by: Lyude Paul <lyude@redhat.com>
>
> Cc: <stable@vger.kernel.org> # v5.9+
> Fixes: 3f649ab728cd ("treewide: Remove uninitialized_var() usage")
> Signed-off-by: Lyude Paul <lyude@redhat.com>
> ---
>  drivers/gpu/drm/drm_edid.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> index 631125b46e04..2da158ffed8e 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -3094,6 +3094,7 @@ static int drm_cvt_modes(struct drm_connector *connector,
>
>         for (i = 0; i < 4; i++) {
>                 int width, height;
> +               u8 cvt_aspect_ratio;
>
>                 cvt = &(timing->data.other_data.data.cvt[i]);
>
> @@ -3101,7 +3102,8 @@ static int drm_cvt_modes(struct drm_connector *connector,
>                         continue;
>
>                 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
> -               switch (cvt->code[1] & 0x0c) {
> +               cvt_aspect_ratio = cvt->code[1] & 0x0c;
> +               switch (cvt_aspect_ratio) {
>                 case 0x00:
>                         width = height * 4 / 3;
>                         break;
> @@ -3114,6 +3116,10 @@ static int drm_cvt_modes(struct drm_connector *connector,
>                 case 0x0c:
>                         width = height * 15 / 9;
>                         break;
> +               default:

What value would cvt->code[1] have such that this gets hit?

Or is this a "compiler is broken, so let's add more code" situation?
If so, perhaps the code added could just be enough to silence the
compiler (unreachable, etc)?

  -ilia
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drm/edid: Fix uninitialized variable in drm_cvt_modes()
  2020-10-22 18:04 ` Ilia Mirkin
@ 2020-11-03 19:47   ` Lyude Paul
  2020-11-03 19:53     ` Ilia Mirkin
  0 siblings, 1 reply; 5+ messages in thread
From: Lyude Paul @ 2020-11-03 19:47 UTC (permalink / raw)
  To: Ilia Mirkin
  Cc: Kees Cook, Leon Romanovsky, David Airlie, Chao Yu, open list,
	dri-devel, Jason Gunthorpe, # 3.9+,
	Thomas Zimmermann, Kalle Valo

Sorry! Thought I had responded to this but apparently not, comments down below

On Thu, 2020-10-22 at 14:04 -0400, Ilia Mirkin wrote:
> On Thu, Oct 22, 2020 at 12:55 PM Lyude Paul <lyude@redhat.com> wrote:
> > 
> > Noticed this when trying to compile with -Wall on a kernel fork. We
> > potentially
> > don't set width here, which causes the compiler to complain about width
> > potentially being uninitialized in drm_cvt_modes(). So, let's fix that.
> > 
> > Signed-off-by: Lyude Paul <lyude@redhat.com>
> > 
> > Cc: <stable@vger.kernel.org> # v5.9+
> > Fixes: 3f649ab728cd ("treewide: Remove uninitialized_var() usage")
> > Signed-off-by: Lyude Paul <lyude@redhat.com>
> > ---
> >  drivers/gpu/drm/drm_edid.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> > index 631125b46e04..2da158ffed8e 100644
> > --- a/drivers/gpu/drm/drm_edid.c
> > +++ b/drivers/gpu/drm/drm_edid.c
> > @@ -3094,6 +3094,7 @@ static int drm_cvt_modes(struct drm_connector
> > *connector,
> > 
> >         for (i = 0; i < 4; i++) {
> >                 int width, height;
> > +               u8 cvt_aspect_ratio;
> > 
> >                 cvt = &(timing->data.other_data.data.cvt[i]);
> > 
> > @@ -3101,7 +3102,8 @@ static int drm_cvt_modes(struct drm_connector
> > *connector,
> >                         continue;
> > 
> >                 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) *
> > 2;
> > -               switch (cvt->code[1] & 0x0c) {
> > +               cvt_aspect_ratio = cvt->code[1] & 0x0c;
> > +               switch (cvt_aspect_ratio) {
> >                 case 0x00:
> >                         width = height * 4 / 3;
> >                         break;
> > @@ -3114,6 +3116,10 @@ static int drm_cvt_modes(struct drm_connector
> > *connector,
> >                 case 0x0c:
> >                         width = height * 15 / 9;
> >                         break;
> > +               default:
> 
> What value would cvt->code[1] have such that this gets hit?
> 
> Or is this a "compiler is broken, so let's add more code" situation?
> If so, perhaps the code added could just be enough to silence the
> compiler (unreachable, etc)?

I mean, this information comes from the EDID which inherently means it's coming
from an untrusted source so the value could be literally anything as long as the
EDID has a valid checksum. Note (assuming I'm understanding this code
correctly): 

drm_add_edid_modes() → add_cvt_modes() → drm_for_each_detailed_block() →
do_cvt_mode() → drm_cvt_modes()

So afaict this isn't a broken compiler but a legitimate uninitialized variable.
> 
>   -ilia
> 

-- 
Sincerely,
   Lyude Paul (she/her)
   Software Engineer at Red Hat
   
Note: I deal with a lot of emails and have a lot of bugs on my plate. If you've
asked me a question, are waiting for a review/merge on a patch, etc. and I
haven't responded in a while, please feel free to send me another email to check
on my status. I don't bite!

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drm/edid: Fix uninitialized variable in drm_cvt_modes()
  2020-11-03 19:47   ` Lyude Paul
@ 2020-11-03 19:53     ` Ilia Mirkin
  2020-11-03 20:03       ` Lyude Paul
  0 siblings, 1 reply; 5+ messages in thread
From: Ilia Mirkin @ 2020-11-03 19:53 UTC (permalink / raw)
  To: Lyude
  Cc: Kees Cook, Leon Romanovsky, David Airlie, Chao Yu, open list,
	dri-devel, Jason Gunthorpe, # 3.9+,
	Thomas Zimmermann, Kalle Valo

On Tue, Nov 3, 2020 at 2:47 PM Lyude Paul <lyude@redhat.com> wrote:
>
> Sorry! Thought I had responded to this but apparently not, comments down below
>
> On Thu, 2020-10-22 at 14:04 -0400, Ilia Mirkin wrote:
> > On Thu, Oct 22, 2020 at 12:55 PM Lyude Paul <lyude@redhat.com> wrote:
> > >
> > > Noticed this when trying to compile with -Wall on a kernel fork. We
> > > potentially
> > > don't set width here, which causes the compiler to complain about width
> > > potentially being uninitialized in drm_cvt_modes(). So, let's fix that.
> > >
> > > Signed-off-by: Lyude Paul <lyude@redhat.com>
> > >
> > > Cc: <stable@vger.kernel.org> # v5.9+
> > > Fixes: 3f649ab728cd ("treewide: Remove uninitialized_var() usage")
> > > Signed-off-by: Lyude Paul <lyude@redhat.com>
> > > ---
> > >  drivers/gpu/drm/drm_edid.c | 8 +++++++-
> > >  1 file changed, 7 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> > > index 631125b46e04..2da158ffed8e 100644
> > > --- a/drivers/gpu/drm/drm_edid.c
> > > +++ b/drivers/gpu/drm/drm_edid.c
> > > @@ -3094,6 +3094,7 @@ static int drm_cvt_modes(struct drm_connector
> > > *connector,
> > >
> > >         for (i = 0; i < 4; i++) {
> > >                 int width, height;
> > > +               u8 cvt_aspect_ratio;
> > >
> > >                 cvt = &(timing->data.other_data.data.cvt[i]);
> > >
> > > @@ -3101,7 +3102,8 @@ static int drm_cvt_modes(struct drm_connector
> > > *connector,
> > >                         continue;
> > >
> > >                 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) *
> > > 2;
> > > -               switch (cvt->code[1] & 0x0c) {
> > > +               cvt_aspect_ratio = cvt->code[1] & 0x0c;
> > > +               switch (cvt_aspect_ratio) {
> > >                 case 0x00:
> > >                         width = height * 4 / 3;
> > >                         break;
> > > @@ -3114,6 +3116,10 @@ static int drm_cvt_modes(struct drm_connector
> > > *connector,
> > >                 case 0x0c:
> > >                         width = height * 15 / 9;
> > >                         break;
> > > +               default:
> >
> > What value would cvt->code[1] have such that this gets hit?
> >
> > Or is this a "compiler is broken, so let's add more code" situation?
> > If so, perhaps the code added could just be enough to silence the
> > compiler (unreachable, etc)?
>
> I mean, this information comes from the EDID which inherently means it's coming
> from an untrusted source so the value could be literally anything as long as the
> EDID has a valid checksum. Note (assuming I'm understanding this code
> correctly):
>
> drm_add_edid_modes() → add_cvt_modes() → drm_for_each_detailed_block() →
> do_cvt_mode() → drm_cvt_modes()
>
> So afaict this isn't a broken compiler but a legitimate uninitialized variable.

The value can be anything, but it has to be something. The switch is
on "unknown & 0x0c", so only 4 cases are possible, which are
enumerated in the switch.

  -ilia
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH] drm/edid: Fix uninitialized variable in drm_cvt_modes()
  2020-11-03 19:53     ` Ilia Mirkin
@ 2020-11-03 20:03       ` Lyude Paul
  0 siblings, 0 replies; 5+ messages in thread
From: Lyude Paul @ 2020-11-03 20:03 UTC (permalink / raw)
  To: Ilia Mirkin
  Cc: Kees Cook, Leon Romanovsky, David Airlie, Chao Yu, open list,
	dri-devel, Jason Gunthorpe, # 3.9+,
	Thomas Zimmermann, Kalle Valo

On Tue, 2020-11-03 at 14:53 -0500, Ilia Mirkin wrote:
> On Tue, Nov 3, 2020 at 2:47 PM Lyude Paul <lyude@redhat.com> wrote:
> > 
> > Sorry! Thought I had responded to this but apparently not, comments down
> > below
> > 
> > On Thu, 2020-10-22 at 14:04 -0400, Ilia Mirkin wrote:
> > > On Thu, Oct 22, 2020 at 12:55 PM Lyude Paul <lyude@redhat.com> wrote:
> > > > 
> > > > Noticed this when trying to compile with -Wall on a kernel fork. We
> > > > potentially
> > > > don't set width here, which causes the compiler to complain about width
> > > > potentially being uninitialized in drm_cvt_modes(). So, let's fix that.
> > > > 
> > > > Signed-off-by: Lyude Paul <lyude@redhat.com>
> > > > 
> > > > Cc: <stable@vger.kernel.org> # v5.9+
> > > > Fixes: 3f649ab728cd ("treewide: Remove uninitialized_var() usage")
> > > > Signed-off-by: Lyude Paul <lyude@redhat.com>
> > > > ---
> > > >  drivers/gpu/drm/drm_edid.c | 8 +++++++-
> > > >  1 file changed, 7 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> > > > index 631125b46e04..2da158ffed8e 100644
> > > > --- a/drivers/gpu/drm/drm_edid.c
> > > > +++ b/drivers/gpu/drm/drm_edid.c
> > > > @@ -3094,6 +3094,7 @@ static int drm_cvt_modes(struct drm_connector
> > > > *connector,
> > > > 
> > > >         for (i = 0; i < 4; i++) {
> > > >                 int width, height;
> > > > +               u8 cvt_aspect_ratio;
> > > > 
> > > >                 cvt = &(timing->data.other_data.data.cvt[i]);
> > > > 
> > > > @@ -3101,7 +3102,8 @@ static int drm_cvt_modes(struct drm_connector
> > > > *connector,
> > > >                         continue;
> > > > 
> > > >                 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) +
> > > > 1) *
> > > > 2;
> > > > -               switch (cvt->code[1] & 0x0c) {
> > > > +               cvt_aspect_ratio = cvt->code[1] & 0x0c;
> > > > +               switch (cvt_aspect_ratio) {
> > > >                 case 0x00:
> > > >                         width = height * 4 / 3;
> > > >                         break;
> > > > @@ -3114,6 +3116,10 @@ static int drm_cvt_modes(struct drm_connector
> > > > *connector,
> > > >                 case 0x0c:
> > > >                         width = height * 15 / 9;
> > > >                         break;
> > > > +               default:
> > > 
> > > What value would cvt->code[1] have such that this gets hit?
> > > 
> > > Or is this a "compiler is broken, so let's add more code" situation?
> > > If so, perhaps the code added could just be enough to silence the
> > > compiler (unreachable, etc)?
> > 
> > I mean, this information comes from the EDID which inherently means it's
> > coming
> > from an untrusted source so the value could be literally anything as long as
> > the
> > EDID has a valid checksum. Note (assuming I'm understanding this code
> > correctly):
> > 
> > drm_add_edid_modes() → add_cvt_modes() → drm_for_each_detailed_block() →
> > do_cvt_mode() → drm_cvt_modes()
> > 
> > So afaict this isn't a broken compiler but a legitimate uninitialized
> > variable.
> 
> The value can be anything, but it has to be something. The switch is
> on "unknown & 0x0c", so only 4 cases are possible, which are
> enumerated in the switch.

oops, you're completely right lol. will figure out what the unreachable macro in
the kernel is and use that in a respin of this patch

> 
>   -ilia
> 

-- 
Sincerely,
   Lyude Paul (she/her)
   Software Engineer at Red Hat
   
Note: I deal with a lot of emails and have a lot of bugs on my plate. If you've
asked me a question, are waiting for a review/merge on a patch, etc. and I
haven't responded in a while, please feel free to send me another email to check
on my status. I don't bite!

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

end of thread, other threads:[~2020-11-03 20:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-22 16:54 [PATCH] drm/edid: Fix uninitialized variable in drm_cvt_modes() Lyude Paul
2020-10-22 18:04 ` Ilia Mirkin
2020-11-03 19:47   ` Lyude Paul
2020-11-03 19:53     ` Ilia Mirkin
2020-11-03 20:03       ` Lyude Paul

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).