Linux Perf Users
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: Henry Martin <bsdhenrymartin@gmail.com>,
	linux-perf-users@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Cc: LKML <linux-kernel@vger.kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Will Deacon <will@kernel.org>
Subject: Re: [PATCH v3] driver: tx2: Add NULL check in tx2_uncore_pmu_register
Date: Mon, 31 Mar 2025 17:00:21 +0200	[thread overview]
Message-ID: <b1749989-ae58-4b1d-b228-62c996dfe87d@web.de> (raw)
In-Reply-To: <20250331144324.12940-1-bsdhenrymartin@gmail.com>

> devm_kasprintf() returns NULL if memory allocation fails.

                call                                 failed?


>                                                           Currently,
> tx2_uncore_pmu_register() does not check for this case, leading to a
> NULL pointer dereference.

This (temporary) view should be reconsidered in more detail.


> No automated tools were used;

Further development tools can help for such analysis attempts.


>                               this was found during manual code review.

This approach might be misleading so far.


…
> +++ b/drivers/perf/thunderx2_pmu.c
> @@ -738,7 +738,8 @@ static int tx2_uncore_pmu_register(
>
>  	tx2_pmu->pmu.name = devm_kasprintf(dev, GFP_KERNEL,
>  			"%s", name);
> -
> +	if (!tx2_pmu->pmu.name)
> +		return -ENOMEM;
>  	return perf_pmu_register(&tx2_pmu->pmu, tx2_pmu->pmu.name, -1);
>  }
…

Should your source code analysis approaches take further implementation details
better into account?

Example:
perf_pmu_register()
https://elixir.bootlin.com/linux/v6.14-rc6/source/kernel/events/core.c#L11859-L11862
…
	if (WARN_ONCE(!name, "Can not register anonymous pmu.\n")) {
		ret = -EINVAL;
…


Regards,
Markus

      reply	other threads:[~2025-03-31 15:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-31 14:43 [PATCH v3] driver: tx2: Add NULL check in tx2_uncore_pmu_register Henry Martin
2025-03-31 15:00 ` Markus Elfring [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=b1749989-ae58-4b1d-b228-62c996dfe87d@web.de \
    --to=markus.elfring@web.de \
    --cc=bsdhenrymartin@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=will@kernel.org \
    /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