diff mbox

[2/2] drm/i915/cmdparser: Do not check past the cmd length.

Message ID 20180205142916.27092-3-msrb@suse.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michal Srb Feb. 5, 2018, 2:29 p.m. UTC
The command MEDIA_VFE_STATE checks bits at offset +2 dwords. However, it is
possible to have MEDIA_VFE_STATE command with length = 0 + LENGTH_BIAS = 2.
In that case check_cmd will read bits from the following command, or even past
the end of the buffer.

Similarly to how registers are checked - if the offset ends up outside of the
command length, just ignore it.

Signed-off-by: Michal Srb <msrb@suse.com>
---
 drivers/gpu/drm/i915/i915_cmd_parser.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Chris Wilson Feb. 5, 2018, 2:48 p.m. UTC | #1
Quoting Michal Srb (2018-02-05 14:29:16)
> The command MEDIA_VFE_STATE checks bits at offset +2 dwords. However, it is
> possible to have MEDIA_VFE_STATE command with length = 0 + LENGTH_BIAS = 2.
> In that case check_cmd will read bits from the following command, or even past
> the end of the buffer.
> 
> Similarly to how registers are checked - if the offset ends up outside of the
> command length, just ignore it.
> 
> Signed-off-by: Michal Srb <msrb@suse.com>
> ---
>  drivers/gpu/drm/i915/i915_cmd_parser.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/gpu/drm/i915/i915_cmd_parser.c b/drivers/gpu/drm/i915/i915_cmd_parser.c
> index de7ec59433d1..827740b866a8 100644
> --- a/drivers/gpu/drm/i915/i915_cmd_parser.c
> +++ b/drivers/gpu/drm/i915/i915_cmd_parser.c
> @@ -1218,6 +1218,9 @@ static bool check_cmd(const struct intel_engine_cs *engine,
>                                         continue;
>                         }
>  
> +                       if (desc->bits[i].offset >= length)
> +                               continue;

Should be return false since the command can't be validated.
-Chris
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_cmd_parser.c b/drivers/gpu/drm/i915/i915_cmd_parser.c
index de7ec59433d1..827740b866a8 100644
--- a/drivers/gpu/drm/i915/i915_cmd_parser.c
+++ b/drivers/gpu/drm/i915/i915_cmd_parser.c
@@ -1218,6 +1218,9 @@  static bool check_cmd(const struct intel_engine_cs *engine,
 					continue;
 			}
 
+			if (desc->bits[i].offset >= length)
+				continue;
+
 			dword = cmd[desc->bits[i].offset] &
 				desc->bits[i].mask;