mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
To: Saravana Kannan <saravanak@google.com>
Cc: <robh+dt@kernel.org>, <frowand.list@gmail.com>,
	<gregkh@linuxfoundation.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, Marc Zyngier <maz@kernel.org>
Subject: Re: [PATCH] of: property: Add missing of_node_get() in parse_interrupt()
Date: Wed, 1 Mar 2023 10:29:19 +0100	[thread overview]
Message-ID: <e335b715-471c-8e25-8eea-95ca1f64d17c@traphandler.com> (raw)
In-Reply-To: <CAGETcx-w4A3fz_DPqJG+9P6ETGAPv547DcnsO52gqTO1_vijsw@mail.gmail.com>


On 28/02/2023 20:07, Saravana Kannan wrote:
> On Tue, Feb 28, 2023 at 9:40 AM Jean-Jacques Hiblot
> <jjhiblot@traphandler.com> wrote:
>> From: Jean Jacques Hiblot <jjhiblot@traphandler.com>
>>
>> As all the other parsers do, parse_interrupt() must increase the refcount
>> of the device_node. Otherwise the refcount is decremented every time
>> parse_interrupt() is called on this node, leading to a potential
>> use-after-free.
>>
>> This is a regression introduced by commit f265f06af194 ("of: property:
>> Fix fw_devlink handling of interrupts/interrupts-extended"). The reason is
>> that of_irq_parse_one() does not increase the refcount while the previously
>> used of_irq_find_parent() does.
> Thanks for catching the issue Jean!
>
> This feels like a bug in of_irq_parse_one() to me. It's returning a
> reference to a node without doing a of_node_get() on it.
>
> Rob, Marc, Do you agree?

Sarvana,

it looks like you're right. The bug seems to be in of_irq_parse_one().

It doesn't behave in the same way for "interrupts-extended" where it 
does a get() and 'interrupts" where it doesn't.

So please ignore this patch.

Thanks

>
> Jean,
>
> If they agree, can you please fix of_irq_parse_one() and add a
> of_node_put() to existing callers (if they aren't already doing a
> put()).
>
> Thanks,
> Saravana
>
>> Fixes: f265f06af194 ("of: property: Fix fw_devlink handling of interrupts/interrupts-extended")
>> Signed-off-by: Jean Jacques Hiblot <jjhiblot@traphandler.com>
>> ---
>>   drivers/of/property.c | 5 ++++-
>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/of/property.c b/drivers/of/property.c
>> index 134cfc980b70b..1f23bcb765c4e 100644
>> --- a/drivers/of/property.c
>> +++ b/drivers/of/property.c
>> @@ -1380,7 +1380,10 @@ static struct device_node *parse_interrupts(struct device_node *np,
>>              strcmp(prop_name, "interrupts-extended"))
>>                  return NULL;
>>
>> -       return of_irq_parse_one(np, index, &sup_args) ? NULL : sup_args.np;
>> +       if (of_irq_parse_one(np, index, &sup_args))
>> +               return NULL;
>> +
>> +       return of_node_get(sup_args.np);
>>   }
>>
>>   static const struct supplier_bindings of_supplier_bindings[] = {
>> --
>> 2.25.1
>>

      parent reply	other threads:[~2023-03-01  9:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-28 17:40 Jean-Jacques Hiblot
2023-02-28 19:07 ` Saravana Kannan
2023-02-28 21:01   ` Rob Herring
2023-02-28 21:57     ` Saravana Kannan
2023-02-28 23:51       ` Rob Herring
2023-03-01  9:29   ` Jean-Jacques Hiblot [this message]

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=e335b715-471c-8e25-8eea-95ca1f64d17c@traphandler.com \
    --to=jjhiblot@traphandler.com \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=saravanak@google.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

all inboxes | Powered by JetHome®