All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Anholt <eric@anholt.net>
To: David Airlie <airlied@linux.ie>
Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	"Gustavo A. R. Silva" <gustavo@embeddedor.com>
Subject: Re: [PATCH] drm/vc4_validate: Remove VLA usage
Date: Fri, 16 Mar 2018 16:05:03 -0700	[thread overview]
Message-ID: <87y3irvcyo.fsf@anholt.net> (raw)
In-Reply-To: <20180313143151.GA27486@embeddedgus>


[-- Attachment #1.1: Type: text/plain, Size: 1576 bytes --]

"Gustavo A. R. Silva" <gustavo@embeddedor.com> writes:

> In preparation to enabling -Wvla, remove VLA. In this particular
> case use macro ARRAY_SIZE so the length of array _bo_ can be
> computed at preprocessing time.
>
> The use of stack Variable Length Arrays needs to be avoided, as they
> can be a vector for stack exhaustion, which can be both a runtime bug
> or a security flaw. Also, in general, as code evolves it is easy to
> lose track of how big a VLA can get. Thus, we can end up having runtime
> failures that are hard to debug.
>
> Also, fixed as part of the directive to remove all VLAs from
> the kernel: https://lkml.org/lkml/2018/3/7/621
>
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>  drivers/gpu/drm/vc4/vc4_validate.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/vc4/vc4_validate.c b/drivers/gpu/drm/vc4/vc4_validate.c
> index 2db485a..eec76af 100644
> --- a/drivers/gpu/drm/vc4/vc4_validate.c
> +++ b/drivers/gpu/drm/vc4/vc4_validate.c
> @@ -753,7 +753,7 @@ validate_gl_shader_rec(struct drm_device *dev,
>  		28, /* cs */
>  	};
>  	uint32_t shader_reloc_count = ARRAY_SIZE(shader_reloc_offsets);
> -	struct drm_gem_cma_object *bo[shader_reloc_count + 8];
> +	struct drm_gem_cma_object *bo[ARRAY_SIZE(shader_reloc_offsets) + 8];
>  	uint32_t nr_attributes, nr_relocs, packet_size;
>  	int i;
>  
> -- 
> 2.7.4

It's a shame that the compiler is warning about this when it's obviously
a compile-time constant.  Regardless, reviewed and applied.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

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

WARNING: multiple messages have this Message-ID (diff)
From: Eric Anholt <eric@anholt.net>
To: "Gustavo A. R. Silva" <gustavo@embeddedor.com>,
	David Airlie <airlied@linux.ie>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	"Gustavo A. R. Silva" <gustavo@embeddedor.com>
Subject: Re: [PATCH] drm/vc4_validate: Remove VLA usage
Date: Fri, 16 Mar 2018 16:05:03 -0700	[thread overview]
Message-ID: <87y3irvcyo.fsf@anholt.net> (raw)
In-Reply-To: <20180313143151.GA27486@embeddedgus>

[-- Attachment #1: Type: text/plain, Size: 1576 bytes --]

"Gustavo A. R. Silva" <gustavo@embeddedor.com> writes:

> In preparation to enabling -Wvla, remove VLA. In this particular
> case use macro ARRAY_SIZE so the length of array _bo_ can be
> computed at preprocessing time.
>
> The use of stack Variable Length Arrays needs to be avoided, as they
> can be a vector for stack exhaustion, which can be both a runtime bug
> or a security flaw. Also, in general, as code evolves it is easy to
> lose track of how big a VLA can get. Thus, we can end up having runtime
> failures that are hard to debug.
>
> Also, fixed as part of the directive to remove all VLAs from
> the kernel: https://lkml.org/lkml/2018/3/7/621
>
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>  drivers/gpu/drm/vc4/vc4_validate.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/vc4/vc4_validate.c b/drivers/gpu/drm/vc4/vc4_validate.c
> index 2db485a..eec76af 100644
> --- a/drivers/gpu/drm/vc4/vc4_validate.c
> +++ b/drivers/gpu/drm/vc4/vc4_validate.c
> @@ -753,7 +753,7 @@ validate_gl_shader_rec(struct drm_device *dev,
>  		28, /* cs */
>  	};
>  	uint32_t shader_reloc_count = ARRAY_SIZE(shader_reloc_offsets);
> -	struct drm_gem_cma_object *bo[shader_reloc_count + 8];
> +	struct drm_gem_cma_object *bo[ARRAY_SIZE(shader_reloc_offsets) + 8];
>  	uint32_t nr_attributes, nr_relocs, packet_size;
>  	int i;
>  
> -- 
> 2.7.4

It's a shame that the compiler is warning about this when it's obviously
a compile-time constant.  Regardless, reviewed and applied.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2018-03-16 23:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-13 14:31 [PATCH] drm/vc4_validate: Remove VLA usage Gustavo A. R. Silva
2018-03-16 23:05 ` Eric Anholt [this message]
2018-03-16 23:05   ` Eric Anholt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y3irvcyo.fsf@anholt.net \
    --to=eric@anholt.net \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gustavo@embeddedor.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.