All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm: Make sure that encoder_type for drm_encoder_init() is in the list
@ 2018-06-21 23:04 Jordan Crouse
  2018-06-22  8:31 ` Daniel Vetter
  0 siblings, 1 reply; 5+ messages in thread
From: Jordan Crouse @ 2018-06-21 23:04 UTC (permalink / raw)
  To: dri-devel

If a encoder name isn't specified for drm_encoder_init() it will try
to construct one based on the incoming encoder_type identifier. If the
caller passes an invalid encoder_type value the lookup could walk right
past the end of the table.

Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
---
 drivers/gpu/drm/drm_encoder.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c
index 273e1c59c54a..4cf6c3bb8503 100644
--- a/drivers/gpu/drm/drm_encoder.c
+++ b/drivers/gpu/drm/drm_encoder.c
@@ -128,6 +128,12 @@ int drm_encoder_init(struct drm_device *dev,
 		encoder->name = kvasprintf(GFP_KERNEL, name, ap);
 		va_end(ap);
 	} else {
+		/* Make sure that the requested encoder type is in the list */
+		if (encoder_type >= ARRAY_SIZE(drm_encoder_enum_list)) {
+			ret = -EINVAL;
+			goto out_put;
+		}
+
 		encoder->name = kasprintf(GFP_KERNEL, "%s-%d",
 					  drm_encoder_enum_list[encoder_type].name,
 					  encoder->base.id);
-- 
2.17.1

_______________________________________________
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: Make sure that encoder_type for drm_encoder_init() is in the list
  2018-06-21 23:04 [PATCH] drm: Make sure that encoder_type for drm_encoder_init() is in the list Jordan Crouse
@ 2018-06-22  8:31 ` Daniel Vetter
  2018-06-22 14:56   ` Jordan Crouse
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Vetter @ 2018-06-22  8:31 UTC (permalink / raw)
  To: Jordan Crouse; +Cc: dri-devel

On Thu, Jun 21, 2018 at 05:04:02PM -0600, Jordan Crouse wrote:
> If a encoder name isn't specified for drm_encoder_init() it will try
> to construct one based on the incoming encoder_type identifier. If the
> caller passes an invalid encoder_type value the lookup could walk right
> past the end of the table.
> 
> Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
> ---
>  drivers/gpu/drm/drm_encoder.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c
> index 273e1c59c54a..4cf6c3bb8503 100644
> --- a/drivers/gpu/drm/drm_encoder.c
> +++ b/drivers/gpu/drm/drm_encoder.c
> @@ -128,6 +128,12 @@ int drm_encoder_init(struct drm_device *dev,
>  		encoder->name = kvasprintf(GFP_KERNEL, name, ap);
>  		va_end(ap);
>  	} else {
> +		/* Make sure that the requested encoder type is in the list */
> +		if (encoder_type >= ARRAY_SIZE(drm_encoder_enum_list)) {

I think moving that to the top and wrapping it in a WARN_ON would be even
better - specifying and invalid encoder type is clearly a driver bug.
-Daniel

> +			ret = -EINVAL;
> +			goto out_put;
> +		}
> +
>  		encoder->name = kasprintf(GFP_KERNEL, "%s-%d",
>  					  drm_encoder_enum_list[encoder_type].name,
>  					  encoder->base.id);
> -- 
> 2.17.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
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: Make sure that encoder_type for drm_encoder_init() is in the list
  2018-06-22  8:31 ` Daniel Vetter
@ 2018-06-22 14:56   ` Jordan Crouse
  0 siblings, 0 replies; 5+ messages in thread
From: Jordan Crouse @ 2018-06-22 14:56 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: dri-devel

On Fri, Jun 22, 2018 at 10:31:42AM +0200, Daniel Vetter wrote:
> On Thu, Jun 21, 2018 at 05:04:02PM -0600, Jordan Crouse wrote:
> > If a encoder name isn't specified for drm_encoder_init() it will try
> > to construct one based on the incoming encoder_type identifier. If the
> > caller passes an invalid encoder_type value the lookup could walk right
> > past the end of the table.
> > 
> > Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
> > ---
> >  drivers/gpu/drm/drm_encoder.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c
> > index 273e1c59c54a..4cf6c3bb8503 100644
> > --- a/drivers/gpu/drm/drm_encoder.c
> > +++ b/drivers/gpu/drm/drm_encoder.c
> > @@ -128,6 +128,12 @@ int drm_encoder_init(struct drm_device *dev,
> >  		encoder->name = kvasprintf(GFP_KERNEL, name, ap);
> >  		va_end(ap);
> >  	} else {
> > +		/* Make sure that the requested encoder type is in the list */
> > +		if (encoder_type >= ARRAY_SIZE(drm_encoder_enum_list)) {
> 
> I think moving that to the top and wrapping it in a WARN_ON would be even
> better - specifying and invalid encoder type is clearly a driver bug.
> -Daniel

It wasn't immediately clear to me if it was legal to pass a "custom" encoder
type assuming you provided a name for it so I erred on the side of caution.
I would have no problem moving it up to the top and being loud about it.

Jordan

> > +			ret = -EINVAL;
> > +			goto out_put;
> > +		}
> > +
> >  		encoder->name = kasprintf(GFP_KERNEL, "%s-%d",
> >  					  drm_encoder_enum_list[encoder_type].name,
> >  					  encoder->base.id);
> > -- 
> > 2.17.1
> > 
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
> 
> -- 
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch

-- 
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
_______________________________________________
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: Make sure that encoder_type for drm_encoder_init() is in the list
  2018-06-29 21:47 Jordan Crouse
@ 2018-07-02  8:11 ` Daniel Vetter
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Vetter @ 2018-07-02  8:11 UTC (permalink / raw)
  To: Jordan Crouse; +Cc: dri-devel

On Fri, Jun 29, 2018 at 03:47:43PM -0600, Jordan Crouse wrote:
> If a encoder name isn't specified for drm_encoder_init() it will try
> to construct one based on the incoming encoder_type identifier. If the
> caller passes an invalid encoder_type value the lookup could walk right
> past the end of the table.
> 
> [v2: Use a WARN() at the top of the function as suggested by Daniel
>  Vetter]
> 
> Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

Aside: Want drm-misc commit rights so you can push patches like these
yourself?

Might also be useful in case the group maintainership thing with msm
happens, just as prep.
-Daniel

> ---
>  drivers/gpu/drm/drm_encoder.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c
> index 273e1c59c54a..6228c2cee5f0 100644
> --- a/drivers/gpu/drm/drm_encoder.c
> +++ b/drivers/gpu/drm/drm_encoder.c
> @@ -114,6 +114,10 @@ int drm_encoder_init(struct drm_device *dev,
>  	if (WARN_ON(dev->mode_config.num_encoder >= 32))
>  		return -EINVAL;
>  
> +	/* Make sure that the requested encoder type is in the list */
> +	if (WARN_ON(encoder_type >= ARRAY_SIZE(drm_encoder_enum_list)))
> +		return -EINVAL;
> +
>  	ret = drm_mode_object_add(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER);
>  	if (ret)
>  		return ret;
> -- 
> 2.17.1
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
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

* [PATCH] drm: Make sure that encoder_type for drm_encoder_init() is in the list
@ 2018-06-29 21:47 Jordan Crouse
  2018-07-02  8:11 ` Daniel Vetter
  0 siblings, 1 reply; 5+ messages in thread
From: Jordan Crouse @ 2018-06-29 21:47 UTC (permalink / raw)
  To: dri-devel

If a encoder name isn't specified for drm_encoder_init() it will try
to construct one based on the incoming encoder_type identifier. If the
caller passes an invalid encoder_type value the lookup could walk right
past the end of the table.

[v2: Use a WARN() at the top of the function as suggested by Daniel
 Vetter]

Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
---
 drivers/gpu/drm/drm_encoder.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c
index 273e1c59c54a..6228c2cee5f0 100644
--- a/drivers/gpu/drm/drm_encoder.c
+++ b/drivers/gpu/drm/drm_encoder.c
@@ -114,6 +114,10 @@ int drm_encoder_init(struct drm_device *dev,
 	if (WARN_ON(dev->mode_config.num_encoder >= 32))
 		return -EINVAL;
 
+	/* Make sure that the requested encoder type is in the list */
+	if (WARN_ON(encoder_type >= ARRAY_SIZE(drm_encoder_enum_list)))
+		return -EINVAL;
+
 	ret = drm_mode_object_add(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER);
 	if (ret)
 		return ret;
-- 
2.17.1

_______________________________________________
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

end of thread, other threads:[~2018-07-02  8:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-21 23:04 [PATCH] drm: Make sure that encoder_type for drm_encoder_init() is in the list Jordan Crouse
2018-06-22  8:31 ` Daniel Vetter
2018-06-22 14:56   ` Jordan Crouse
2018-06-29 21:47 Jordan Crouse
2018-07-02  8:11 ` Daniel Vetter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.