lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMpxmJUUth5w8tvZp8mFV-FDz0YivmRWAqsOQSTdze1xagMX8A@mail.gmail.com>
Date:   Thu, 12 Mar 2020 14:54:12 +0100
From:   Bartosz Golaszewski <bgolaszewski@...libre.com>
To:     Gabriel Ravier <gabravier@...il.com>
Cc:     Linus Walleij <linus.walleij@...aro.org>,
        linux-gpio <linux-gpio@...r.kernel.org>,
        LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] gpio-hammer: Avoid potential overflow in main

czw., 12 mar 2020 o 10:40 Gabriel Ravier <gabravier@...il.com> napisaƂ(a):
>
> If '-o' was used more than 64 times in a single invocation of gpio-hammer,
> this could lead to an overflow of the 'lines' array. This commit fixes
> this by avoiding the overflow and giving a proper diagnostic back to the
> user
>
> Signed-off-by: Gabriel Ravier <gabravier@...il.com>
> ---
>  tools/gpio/gpio-hammer.c | 19 +++++++++++++++++--
>  1 file changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/tools/gpio/gpio-hammer.c b/tools/gpio/gpio-hammer.c
> index 0e0060a6e..273d33847 100644
> --- a/tools/gpio/gpio-hammer.c
> +++ b/tools/gpio/gpio-hammer.c
> @@ -77,7 +77,7 @@ int hammer_device(const char *device_name, unsigned int *lines, int nlines,
>
>                 fprintf(stdout, "[%c] ", swirr[j]);
>                 j++;
> -               if (j == sizeof(swirr)-1)
> +               if (j == sizeof(swirr) - 1)

Please don't try to sneak in unrelated changes into commits. This is
of course correct coding-style-wise but send it in a separate patch.

>                         j = 0;
>
>                 fprintf(stdout, "[");
> @@ -135,7 +135,14 @@ int main(int argc, char **argv)
>                         device_name = optarg;
>                         break;
>                 case 'o':
> -                       lines[i] = strtoul(optarg, NULL, 10);
> +                       /*
> +                        * Avoid overflow. Do not immediately error, we want to
> +                        * be able to accurately report on the amount of times
> +                        *'-o' was given to give an accurate error message
> +                        */
> +                       if (i < GPIOHANDLES_MAX)
> +                               lines[i] = strtoul(optarg, NULL, 10);
> +
>                         i++;
>                         break;
>                 case '?':
> @@ -143,6 +150,14 @@ int main(int argc, char **argv)
>                         return -1;
>                 }
>         }
> +
> +       if (i >= GPIOHANDLES_MAX) {
> +               fprintf(stderr,
> +                       "Only %d occurences of '-o' are allowed, %d were found\n",
> +                       GPIOHANDLES_MAX, i + 1);
> +               return -1;
> +       }
> +
>         nlines = i;
>
>         if (!device_name || !nlines) {
> --
> 2.24.1
>

Other than that, looks good.

Bartosz

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ