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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 18 Sep 2023 18:31:36 +0300
From:   Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To:     Bartosz Golaszewski <brgl@...ev.pl>
Cc:     Linus Walleij <linus.walleij@...aro.org>,
        Kent Gibson <warthog618@...il.com>,
        Alexey Dobriyan <adobriyan@...il.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        akpm@...ux-foundation.org, linux-gpio@...r.kernel.org,
        linux-kernel@...r.kernel.org,
        Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
Subject: Re: [PATCH v4] gpio: sim: fix an invalid __free() usage

On Mon, Sep 18, 2023 at 04:55:33PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
> 
> gpio_sim_make_line_names() returns NULL or ERR_PTR() so we must not use
> __free(kfree) on the returned address. Split this function into two, one
> that determines the size of the "gpio-line-names" array to allocate and
> one that actually sets the names at correct offsets. The allocation and
> assignment of the managed pointer happens in between.

...

> +	unsigned int size = 0;
>  
>  	list_for_each_entry(line, &bank->line_list, siblings) {
> +		if (!line->name || (line->offset >= bank->num_lines))
>  			continue;
>  
> +		size = line->offset + 1;
>  	}
>  
> +	return size;

So, now the function iterates over all lines and returns the size of the last
match, correct?

Why not

	list_for_each_entry_reversed() {
		if (line->name && ())
			break;
	}

	return size;

?

...

> +static void
> +gpio_sim_set_line_names(struct gpio_sim_bank *bank, char **line_names)
> +{
> +	struct gpio_sim_line *line;
>  
>  	list_for_each_entry(line, &bank->line_list, siblings) {
> -		if (line->offset >= bank->num_lines)
> +		if (!line->name || (line->offset >= bank->num_lines))
>  			continue;
>  
> -		if (line->name && (line->offset <= max_offset))
> -			line_names[line->offset] = line->name;
> +		line_names[line->offset] = line->name;
>  	}
> -
> -	return line_names;
>  }

Can be done in the similar (I see the difference) way for the consistency with
above.

...

> +	line_names_size = gpio_sim_get_line_names_size(bank);

> +	if (line_names_size) {

Of course this can be replace with...

> +		line_names = kcalloc(line_names_size, sizeof(*line_names),
> +				     GFP_KERNEL);

> +		if (!line_names)

ZERO_OR_NULL_PTR() check here, but I assume we discourage use of it.

> +			return ERR_PTR(-ENOMEM);
> +
> +		gpio_sim_set_line_names(bank, line_names);
>  
> -	if (line_names)
>  		properties[prop_idx++] = PROPERTY_ENTRY_STRING_ARRAY_LEN(
>  						"gpio-line-names",
>  						line_names, line_names_size);
> +	}

-- 
With Best Regards,
Andy Shevchenko


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ