devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of: overlay: add_changeset_property() memory leak
@ 2019-11-21 19:16 frowand.list
  2019-11-21 19:20 ` Frank Rowand
  2019-11-26 19:23 ` Rob Herring
  0 siblings, 2 replies; 4+ messages in thread
From: frowand.list @ 2019-11-21 19:16 UTC (permalink / raw)
  To: Rob Herring, Vincent Whitchurch, pantelis.antoniou, Pantelis Antoniou
  Cc: devicetree, linux-kernel, Vincent Whitchurch, geert, Alan Tull

From: Frank Rowand <frank.rowand@sony.com>

No changeset entries are created for #address-cells and #size-cells
properties, but the duplicated properties are never freed.  This
results in a memory leak which is detected by kmemleak:

 unreferenced object 0x85887180 (size 64):
   backtrace:
     kmem_cache_alloc_trace+0x1fb/0x1fc
     __of_prop_dup+0x25/0x7c
     add_changeset_property+0x17f/0x370
     build_changeset_next_level+0x29/0x20c
     of_overlay_fdt_apply+0x32b/0x6b4
     ...

Fixes: 6f75118800acf77f8 ("of: overlay: validate overlay properties #address-cells and #size-cells")
Reported-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
Signed-off-by: Frank Rowand <frank.rowand@sony.com>
---
 drivers/of/overlay.c | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index c423e94baf0f..9617b7df7c4d 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -305,7 +305,6 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
 {
 	struct property *new_prop = NULL, *prop;
 	int ret = 0;
-	bool check_for_non_overlay_node = false;
 
 	if (target->in_livetree)
 		if (!of_prop_cmp(overlay_prop->name, "name") ||
@@ -318,6 +317,25 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
 	else
 		prop = NULL;
 
+	if (prop) {
+		if (!of_prop_cmp(prop->name, "#address-cells")) {
+			if (!of_prop_val_eq(prop, overlay_prop)) {
+				pr_err("ERROR: changing value of #address-cells is not allowed in %pOF\n",
+				       target->np);
+				ret = -EINVAL;
+			}
+			return ret;
+
+		} else if (!of_prop_cmp(prop->name, "#size-cells")) {
+			if (!of_prop_val_eq(prop, overlay_prop)) {
+				pr_err("ERROR: changing value of #size-cells is not allowed in %pOF\n",
+				       target->np);
+				ret = -EINVAL;
+			}
+			return ret;
+		}
+	}
+
 	if (is_symbols_prop) {
 		if (prop)
 			return -EINVAL;
@@ -330,33 +348,18 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
 		return -ENOMEM;
 
 	if (!prop) {
-		check_for_non_overlay_node = true;
 		if (!target->in_livetree) {
 			new_prop->next = target->np->deadprops;
 			target->np->deadprops = new_prop;
 		}
 		ret = of_changeset_add_property(&ovcs->cset, target->np,
 						new_prop);
-	} else if (!of_prop_cmp(prop->name, "#address-cells")) {
-		if (!of_prop_val_eq(prop, new_prop)) {
-			pr_err("ERROR: changing value of #address-cells is not allowed in %pOF\n",
-			       target->np);
-			ret = -EINVAL;
-		}
-	} else if (!of_prop_cmp(prop->name, "#size-cells")) {
-		if (!of_prop_val_eq(prop, new_prop)) {
-			pr_err("ERROR: changing value of #size-cells is not allowed in %pOF\n",
-			       target->np);
-			ret = -EINVAL;
-		}
 	} else {
-		check_for_non_overlay_node = true;
 		ret = of_changeset_update_property(&ovcs->cset, target->np,
 						   new_prop);
 	}
 
-	if (check_for_non_overlay_node &&
-	    !of_node_check_flag(target->np, OF_OVERLAY))
+	if (!of_node_check_flag(target->np, OF_OVERLAY))
 		pr_err("WARNING: memory leak will occur if overlay removed, property: %pOF/%s\n",
 		       target->np, new_prop->name);
 
-- 
Frank Rowand <frank.rowand@sony.com>


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

* Re: [PATCH] of: overlay: add_changeset_property() memory leak
  2019-11-21 19:16 [PATCH] of: overlay: add_changeset_property() memory leak frowand.list
@ 2019-11-21 19:20 ` Frank Rowand
  2019-11-25 15:17   ` Vincent Whitchurch
  2019-11-26 19:23 ` Rob Herring
  1 sibling, 1 reply; 4+ messages in thread
From: Frank Rowand @ 2019-11-21 19:20 UTC (permalink / raw)
  To: Rob Herring, Vincent Whitchurch, pantelis.antoniou, Pantelis Antoniou
  Cc: devicetree, linux-kernel, Vincent Whitchurch, geert, Alan Tull

Hi Vincent,

On 11/21/19 1:16 PM, frowand.list@gmail.com wrote:
> From: Frank Rowand <frank.rowand@sony.com>
> 
> No changeset entries are created for #address-cells and #size-cells
> properties, but the duplicated properties are never freed.  This
> results in a memory leak which is detected by kmemleak:
> 
>  unreferenced object 0x85887180 (size 64):
>    backtrace:
>      kmem_cache_alloc_trace+0x1fb/0x1fc
>      __of_prop_dup+0x25/0x7c
>      add_changeset_property+0x17f/0x370
>      build_changeset_next_level+0x29/0x20c
>      of_overlay_fdt_apply+0x32b/0x6b4
>      ...
> 
> Fixes: 6f75118800acf77f8 ("of: overlay: validate overlay properties #address-cells and #size-cells")
> Reported-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
> Signed-off-by: Frank Rowand <frank.rowand@sony.com>
> ---
>  drivers/of/overlay.c | 37 ++++++++++++++++++++-----------------
>  1 file changed, 20 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
> index c423e94baf0f..9617b7df7c4d 100644
> --- a/drivers/of/overlay.c
> +++ b/drivers/of/overlay.c
> @@ -305,7 +305,6 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
>  {
>  	struct property *new_prop = NULL, *prop;
>  	int ret = 0;
> -	bool check_for_non_overlay_node = false;
>  
>  	if (target->in_livetree)
>  		if (!of_prop_cmp(overlay_prop->name, "name") ||
> @@ -318,6 +317,25 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
>  	else
>  		prop = NULL;
>  
> +	if (prop) {
> +		if (!of_prop_cmp(prop->name, "#address-cells")) {
> +			if (!of_prop_val_eq(prop, overlay_prop)) {
> +				pr_err("ERROR: changing value of #address-cells is not allowed in %pOF\n",
> +				       target->np);
> +				ret = -EINVAL;
> +			}
> +			return ret;
> +
> +		} else if (!of_prop_cmp(prop->name, "#size-cells")) {
> +			if (!of_prop_val_eq(prop, overlay_prop)) {
> +				pr_err("ERROR: changing value of #size-cells is not allowed in %pOF\n",
> +				       target->np);
> +				ret = -EINVAL;
> +			}
> +			return ret;
> +		}
> +	}
> +
>  	if (is_symbols_prop) {
>  		if (prop)
>  			return -EINVAL;
> @@ -330,33 +348,18 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
>  		return -ENOMEM;
>  
>  	if (!prop) {
> -		check_for_non_overlay_node = true;
>  		if (!target->in_livetree) {
>  			new_prop->next = target->np->deadprops;
>  			target->np->deadprops = new_prop;
>  		}
>  		ret = of_changeset_add_property(&ovcs->cset, target->np,
>  						new_prop);
> -	} else if (!of_prop_cmp(prop->name, "#address-cells")) {
> -		if (!of_prop_val_eq(prop, new_prop)) {
> -			pr_err("ERROR: changing value of #address-cells is not allowed in %pOF\n",
> -			       target->np);
> -			ret = -EINVAL;
> -		}
> -	} else if (!of_prop_cmp(prop->name, "#size-cells")) {
> -		if (!of_prop_val_eq(prop, new_prop)) {
> -			pr_err("ERROR: changing value of #size-cells is not allowed in %pOF\n",
> -			       target->np);
> -			ret = -EINVAL;
> -		}
>  	} else {
> -		check_for_non_overlay_node = true;
>  		ret = of_changeset_update_property(&ovcs->cset, target->np,
>  						   new_prop);
>  	}
>  
> -	if (check_for_non_overlay_node &&
> -	    !of_node_check_flag(target->np, OF_OVERLAY))
> +	if (!of_node_check_flag(target->np, OF_OVERLAY))
>  		pr_err("WARNING: memory leak will occur if overlay removed, property: %pOF/%s\n",
>  		       target->np, new_prop->name);
>  
> 

Can you please check whether this patch fixes the memleak that you
found and fixed in "[PATCH 1/2] of: overlay: fix properties memory leak"?

Thanks,

Frank

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

* Re: [PATCH] of: overlay: add_changeset_property() memory leak
  2019-11-21 19:20 ` Frank Rowand
@ 2019-11-25 15:17   ` Vincent Whitchurch
  0 siblings, 0 replies; 4+ messages in thread
From: Vincent Whitchurch @ 2019-11-25 15:17 UTC (permalink / raw)
  To: Frank Rowand
  Cc: Rob Herring, pantelis.antoniou, Pantelis Antoniou, devicetree,
	linux-kernel, geert, Alan Tull

On Thu, Nov 21, 2019 at 08:20:21PM +0100, Frank Rowand wrote:
> On 11/21/19 1:16 PM, frowand.list@gmail.com wrote:
> > From: Frank Rowand <frank.rowand@sony.com>
> > 
> > No changeset entries are created for #address-cells and #size-cells
> > properties, but the duplicated properties are never freed.  This
> > results in a memory leak which is detected by kmemleak:
> > 
> >  unreferenced object 0x85887180 (size 64):
> >    backtrace:
> >      kmem_cache_alloc_trace+0x1fb/0x1fc
> >      __of_prop_dup+0x25/0x7c
> >      add_changeset_property+0x17f/0x370
> >      build_changeset_next_level+0x29/0x20c
> >      of_overlay_fdt_apply+0x32b/0x6b4
> >      ...
> > 
> > Fixes: 6f75118800acf77f8 ("of: overlay: validate overlay properties #address-cells and #size-cells")
> > Reported-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
> > Signed-off-by: Frank Rowand <frank.rowand@sony.com>
> 
> Can you please check whether this patch fixes the memleak that you
> found and fixed in "[PATCH 1/2] of: overlay: fix properties memory leak"?

Tested-by: Vincent Whitchurch <vincent.whitchurch@axis.com>

Thanks.

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

* Re: [PATCH] of: overlay: add_changeset_property() memory leak
  2019-11-21 19:16 [PATCH] of: overlay: add_changeset_property() memory leak frowand.list
  2019-11-21 19:20 ` Frank Rowand
@ 2019-11-26 19:23 ` Rob Herring
  1 sibling, 0 replies; 4+ messages in thread
From: Rob Herring @ 2019-11-26 19:23 UTC (permalink / raw)
  To: frowand.list
  Cc: Vincent Whitchurch, pantelis.antoniou, Pantelis Antoniou,
	devicetree, linux-kernel, Vincent Whitchurch, geert, Alan Tull

On Thu, 21 Nov 2019 13:16:56 -0600, frowand.list@gmail.com wrote:
> From: Frank Rowand <frank.rowand@sony.com>
> 
> No changeset entries are created for #address-cells and #size-cells
> properties, but the duplicated properties are never freed.  This
> results in a memory leak which is detected by kmemleak:
> 
>  unreferenced object 0x85887180 (size 64):
>    backtrace:
>      kmem_cache_alloc_trace+0x1fb/0x1fc
>      __of_prop_dup+0x25/0x7c
>      add_changeset_property+0x17f/0x370
>      build_changeset_next_level+0x29/0x20c
>      of_overlay_fdt_apply+0x32b/0x6b4
>      ...
> 
> Fixes: 6f75118800acf77f8 ("of: overlay: validate overlay properties #address-cells and #size-cells")
> Reported-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
> Signed-off-by: Frank Rowand <frank.rowand@sony.com>
> ---
>  drivers/of/overlay.c | 37 ++++++++++++++++++++-----------------
>  1 file changed, 20 insertions(+), 17 deletions(-)
> 

Applied, thanks.

Rob

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

end of thread, other threads:[~2019-11-26 19:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-21 19:16 [PATCH] of: overlay: add_changeset_property() memory leak frowand.list
2019-11-21 19:20 ` Frank Rowand
2019-11-25 15:17   ` Vincent Whitchurch
2019-11-26 19:23 ` Rob Herring

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).