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]
Message-ID: <aScSNtqQ01cKJ7gW@opensource.cirrus.com>
Date: Wed, 26 Nov 2025 14:44:06 +0000
From: Charles Keepax <ckeepax@...nsource.cirrus.com>
To: sparkhuang <huangshaobo3@...omi.com>
Cc: Liam Girdwood <lgirdwood@...il.com>, Mark Brown <broonie@...nel.org>,
        Charles Keepax <ckeepax@...nsource.wolfsonmicro.com>,
        linux-kernel@...r.kernel.org, weipengliang@...omi.com,
        wengjinfei@...omi.com, caodan1@...omi.com
Subject: Re: [PATCH] regulator: core: Protect regulator_supply_alias_list
 with regulator_list_mutex

On Wed, Nov 26, 2025 at 02:15:42PM +0800, sparkhuang wrote:
> regulator_supply_alias_list was accessed without any locking in
> regulator_supply_alias(), regulator_register_supply_alias(), and
> regulator_unregister_supply_alias(). Concurrent registration,
> unregistration and lookups can race, leading to:
> 
> 1 use-after-free if an alias entry is removed while being read,
> 2 duplicate entries when two threads register the same alias,
> 3 inconsistent alias mappings observed by consumers.
> 
> Protect all traversals, insertions and deletions on
> regulator_supply_alias_list with the existing regulator_list_mutex.
> 
> Fixes: a06ccd9c3785f ("regulator: core: Add ability to create a lookup alias for supply")
> Signed-off-by: sparkhuang <huangshaobo3@...omi.com>
> ---
>  {
>  	struct regulator_supply_alias *map;
> +	struct regulator_supply_alias *new_map;
>  
> -	map = regulator_find_supply_alias(dev, id);
> -	if (map)
> -		return -EEXIST;
> -
> -	map = kzalloc(sizeof(struct regulator_supply_alias), GFP_KERNEL);
> -	if (!map)
> +	new_map = kzalloc(sizeof(struct regulator_supply_alias), GFP_KERNEL);
> +	if (!new_map)
>  		return -ENOMEM;
>  
> -	map->src_dev = dev;
> -	map->src_supply = id;
> -	map->alias_dev = alias_dev;
> -	map->alias_supply = alias_id;
> +	mutex_lock(&regulator_list_mutex);
> +	map = regulator_find_supply_alias(dev, id);
> +	if (map) {
> +		mutex_unlock(&regulator_list_mutex);
> +		kfree(new_map);
> +		return -EEXIST;
> +	}
>  
> +	new_map->src_dev = dev;
> +	new_map->src_supply = id;
> +	new_map->alias_dev = alias_dev;
> +	new_map->alias_supply = alias_id;
>  	list_add(&map->list, &regulator_supply_alias_list);

In addition to Mark's comment the first argument here should be
the new item to add. Personally I would be inclined to just leave
the allocation inside the lock and not require the extra variable
but up to you.

Thanks,
Charles

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ