public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: vchiq_arm: Clear VLA warning
@ 2018-03-09  6:21 Tobin C. Harding
  2018-03-09 18:11 ` Eric Anholt
  0 siblings, 1 reply; 4+ messages in thread
From: Tobin C. Harding @ 2018-03-09  6:21 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Eric Anholt, Stefan Wahren
  Cc: Tycho Andersen, Kees Cook, kernel-hardening, driverdev-devel,
	linux-kernel

The kernel would like to have all stack VLA usage removed[1].  The
array here is fixed (declared with a const variable) but it appears
like VLA to the compiler.  We can use a pre-processor define to quiet
the compiler.

[1]: https://lkml.org/lkml/2018/3/7/621

Signed-off-by: Tobin C. Harding <me@tobin.cc>
---

The name of this constant may need changing, there is already a
pre-processor constant VCHIQ_MAX_SERVICES

 .../staging/vc04_services/interface/vchiq_arm/vchiq_arm.c  | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index f5cefda49b22..c972869a0333 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -3434,13 +3434,15 @@ vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle)
 	return ret;
 }
 
+/* Only dump 64 services */
+#define VCHIQ_LOCAL_MAX_SERVICES 64
+
 void
 vchiq_dump_service_use_state(VCHIQ_STATE_T *state)
 {
 	VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
 	int i, j = 0;
-	/* Only dump 64 services */
-	static const int local_max_services = 64;
+
 	/* If there's more than 64 services, only dump ones with
 	 * non-zero counts */
 	int only_nonzero = 0;
@@ -3455,7 +3457,7 @@ vchiq_dump_service_use_state(VCHIQ_STATE_T *state)
 		int fourcc;
 		int clientid;
 		int use_count;
-	} service_data[local_max_services];
+	} service_data[VCHIQ_LOCAL_MAX_SERVICES];
 
 	if (!arm_state)
 		return;
@@ -3466,10 +3468,10 @@ vchiq_dump_service_use_state(VCHIQ_STATE_T *state)
 	peer_count = arm_state->peer_use_count;
 	vc_use_count = arm_state->videocore_use_count;
 	active_services = state->unused_service;
-	if (active_services > local_max_services)
+	if (active_services > VCHIQ_LOCAL_MAX_SERVICES)
 		only_nonzero = 1;
 
-	for (i = 0; (i < active_services) && (j < local_max_services); i++) {
+	for (i = 0; (i < active_services) && (j < VCHIQ_LOCAL_MAX_SERVICES); i++) {
 		VCHIQ_SERVICE_T *service_ptr = state->services[i];
 
 		if (!service_ptr)
@@ -3499,7 +3501,7 @@ vchiq_dump_service_use_state(VCHIQ_STATE_T *state)
 		vchiq_log_warning(vchiq_susp_log_level, "Too many active "
 			"services (%d).  Only dumping up to first %d services "
 			"with non-zero use-count", active_services,
-			local_max_services);
+			VCHIQ_LOCAL_MAX_SERVICES);
 
 	for (i = 0; i < j; i++) {
 		vchiq_log_warning(vchiq_susp_log_level,
-- 
2.7.4

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH] staging: vchiq_arm: Clear VLA warning
  2018-03-09  6:21 [PATCH] staging: vchiq_arm: Clear VLA warning Tobin C. Harding
@ 2018-03-09 18:11 ` Eric Anholt
  2018-03-09 18:35   ` Kees Cook
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Anholt @ 2018-03-09 18:11 UTC (permalink / raw)
  To: Tobin C. Harding, Greg Kroah-Hartman, Stefan Wahren
  Cc: Tobin C. Harding, kernel-hardening, linux-kernel, driverdev-devel,
	Tycho Andersen, Kees Cook

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

"Tobin C. Harding" <me@tobin.cc> writes:

> The kernel would like to have all stack VLA usage removed[1].  The
> array here is fixed (declared with a const variable) but it appears
> like VLA to the compiler.  We can use a pre-processor define to quiet
> the compiler.
>
> [1]: https://lkml.org/lkml/2018/3/7/621
>
> Signed-off-by: Tobin C. Harding <me@tobin.cc>
> ---
>
> The name of this constant may need changing, there is already a
> pre-processor constant VCHIQ_MAX_SERVICES

Maybe just use ARRAY_SIZE(local_max_services) and not have the #define?

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

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

* Re: [PATCH] staging: vchiq_arm: Clear VLA warning
  2018-03-09 18:11 ` Eric Anholt
@ 2018-03-09 18:35   ` Kees Cook
  2018-03-09 18:44     ` Linus Torvalds
  0 siblings, 1 reply; 4+ messages in thread
From: Kees Cook @ 2018-03-09 18:35 UTC (permalink / raw)
  To: Eric Anholt
  Cc: Stefan Wahren, Tycho Andersen, Kernel Hardening,
	Greg Kroah-Hartman, driverdev-devel, LKML

On Fri, Mar 9, 2018 at 10:11 AM, Eric Anholt <eric@anholt.net> wrote:
> "Tobin C. Harding" <me@tobin.cc> writes:
>
>> The kernel would like to have all stack VLA usage removed[1].  The
>> array here is fixed (declared with a const variable) but it appears
>> like VLA to the compiler.  We can use a pre-processor define to quiet
>> the compiler.
>>
>> [1]: https://lkml.org/lkml/2018/3/7/621
>>
>> Signed-off-by: Tobin C. Harding <me@tobin.cc>
>> ---
>>
>> The name of this constant may need changing, there is already a
>> pre-processor constant VCHIQ_MAX_SERVICES
>
> Maybe just use ARRAY_SIZE(local_max_services) and not have the #define?

I think you mean ARRAY_SIZE(service_data) ? In that case, yeah, it
seems like a raw "64" for the array size can be used instead.

-Kees

-- 
Kees Cook
Pixel Security
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH] staging: vchiq_arm: Clear VLA warning
  2018-03-09 18:35   ` Kees Cook
@ 2018-03-09 18:44     ` Linus Torvalds
  0 siblings, 0 replies; 4+ messages in thread
From: Linus Torvalds @ 2018-03-09 18:44 UTC (permalink / raw)
  To: Kees Cook
  Cc: Stefan Wahren, Tycho Andersen, Kernel Hardening,
	Greg Kroah-Hartman, driverdev-devel, LKML, Eric Anholt

On Fri, Mar 9, 2018 at 10:35 AM, Kees Cook <keescook@chromium.org> wrote:
>
> I think you mean ARRAY_SIZE(service_data) ? In that case, yeah, it
> seems like a raw "64" for the array size can be used instead.

I think 64 is much too big anyway. That's 768 bytes of stack data that
is used to check stuff deep in some transfer call chain.

So that code is broken from a stack usage model anyway. If it's just a
"random big number", then cut it down in size.

I don't know. The code was imported in 2013, and has seen very little
change since. I'm not sure how many users it has. But while changing
this, just do the stack size limitation at the same time.

              Linus
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

end of thread, other threads:[~2018-03-09 18:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-09  6:21 [PATCH] staging: vchiq_arm: Clear VLA warning Tobin C. Harding
2018-03-09 18:11 ` Eric Anholt
2018-03-09 18:35   ` Kees Cook
2018-03-09 18:44     ` Linus Torvalds

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox