[Intel-gfx] [PATCH 02/10] drm/uapi: Validate the mode flags/type

Chris Wilson chris at chris-wilson.co.uk
Tue Nov 14 18:42:06 UTC 2017


Quoting Ville Syrjala (2017-11-14 18:32:50)
> From: Ville Syrjälä <ville.syrjala at linux.intel.com>
> 
> Currently userspace is allowed to feed in any king of garbage in the
> high bits of the mode flags/type, as are drivers when probing modes.
> Reject any mode with bogus flags/type.
> 
> Hopefully this won't break any current userspace...
> 
> Cc: Jose Abreu <Jose.Abreu at synopsys.com>
> Cc: Adam Jackson <ajax at redhat.com>
> Cc: Keith Packard <keithp at keithp.com>
> Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
> ---
>  drivers/gpu/drm/drm_modes.c |  4 ++++
>  include/uapi/drm/drm_mode.h | 24 ++++++++++++++++++++++++
>  2 files changed, 28 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
> index 1a72883b836e..f99ba963fb3e 100644
> --- a/drivers/gpu/drm/drm_modes.c
> +++ b/drivers/gpu/drm/drm_modes.c
> @@ -1036,6 +1036,10 @@ EXPORT_SYMBOL(drm_mode_equal_no_clocks_no_stereo);
>  enum drm_mode_status
>  drm_mode_validate_basic(const struct drm_display_mode *mode)
>  {
> +       if (mode->type & ~DRM_MODE_TYPE_ALL ||
> +           mode->flags & ~DRM_MODE_FLAG_ALL)
> +               return MODE_BAD;

I had to read this twice to realise they were different masks. (If the
start and end of a word match expectations, the eye skips the middle.)
Can we split this up into two separate ifs, so the reader doesn't fall
into this trap :)
-Chris


More information about the Intel-gfx mailing list