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: <f7d92fa5-16b9-6e60-cd52-db3f848abe6c@metafoo.de>
Date:   Wed, 13 Dec 2017 10:32:39 +0100
From:   Lars-Peter Clausen <lars@...afoo.de>
To:     Bartosz Golaszewski <brgl@...ev.pl>,
        Mark Brown <broonie@...nel.org>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc:     linux-kernel@...r.kernel.org,
        Andy Shevchenko <andy.shevchenko@...il.com>
Subject: Re: [PATCH 3/3] regmap: duplicate the name string stored in regmap

On 12/13/2017 10:28 AM, Bartosz Golaszewski wrote:
> Currently we just copy over the pointer passed to regmap_init() in
> the regmap config struct. To be on the safe side: duplicate the string
> so that if an unaware user passes an address to a stack-allocated
> buffer, we won't crash.
> 
> Signed-off-by: Bartosz Golaszewski <brgl@...ev.pl>
> ---
>  drivers/base/regmap/regmap.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
> index a2a02ce58824..3952e5d7638a 100644
> --- a/drivers/base/regmap/regmap.c
> +++ b/drivers/base/regmap/regmap.c
> @@ -672,6 +672,14 @@ struct regmap *__regmap_init(struct device *dev,
>  		goto err;
>  	}
>  
> +	if (config->name) {
> +		map->name = kstrdup(config->name, GFP_KERNEL);

To get the best of both worlds: kstrdup_const(), this will not make a copy
when it is in a read-only section (like most strings will be). Needs to be
matched with kfree_const().

> +		if (!map->name) {
> +			ret = -ENOMEM;
> +			goto err_map;
> +		}
> +	}
> +
>  	if (config->disable_locking) {
>  		map->locking_disabled = true;
>  		map->lock = map->unlock = regmap_lock_unlock_none;
> @@ -763,7 +771,6 @@ struct regmap *__regmap_init(struct device *dev,
>  	map->volatile_reg = config->volatile_reg;
>  	map->precious_reg = config->precious_reg;
>  	map->cache_type = config->cache_type;
> -	map->name = config->name;
>  
>  	spin_lock_init(&map->async_lock);
>  	INIT_LIST_HEAD(&map->async_list);
> @@ -1308,6 +1315,7 @@ void regmap_exit(struct regmap *map)
>  	}
>  	if (map->hwlock)
>  		hwspin_lock_free(map->hwlock);
> +	kfree(map->name);
>  	kfree(map);
>  }
>  EXPORT_SYMBOL_GPL(regmap_exit);
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ