All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: Dan Carpenter <dan.carpenter@linaro.org>,
	linux-riscv@lists.infradead.org
Cc: kernel-janitors@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>, Drew Fustini <drew@pdp7.com>,
	Fu Wei <wefu@redhat.com>, Guo Ren <guoren@kernel.org>,
	Michal Wilczynski <m.wilczynski@samsung.com>,
	Ulf Hansson <ulf.hansson@linaro.org>
Subject: Re: [PATCH next] firmware: thead,th1520-aon: Fix use after free in th1520_aon_init()
Date: Sun, 16 Mar 2025 13:05:08 +0100	[thread overview]
Message-ID: <d90c0678-d2ed-4e77-901a-fdbab7dfca71@web.de> (raw)
In-Reply-To: <f19be994-d355-48a6-ab45-d0f7e5955daf@stanley.mountain>

> Record the error code before freeing "aon_chan" to avoid a
> use after free.

Would it become helpful to mention which selection of source code
analysis tools detected such a questionable implementation detail?


…
> +++ b/drivers/firmware/thead,th1520-aon.c
> @@ -203,6 +203,7 @@ struct th1520_aon_chan *th1520_aon_init(struct device *dev)
>  {
>  	struct th1520_aon_chan *aon_chan;
>  	struct mbox_client *cl;
> +	int ret;
>
>  	aon_chan = kzalloc(sizeof(*aon_chan), GFP_KERNEL);
>  	if (!aon_chan)
> @@ -217,8 +218,9 @@ struct th1520_aon_chan *th1520_aon_init(struct device *dev)
>  	aon_chan->ch = mbox_request_channel_byname(cl, "aon");
>  	if (IS_ERR(aon_chan->ch)) {
>  		dev_err(dev, "Failed to request aon mbox chan\n");
> +		ret = PTR_ERR(aon_chan->ch);
>  		kfree(aon_chan);
> -		return ERR_CAST(aon_chan->ch);
> +		return ERR_PTR(ret);
>  	}
>
>  	mutex_init(&aon_chan->transaction_lock);

May the additional variable (for an information) be defined only for
the affected if branch?
Would a smaller scope be more appropriate here?

Regards,
Markus

WARNING: multiple messages have this Message-ID (diff)
From: Markus Elfring <Markus.Elfring@web.de>
To: Dan Carpenter <dan.carpenter@linaro.org>,
	linux-riscv@lists.infradead.org
Cc: kernel-janitors@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>, Drew Fustini <drew@pdp7.com>,
	Fu Wei <wefu@redhat.com>, Guo Ren <guoren@kernel.org>,
	Michal Wilczynski <m.wilczynski@samsung.com>,
	Ulf Hansson <ulf.hansson@linaro.org>
Subject: Re: [PATCH next] firmware: thead,th1520-aon: Fix use after free in th1520_aon_init()
Date: Sun, 16 Mar 2025 13:05:08 +0100	[thread overview]
Message-ID: <d90c0678-d2ed-4e77-901a-fdbab7dfca71@web.de> (raw)
In-Reply-To: <f19be994-d355-48a6-ab45-d0f7e5955daf@stanley.mountain>

> Record the error code before freeing "aon_chan" to avoid a
> use after free.

Would it become helpful to mention which selection of source code
analysis tools detected such a questionable implementation detail?


…
> +++ b/drivers/firmware/thead,th1520-aon.c
> @@ -203,6 +203,7 @@ struct th1520_aon_chan *th1520_aon_init(struct device *dev)
>  {
>  	struct th1520_aon_chan *aon_chan;
>  	struct mbox_client *cl;
> +	int ret;
>
>  	aon_chan = kzalloc(sizeof(*aon_chan), GFP_KERNEL);
>  	if (!aon_chan)
> @@ -217,8 +218,9 @@ struct th1520_aon_chan *th1520_aon_init(struct device *dev)
>  	aon_chan->ch = mbox_request_channel_byname(cl, "aon");
>  	if (IS_ERR(aon_chan->ch)) {
>  		dev_err(dev, "Failed to request aon mbox chan\n");
> +		ret = PTR_ERR(aon_chan->ch);
>  		kfree(aon_chan);
> -		return ERR_CAST(aon_chan->ch);
> +		return ERR_PTR(ret);
>  	}
>
>  	mutex_init(&aon_chan->transaction_lock);

May the additional variable (for an information) be defined only for
the affected if branch?
Would a smaller scope be more appropriate here?

Regards,
Markus

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2025-03-16 12:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-15 10:04 [PATCH next] firmware: thead,th1520-aon: Fix use after free in th1520_aon_init() Dan Carpenter
2025-03-15 10:04 ` Dan Carpenter
2025-03-16 12:05 ` Markus Elfring [this message]
2025-03-16 12:05   ` Markus Elfring
2025-03-16 14:20   ` Dan Carpenter
2025-03-16 14:20     ` Dan Carpenter
2025-03-18 12:14 ` Ulf Hansson
2025-03-18 12:14   ` Ulf Hansson

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=d90c0678-d2ed-4e77-901a-fdbab7dfca71@web.de \
    --to=markus.elfring@web.de \
    --cc=dan.carpenter@linaro.org \
    --cc=drew@pdp7.com \
    --cc=guoren@kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=m.wilczynski@samsung.com \
    --cc=ulf.hansson@linaro.org \
    --cc=wefu@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.