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]
Date:   Tue, 27 Apr 2021 15:11:56 +0300
From:   Andy Shevchenko <andy.shevchenko@...il.com>
To:     Colin King <colin.king@...onical.com>
Cc:     Linus Walleij <linus.walleij@...aro.org>,
        Bartosz Golaszewski <bgolaszewski@...libre.com>,
        "open list:GPIO SUBSYSTEM" <linux-gpio@...r.kernel.org>,
        kernel-janitors <kernel-janitors@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH][next][V2] gpio: sim: Fix dereference of free'd pointer config

On Tue, Apr 27, 2021 at 2:49 PM Colin King <colin.king@...onical.com> wrote:
>
> From: Colin Ian King <colin.king@...onical.com>
>
> The error return of config->id dereferences the kfree'd object config.
> Fix this by using a temporary variable for the id to avoid this issue.

Thanks!
I'm wondering how I missed this... Nevertheless

Reviewed-by: Andy Shevchenko <andy.shevchenko@...il.com>

> Addresses-Coverity: ("Read from pointer aftyer free")

after

> Fixes: a49d14276ac4 ("gpio: sim: allocate IDA numbers earlier")
> Signed-off-by: Colin Ian King <colin.king@...onical.com>
> ---
> V2: Don't make id local to the if statement to improve coding style.
>     Thanks to Bartosz Golaszewski for this improvement suggestion.
> ---
>  drivers/gpio/gpio-sim.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
> index 2e2e6399e453..b21541c0b700 100644
> --- a/drivers/gpio/gpio-sim.c
> +++ b/drivers/gpio/gpio-sim.c
> @@ -744,20 +744,22 @@ static struct config_item *
>  gpio_sim_config_make_item(struct config_group *group, const char *name)
>  {
>         struct gpio_sim_chip_config *config;
> +       int id;
>
>         config = kzalloc(sizeof(*config), GFP_KERNEL);
>         if (!config)
>                 return ERR_PTR(-ENOMEM);
>
> -       config->id = ida_alloc(&gpio_sim_ida, GFP_KERNEL);
> -       if (config->id < 0) {
> +       id = ida_alloc(&gpio_sim_ida, GFP_KERNEL);
> +       if (id < 0) {
>                 kfree(config);
> -               return ERR_PTR(config->id);
> +               return ERR_PTR(id);
>         }
>
>         config_item_init_type_name(&config->item, name,
>                                    &gpio_sim_chip_config_type);
>         config->num_lines = 1;
> +       config->id = id;
>         mutex_init(&config->lock);
>
>         return &config->item;
> --
> 2.30.2
>


-- 
With Best Regards,
Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ