public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 4/4] video: Remove stack VLA usage
@ 2018-03-09  5:50 Tobin C. Harding
  2018-03-09  6:01 ` Joe Perches
  0 siblings, 1 reply; 6+ messages in thread
From: Tobin C. Harding @ 2018-03-09  5:50 UTC (permalink / raw)
  To: Florian Tobias Schandinat, Bartlomiej Zolnierkiewicz
  Cc: Tobin C. Harding, kernel-hardening, linux-kernel, driverdev-devel,
	Tycho Andersen, Kees Cook

The kernel would like to have all stack VLA usage removed[1].  The
arrays are fixed here (declared with a const variable) but they appear
like VLAs to the compiler.  We can use a pre-processor define to fix the
warning.  

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

Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
 drivers/video/fbdev/via/via_aux_sii164.c |  8 +++++---
 drivers/video/fbdev/via/via_aux_vt1631.c | 11 +++++++----
 drivers/video/fbdev/via/via_aux_vt1632.c | 11 +++++++----
 drivers/video/fbdev/via/via_aux_vt1636.c | 11 +++++++----
 4 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/drivers/video/fbdev/via/via_aux_sii164.c b/drivers/video/fbdev/via/via_aux_sii164.c
index ca1b35f033b1..f715ea4f466c 100644
--- a/drivers/video/fbdev/via/via_aux_sii164.c
+++ b/drivers/video/fbdev/via/via_aux_sii164.c
@@ -27,6 +27,9 @@
 
 static const char *name = "SiI 164 PanelLink Transmitter";
 
+/* check vendor id and device id */
+const u8 id[] = {0x01, 0x00, 0x06, 0x00};
+#define VIA_SII164_LEN ARRAY_SIZE(id)
 
 static void probe(struct via_aux_bus *bus, u8 addr)
 {
@@ -34,9 +37,8 @@ static void probe(struct via_aux_bus *bus, u8 addr)
 		.bus	=	bus,
 		.addr	=	addr,
 		.name	=	name};
-	/* check vendor id and device id */
-	const u8 id[] = {0x01, 0x00, 0x06, 0x00}, len = ARRAY_SIZE(id);
-	u8 tmp[len];
+	u8 tmp[VIA_SII164_LEN];
+	int len = VIA_SII164_LEN;
 
 	if (!via_aux_read(&drv, 0x00, tmp, len) || memcmp(id, tmp, len))
 		return;
diff --git a/drivers/video/fbdev/via/via_aux_vt1631.c b/drivers/video/fbdev/via/via_aux_vt1631.c
index 06e742f1f723..5bfaa20ec5a8 100644
--- a/drivers/video/fbdev/via/via_aux_vt1631.c
+++ b/drivers/video/fbdev/via/via_aux_vt1631.c
@@ -27,16 +27,19 @@
 
 static const char *name = "VT1631 LVDS Transmitter";
 
+/* check vendor id and device id */
+const u8 id[] = {0x06, 0x11, 0x91, 0x31}, len = ARRAY_SIZE(id);
+#define VIA_VT1631_LEN ARRAY_SIZE(id)
 
 void via_aux_vt1631_probe(struct via_aux_bus *bus)
 {
 	struct via_aux_drv drv = {
 		.bus	=	bus,
 		.addr	=	0x38,
-		.name	=	name};
-	/* check vendor id and device id */
-	const u8 id[] = {0x06, 0x11, 0x91, 0x31}, len = ARRAY_SIZE(id);
-	u8 tmp[len];
+		.name	=	name
+	};
+	u8 tmp[VIA_VT1631_LEN];
+	int len = VIA_VT1631_LEN;
 
 	if (!via_aux_read(&drv, 0x00, tmp, len) || memcmp(id, tmp, len))
 		return;
diff --git a/drivers/video/fbdev/via/via_aux_vt1632.c b/drivers/video/fbdev/via/via_aux_vt1632.c
index d24f4cd97401..fcddd761d4a4 100644
--- a/drivers/video/fbdev/via/via_aux_vt1632.c
+++ b/drivers/video/fbdev/via/via_aux_vt1632.c
@@ -27,16 +27,19 @@
 
 static const char *name = "VT1632 DVI Transmitter";
 
+/* check vendor id and device id */
+const u8 id[] = {0x06, 0x11, 0x92, 0x31};
+#define VIA_VT1632_LEN ARRAY_SIZE(id)
 
 static void probe(struct via_aux_bus *bus, u8 addr)
 {
 	struct via_aux_drv drv = {
 		.bus	=	bus,
 		.addr	=	addr,
-		.name	=	name};
-	/* check vendor id and device id */
-	const u8 id[] = {0x06, 0x11, 0x92, 0x31}, len = ARRAY_SIZE(id);
-	u8 tmp[len];
+		.name	=	name
+	};
+	u8 tmp[VIA_VT1632_LEN];
+	int len = VIA_VT1632_LEN;
 
 	if (!via_aux_read(&drv, 0x00, tmp, len) || memcmp(id, tmp, len))
 		return;
diff --git a/drivers/video/fbdev/via/via_aux_vt1636.c b/drivers/video/fbdev/via/via_aux_vt1636.c
index 9e015c101d4d..49c9269c7f81 100644
--- a/drivers/video/fbdev/via/via_aux_vt1636.c
+++ b/drivers/video/fbdev/via/via_aux_vt1636.c
@@ -27,16 +27,19 @@
 
 static const char *name = "VT1636 LVDS Transmitter";
 
+/* check vendor id and device id */
+const u8 id[] = {0x06, 0x11, 0x45, 0x33};
+#define VIA_VT1636_LEN ARRAY_SIZE(id)
 
 void via_aux_vt1636_probe(struct via_aux_bus *bus)
 {
 	struct via_aux_drv drv = {
 		.bus	=	bus,
 		.addr	=	0x40,
-		.name	=	name};
-	/* check vendor id and device id */
-	const u8 id[] = {0x06, 0x11, 0x45, 0x33}, len = ARRAY_SIZE(id);
-	u8 tmp[len];
+		.name	=	name
+	};
+	u8 tmp[VIA_VT1636_LEN];
+	int len = VIA_VT1636_LEN;
 
 	if (!via_aux_read(&drv, 0x00, tmp, len) || memcmp(id, tmp, len))
 		return;
-- 
2.7.4

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

* Re: [PATCH 4/4] video: Remove stack VLA usage
  2018-03-09  5:50 [PATCH 4/4] video: Remove stack VLA usage Tobin C. Harding
@ 2018-03-09  6:01 ` Joe Perches
  2018-03-09  6:04   ` Tobin C. Harding
  2018-03-09  6:11   ` Tycho Andersen
  0 siblings, 2 replies; 6+ messages in thread
From: Joe Perches @ 2018-03-09  6:01 UTC (permalink / raw)
  To: Tobin C. Harding, Florian Tobias Schandinat,
	Bartlomiej Zolnierkiewicz
  Cc: Tycho Andersen, driverdev-devel, linux-kernel, Kees Cook,
	kernel-hardening

On Fri, 2018-03-09 at 16:50 +1100, Tobin C. Harding wrote:
> The kernel would like to have all stack VLA usage removed[1].  The
> arrays are fixed here (declared with a const variable) but they appear
> like VLAs to the compiler.  We can use a pre-processor define to fix the
> warning.  
[]
> diff --git a/drivers/video/fbdev/via/via_aux_sii164.c b/drivers/video/fbdev/via/via_aux_sii164.c
[]
> @@ -27,6 +27,9 @@
>  
>  static const char *name = "SiI 164 PanelLink Transmitter";
>  
> +/* check vendor id and device id */
> +const u8 id[] = {0x01, 0x00, 0x06, 0x00};

It seems id is now global in multiple places.
Perhaps these should be static.

> diff --git a/drivers/video/fbdev/via/via_aux_vt1631.c b/drivers/video/fbdev/via/via_aux_vt1631.c
[]
> @@ -27,16 +27,19 @@
>  
>  static const char *name = "VT1631 LVDS Transmitter";
>  
> +/* check vendor id and device id */
> +const u8 id[] = {0x06, 0x11, 0x91, 0x31}, len = ARRAY_SIZE(id);

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

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

* Re: [PATCH 4/4] video: Remove stack VLA usage
  2018-03-09  6:01 ` Joe Perches
@ 2018-03-09  6:04   ` Tobin C. Harding
  2018-03-09  6:11   ` Tycho Andersen
  1 sibling, 0 replies; 6+ messages in thread
From: Tobin C. Harding @ 2018-03-09  6:04 UTC (permalink / raw)
  To: Joe Perches
  Cc: Tycho Andersen, Kees Cook, kernel-hardening, driverdev-devel,
	linux-kernel, Bartlomiej Zolnierkiewicz,
	Florian Tobias Schandinat

On Thu, Mar 08, 2018 at 10:01:07PM -0800, Joe Perches wrote:
> On Fri, 2018-03-09 at 16:50 +1100, Tobin C. Harding wrote:
> > The kernel would like to have all stack VLA usage removed[1].  The
> > arrays are fixed here (declared with a const variable) but they appear
> > like VLAs to the compiler.  We can use a pre-processor define to fix the
> > warning.  
> []
> > diff --git a/drivers/video/fbdev/via/via_aux_sii164.c b/drivers/video/fbdev/via/via_aux_sii164.c
> []
> > @@ -27,6 +27,9 @@
> >  
> >  static const char *name = "SiI 164 PanelLink Transmitter";
> >  
> > +/* check vendor id and device id */
> > +const u8 id[] = {0x01, 0x00, 0x06, 0x00};
> 
> It seems id is now global in multiple places.
> Perhaps these should be static.

woops, thanks Joe.  Will fix and re-spin.

> 
> > diff --git a/drivers/video/fbdev/via/via_aux_vt1631.c b/drivers/video/fbdev/via/via_aux_vt1631.c
> []
> > @@ -27,16 +27,19 @@
> >  
> >  static const char *name = "VT1631 LVDS Transmitter";
> >  
> > +/* check vendor id and device id */
> > +const u8 id[] = {0x06, 0x11, 0x91, 0x31}, len = ARRAY_SIZE(id);
> 
> etc...

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

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

* Re: [PATCH 4/4] video: Remove stack VLA usage
  2018-03-09  6:01 ` Joe Perches
  2018-03-09  6:04   ` Tobin C. Harding
@ 2018-03-09  6:11   ` Tycho Andersen
  2018-03-09  6:16     ` Gustavo A. R. Silva
  1 sibling, 1 reply; 6+ messages in thread
From: Tycho Andersen @ 2018-03-09  6:11 UTC (permalink / raw)
  To: Joe Perches
  Cc: Kees Cook, kernel-hardening, driverdev-devel,
	Florian Tobias Schandinat, linux-kernel,
	Bartlomiej Zolnierkiewicz

On Thu, Mar 08, 2018 at 10:01:07PM -0800, Joe Perches wrote:
> On Fri, 2018-03-09 at 16:50 +1100, Tobin C. Harding wrote:
> > The kernel would like to have all stack VLA usage removed[1].  The
> > arrays are fixed here (declared with a const variable) but they appear
> > like VLAs to the compiler.  We can use a pre-processor define to fix the
> > warning.  
> []
> > diff --git a/drivers/video/fbdev/via/via_aux_sii164.c b/drivers/video/fbdev/via/via_aux_sii164.c
> []
> > @@ -27,6 +27,9 @@
> >  
> >  static const char *name = "SiI 164 PanelLink Transmitter";
> >  
> > +/* check vendor id and device id */
> > +const u8 id[] = {0x01, 0x00, 0x06, 0x00};
> 
> It seems id is now global in multiple places.
> Perhaps these should be static.

Does it even need to be global? Why not just get rid of the indirection and use
ARRAY_SIZE where we mean it? This seems to work for me,

diff --git a/drivers/video/fbdev/via/via_aux_sii164.c b/drivers/video/fbdev/via/via_aux_sii164.c
index ca1b35f033b1..87db6c98d680 100644
--- a/drivers/video/fbdev/via/via_aux_sii164.c
+++ b/drivers/video/fbdev/via/via_aux_sii164.c
@@ -35,10 +35,10 @@ static void probe(struct via_aux_bus *bus, u8 addr)
                .addr   =       addr,
                .name   =       name};
        /* check vendor id and device id */
-       const u8 id[] = {0x01, 0x00, 0x06, 0x00}, len = ARRAY_SIZE(id);
-       u8 tmp[len];
+       const u8 id[] = {0x01, 0x00, 0x06, 0x00};
+       u8 tmp[ARRAY_SIZE(id)];
 
-       if (!via_aux_read(&drv, 0x00, tmp, len) || memcmp(id, tmp, len))
+       if (!via_aux_read(&drv, 0x00, tmp, sizeof(tmp)) || memcmp(id, tmp, sizeof(tmp)))
                return;
 
        printk(KERN_INFO "viafb: Found %s at address 0x%x\n", name, addr);

Cheers,

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

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

* Re: [PATCH 4/4] video: Remove stack VLA usage
  2018-03-09  6:11   ` Tycho Andersen
@ 2018-03-09  6:16     ` Gustavo A. R. Silva
  2018-03-09  6:28       ` Tobin C. Harding
  0 siblings, 1 reply; 6+ messages in thread
From: Gustavo A. R. Silva @ 2018-03-09  6:16 UTC (permalink / raw)
  To: Tycho Andersen, Joe Perches
  Cc: Tobin C. Harding, Florian Tobias Schandinat,
	Bartlomiej Zolnierkiewicz, kernel-hardening, linux-kernel,
	driverdev-devel, Kees Cook


I sent a patch for this six hours ago:

https://patchwork.kernel.org/patch/10268591/

--
Gustavo

On 03/09/2018 12:11 AM, Tycho Andersen wrote:
> On Thu, Mar 08, 2018 at 10:01:07PM -0800, Joe Perches wrote:
>> On Fri, 2018-03-09 at 16:50 +1100, Tobin C. Harding wrote:
>>> The kernel would like to have all stack VLA usage removed[1].  The
>>> arrays are fixed here (declared with a const variable) but they appear
>>> like VLAs to the compiler.  We can use a pre-processor define to fix the
>>> warning.
>> []
>>> diff --git a/drivers/video/fbdev/via/via_aux_sii164.c b/drivers/video/fbdev/via/via_aux_sii164.c
>> []
>>> @@ -27,6 +27,9 @@
>>>   
>>>   static const char *name = "SiI 164 PanelLink Transmitter";
>>>   
>>> +/* check vendor id and device id */
>>> +const u8 id[] = {0x01, 0x00, 0x06, 0x00};
>>
>> It seems id is now global in multiple places.
>> Perhaps these should be static.
> 
> Does it even need to be global? Why not just get rid of the indirection and use
> ARRAY_SIZE where we mean it? This seems to work for me,
> 
> diff --git a/drivers/video/fbdev/via/via_aux_sii164.c b/drivers/video/fbdev/via/via_aux_sii164.c
> index ca1b35f033b1..87db6c98d680 100644
> --- a/drivers/video/fbdev/via/via_aux_sii164.c
> +++ b/drivers/video/fbdev/via/via_aux_sii164.c
> @@ -35,10 +35,10 @@ static void probe(struct via_aux_bus *bus, u8 addr)
>                  .addr   =       addr,
>                  .name   =       name};
>          /* check vendor id and device id */
> -       const u8 id[] = {0x01, 0x00, 0x06, 0x00}, len = ARRAY_SIZE(id);
> -       u8 tmp[len];
> +       const u8 id[] = {0x01, 0x00, 0x06, 0x00};
> +       u8 tmp[ARRAY_SIZE(id)];
>   
> -       if (!via_aux_read(&drv, 0x00, tmp, len) || memcmp(id, tmp, len))
> +       if (!via_aux_read(&drv, 0x00, tmp, sizeof(tmp)) || memcmp(id, tmp, sizeof(tmp)))
>                  return;
>   
>          printk(KERN_INFO "viafb: Found %s at address 0x%x\n", name, addr);
> 
> Cheers,
> 
> Tycho
> 

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

* Re: [PATCH 4/4] video: Remove stack VLA usage
  2018-03-09  6:16     ` Gustavo A. R. Silva
@ 2018-03-09  6:28       ` Tobin C. Harding
  0 siblings, 0 replies; 6+ messages in thread
From: Tobin C. Harding @ 2018-03-09  6:28 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Tycho Andersen, driverdev-devel, Kees Cook,
	Bartlomiej Zolnierkiewicz, kernel-hardening, linux-kernel,
	Florian Tobias Schandinat, Joe Perches

On Fri, Mar 09, 2018 at 12:16:21AM -0600, Gustavo A. R. Silva wrote:
> 
> I sent a patch for this six hours ago:
> 
> https://patchwork.kernel.org/patch/10268591/
> 
> --
> Gustavo

lol, I knew there would be a race on to fix these :)  And you got it
right, bonus points. Let's drop this one then.


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

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

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

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-09  5:50 [PATCH 4/4] video: Remove stack VLA usage Tobin C. Harding
2018-03-09  6:01 ` Joe Perches
2018-03-09  6:04   ` Tobin C. Harding
2018-03-09  6:11   ` Tycho Andersen
2018-03-09  6:16     ` Gustavo A. R. Silva
2018-03-09  6:28       ` Tobin C. Harding

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