All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] gpio: Remove VLA from stmpe driver
@ 2018-03-28 17:59 Laura Abbott
  2018-03-29  0:07 ` Phil Reid
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Laura Abbott @ 2018-03-28 17:59 UTC (permalink / raw)
  To: Linus Walleij, Kees Cook, Patrice Chotard
  Cc: Laura Abbott, linux-gpio, linux-kernel, kernel-hardening

The new challenge is to remove VLAs from the kernel
(see https://lkml.org/lkml/2018/3/7/621)

The number of GPIOs on the supported chips is fairly small
so stack allocate to a known upper bound and spit out a warning
if any new chips have more gpios.

Signed-off-by: Laura Abbott <labbott@redhat.com>
---
v3: Split this off from the rest of the series since some of the
patches had been picked up. Switched to just hardcoding an upper
bound for the stack array since it's only a few extra bytes
of stack space.
---
 drivers/gpio/gpio-stmpe.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c
index f8d7d1cd8488..8d6a5a7e612d 100644
--- a/drivers/gpio/gpio-stmpe.c
+++ b/drivers/gpio/gpio-stmpe.c
@@ -363,13 +363,15 @@ static struct irq_chip stmpe_gpio_irq_chip = {
 	.irq_set_type		= stmpe_gpio_irq_set_type,
 };
 
+#define MAX_GPIOS 24
+
 static irqreturn_t stmpe_gpio_irq(int irq, void *dev)
 {
 	struct stmpe_gpio *stmpe_gpio = dev;
 	struct stmpe *stmpe = stmpe_gpio->stmpe;
 	u8 statmsbreg;
 	int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8);
-	u8 status[num_banks];
+	u8 status[DIV_ROUND_UP(MAX_GPIOS, 8)];
 	int ret;
 	int i;
 
@@ -434,6 +436,11 @@ static int stmpe_gpio_probe(struct platform_device *pdev)
 	struct stmpe_gpio *stmpe_gpio;
 	int ret, irq;
 
+	if (stmpe->num_gpios > MAX_GPIOS) {
+		dev_err(&pdev->dev, "Need to increase maximum GPIO number\n");
+		return -EINVAL;
+	}
+
 	stmpe_gpio = kzalloc(sizeof(*stmpe_gpio), GFP_KERNEL);
 	if (!stmpe_gpio)
 		return -ENOMEM;
-- 
2.14.3

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

* Re: [PATCH v3] gpio: Remove VLA from stmpe driver
  2018-03-28 17:59 [PATCH v3] gpio: Remove VLA from stmpe driver Laura Abbott
@ 2018-03-29  0:07 ` Phil Reid
  2018-05-23 22:51 ` Kees Cook
  2018-05-24  8:23 ` Linus Walleij
  2 siblings, 0 replies; 4+ messages in thread
From: Phil Reid @ 2018-03-29  0:07 UTC (permalink / raw)
  To: Laura Abbott, Linus Walleij, Kees Cook, Patrice Chotard
  Cc: linux-gpio, linux-kernel, kernel-hardening

On 29/03/2018 01:59, Laura Abbott wrote:
> The new challenge is to remove VLAs from the kernel
> (see https://lkml.org/lkml/2018/3/7/621)
> 
> The number of GPIOs on the supported chips is fairly small
> so stack allocate to a known upper bound and spit out a warning
> if any new chips have more gpios.
> 
> Signed-off-by: Laura Abbott <labbott@redhat.com>
> ---
> v3: Split this off from the rest of the series since some of the
> patches had been picked up. Switched to just hardcoding an upper
> bound for the stack array since it's only a few extra bytes
> of stack space.
> ---
>   drivers/gpio/gpio-stmpe.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c
> index f8d7d1cd8488..8d6a5a7e612d 100644
> --- a/drivers/gpio/gpio-stmpe.c
> +++ b/drivers/gpio/gpio-stmpe.c
> @@ -363,13 +363,15 @@ static struct irq_chip stmpe_gpio_irq_chip = {
>   	.irq_set_type		= stmpe_gpio_irq_set_type,
>   };
>   
> +#define MAX_GPIOS 24
> +
>   static irqreturn_t stmpe_gpio_irq(int irq, void *dev)
>   {
>   	struct stmpe_gpio *stmpe_gpio = dev;
>   	struct stmpe *stmpe = stmpe_gpio->stmpe;
>   	u8 statmsbreg;
>   	int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8);
> -	u8 status[num_banks];
> +	u8 status[DIV_ROUND_UP(MAX_GPIOS, 8)];
>   	int ret;
>   	int i;
>   
> @@ -434,6 +436,11 @@ static int stmpe_gpio_probe(struct platform_device *pdev)
>   	struct stmpe_gpio *stmpe_gpio;
>   	int ret, irq;
>   
> +	if (stmpe->num_gpios > MAX_GPIOS) {
> +		dev_err(&pdev->dev, "Need to increase maximum GPIO number\n");
> +		return -EINVAL;
> +	}
> +
>   	stmpe_gpio = kzalloc(sizeof(*stmpe_gpio), GFP_KERNEL);
>   	if (!stmpe_gpio)
>   		return -ENOMEM;
> 
FWIW
Reviewed-by: Phil Reid <preid@electromag.com.au>

-- 
Regards
Phil Reid

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

* Re: [PATCH v3] gpio: Remove VLA from stmpe driver
  2018-03-28 17:59 [PATCH v3] gpio: Remove VLA from stmpe driver Laura Abbott
  2018-03-29  0:07 ` Phil Reid
@ 2018-05-23 22:51 ` Kees Cook
  2018-05-24  8:23 ` Linus Walleij
  2 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2018-05-23 22:51 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Laura Abbott, Patrice Chotard, linux-gpio, LKML, Kernel Hardening

On Wed, Mar 28, 2018 at 10:59 AM, Laura Abbott <labbott@redhat.com> wrote:
> The new challenge is to remove VLAs from the kernel
> (see https://lkml.org/lkml/2018/3/7/621)
>
> The number of GPIOs on the supported chips is fairly small
> so stack allocate to a known upper bound and spit out a warning
> if any new chips have more gpios.
>
> Signed-off-by: Laura Abbott <labbott@redhat.com>

Reviewed-by: Kees Cook <keescook@chromium.org>

Linus, I think this patch is still needed and got missed? Can you take
it as well?

Thanks!

-Kees

> ---
> v3: Split this off from the rest of the series since some of the
> patches had been picked up. Switched to just hardcoding an upper
> bound for the stack array since it's only a few extra bytes
> of stack space.
> ---
>  drivers/gpio/gpio-stmpe.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c
> index f8d7d1cd8488..8d6a5a7e612d 100644
> --- a/drivers/gpio/gpio-stmpe.c
> +++ b/drivers/gpio/gpio-stmpe.c
> @@ -363,13 +363,15 @@ static struct irq_chip stmpe_gpio_irq_chip = {
>         .irq_set_type           = stmpe_gpio_irq_set_type,
>  };
>
> +#define MAX_GPIOS 24
> +
>  static irqreturn_t stmpe_gpio_irq(int irq, void *dev)
>  {
>         struct stmpe_gpio *stmpe_gpio = dev;
>         struct stmpe *stmpe = stmpe_gpio->stmpe;
>         u8 statmsbreg;
>         int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8);
> -       u8 status[num_banks];
> +       u8 status[DIV_ROUND_UP(MAX_GPIOS, 8)];
>         int ret;
>         int i;
>
> @@ -434,6 +436,11 @@ static int stmpe_gpio_probe(struct platform_device *pdev)
>         struct stmpe_gpio *stmpe_gpio;
>         int ret, irq;
>
> +       if (stmpe->num_gpios > MAX_GPIOS) {
> +               dev_err(&pdev->dev, "Need to increase maximum GPIO number\n");
> +               return -EINVAL;
> +       }
> +
>         stmpe_gpio = kzalloc(sizeof(*stmpe_gpio), GFP_KERNEL);
>         if (!stmpe_gpio)
>                 return -ENOMEM;
> --
> 2.14.3
>



-- 
Kees Cook
Pixel Security

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

* Re: [PATCH v3] gpio: Remove VLA from stmpe driver
  2018-03-28 17:59 [PATCH v3] gpio: Remove VLA from stmpe driver Laura Abbott
  2018-03-29  0:07 ` Phil Reid
  2018-05-23 22:51 ` Kees Cook
@ 2018-05-24  8:23 ` Linus Walleij
  2 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2018-05-24  8:23 UTC (permalink / raw)
  To: Laura Abbott
  Cc: Kees Cook, Patrice Chotard, open list:GPIO SUBSYSTEM,
	linux-kernel, kernel-hardening

On Wed, Mar 28, 2018 at 7:59 PM, Laura Abbott <labbott@redhat.com> wrote:

> The new challenge is to remove VLAs from the kernel
> (see https://lkml.org/lkml/2018/3/7/621)
>
> The number of GPIOs on the supported chips is fairly small
> so stack allocate to a known upper bound and spit out a warning
> if any new chips have more gpios.
>
> Signed-off-by: Laura Abbott <labbott@redhat.com>

Patch applied with the review tags!

Yours,
Linus Walleij

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

end of thread, other threads:[~2018-05-24  8:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-28 17:59 [PATCH v3] gpio: Remove VLA from stmpe driver Laura Abbott
2018-03-29  0:07 ` Phil Reid
2018-05-23 22:51 ` Kees Cook
2018-05-24  8:23 ` Linus Walleij

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.