linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [v8,3/6] power: supply: Add error checking of psy desc during registration
@ 2018-04-23 14:10 Opensource [Adam Thomson]
  0 siblings, 0 replies; 2+ messages in thread
From: Opensource [Adam Thomson] @ 2018-04-23 14:10 UTC (permalink / raw)
  To: Heikki Krogerus, Guenter Roeck, Greg Kroah-Hartman,
	Sebastian Reichel, Hans de Goede, Jun Li
  Cc: linux-usb, linux-pm, linux-kernel, support.opensource

Currently there's no error checking of this parameter in the
registration function and it's blindly added to psy class and
subsequently used as is. For example if this is NULL the call
to psy_register_thermal() will try to dereference the pointer
thus causing a kernel dump.

This commit updates the registration code to add some basic
checks on the desc pointer validity, name, and presence of
properties.

Signed-off-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
---
 drivers/power/supply/power_supply_core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index feac7b0..a7984af 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -849,6 +849,9 @@ static void psy_unregister_cooler(struct power_supply *psy)
 		pr_warn("%s: Expected proper parent device for '%s'\n",
 			__func__, desc->name);
 
+	if (!desc || !desc->name || !desc->properties || !desc->num_properties)
+		return ERR_PTR(-EINVAL);
+
 	psy = kzalloc(sizeof(*psy), GFP_KERNEL);
 	if (!psy)
 		return ERR_PTR(-ENOMEM);

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [v8,3/6] power: supply: Add error checking of psy desc during registration
@ 2018-04-24 12:42 Heikki Krogerus
  0 siblings, 0 replies; 2+ messages in thread
From: Heikki Krogerus @ 2018-04-24 12:42 UTC (permalink / raw)
  To: Adam Thomson
  Cc: Guenter Roeck, Greg Kroah-Hartman, Sebastian Reichel,
	Hans de Goede, Jun Li, linux-usb, linux-pm, linux-kernel,
	support.opensource

On Mon, Apr 23, 2018 at 03:10:58PM +0100, Adam Thomson wrote:
> Currently there's no error checking of this parameter in the
> registration function and it's blindly added to psy class and
> subsequently used as is. For example if this is NULL the call
> to psy_register_thermal() will try to dereference the pointer
> thus causing a kernel dump.
> 
> This commit updates the registration code to add some basic
> checks on the desc pointer validity, name, and presence of
> properties.
> 
> Signed-off-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/power/supply/power_supply_core.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> index feac7b0..a7984af 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -849,6 +849,9 @@ static void psy_unregister_cooler(struct power_supply *psy)
>  		pr_warn("%s: Expected proper parent device for '%s'\n",
>  			__func__, desc->name);
>  
> +	if (!desc || !desc->name || !desc->properties || !desc->num_properties)
> +		return ERR_PTR(-EINVAL);
> +
>  	psy = kzalloc(sizeof(*psy), GFP_KERNEL);
>  	if (!psy)
>  		return ERR_PTR(-ENOMEM);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-04-24 12:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-24 12:42 [v8,3/6] power: supply: Add error checking of psy desc during registration Heikki Krogerus
  -- strict thread matches above, loose matches on Subject: below --
2018-04-23 14:10 Opensource [Adam Thomson]

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).