devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frank Rowand <frowand.list@gmail.com>
To: Rob Herring <robh@kernel.org>, Slawomir Stepien <sst@poczta.fm>
Cc: pantelis.antoniou@konsulko.com, devicetree@vger.kernel.org,
	krzysztof.adamski@nokia.com, tomasz.medrek@nokia.com,
	alexander.sverdlin@nokia.com
Subject: Re: [PATCH] of: overlay: set 'overlay_tree' and 'fdt' fields only on success
Date: Thu, 7 Apr 2022 14:53:07 -0500	[thread overview]
Message-ID: <2f5b4459-3fbe-a2b1-def4-e45475599c28@gmail.com> (raw)
In-Reply-To: <4375072d-abb4-6ff6-d1a0-4c2fca54cf39@gmail.com>

Hi Slawomir,

 On 4/4/22 16:02, Frank Rowand wrote:
> On 4/4/22 15:38, Rob Herring wrote:
>> On Thu, Mar 31, 2022 at 11:56:33AM +0200, Slawomir Stepien wrote:
>>> From: Slawomir Stepien <slawomir.stepien@nokia.com>
>>>
>>> Before this change, the memory pointed by fields 'overlay_tree' and
>>> 'fdt' will be double freed by a call to free_overlay_changeset() from
>>> of_overlay_apply(), when the init_overlay_changeset() fails.
>>>
>>> The first free will happen under 'err_free_tree' label and for the
>>> second time under 'err_free_overlay_changeset' label, where we call
>>> free_overlay_changeset().
>>>
>>> This could happen for example, when you are applying an overlay to a
>>> target path that does not exists.
>>>
>>> By setting the pointers only when we are sure that
>>> init_overlay_changeset() will not fail, will prevent this double free.
>>
>> It looks to me like the free should just be moved from 
>> init_overlay_changeset() to of_overlay_fdt_apply() where the allocation 
>> is done. Frank?
> 
> This patch is next on my list to look over.

Thanks for finding this problem.  While investigating what you reported
I found that there are additional related issues.  I am in the process
of testing a patch to fix all of the issues.

-Frank

> 
> -Frank
> 
>>
>> Also, I believe there's a bug that of_overlay_apply() should be passed 
>> new_fdt_align rather than new_fdt. It's only a bug if we expect 
>> overlay_changeset.fdt to point to a valid fdt rather than the memory 
>> allocation.
>>
>> Rob
> 


  reply	other threads:[~2022-04-07 20:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-31  9:56 [PATCH] of: overlay: set 'overlay_tree' and 'fdt' fields only on success Slawomir Stepien
2022-03-31 10:06 ` Alexander Sverdlin
2022-04-04 20:38 ` Rob Herring
2022-04-04 21:02   ` Frank Rowand
2022-04-07 19:53     ` Frank Rowand [this message]
2022-04-08  6:05       ` Slawomir Stepien
2022-04-10 20:30   ` Frank Rowand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2f5b4459-3fbe-a2b1-def4-e45475599c28@gmail.com \
    --to=frowand.list@gmail.com \
    --cc=alexander.sverdlin@nokia.com \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.adamski@nokia.com \
    --cc=pantelis.antoniou@konsulko.com \
    --cc=robh@kernel.org \
    --cc=sst@poczta.fm \
    --cc=tomasz.medrek@nokia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).