mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>
To: Pengpeng Hou <pengpeng@iscas.ac.cn>,
	Daniel Lezcano <daniel.lezcano@kernel.org>,
	Thomas Gleixner <tglx@kernel.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] clocksource/drivers/timer-sp804: validate DT compatible before using it as a name
Date: Fri, 3 Apr 2026 10:08:28 +0200	[thread overview]
Message-ID: <fac94f92-3e59-4bb4-ae94-88d0b6a54ccb@oss.qualcomm.com> (raw)
In-Reply-To: <20260403183505.5-timer-sp804-compatible-pengpeng@iscas.ac.cn>


Hi Pengpeng,

On 4/3/26 08:55, Pengpeng Hou wrote:
> `sp804_of_init()` and `integrator_cp_of_init()` fetch raw
> `"compatible"` bytes with `of_get_property()` and then pass the returned
> pointer onward as the timer name.
> 
> That name is used in later clock lookup and clocksource / clockevent
> registration paths, so malformed unterminated live-tree properties can
> trigger out-of-bounds reads before timer initialization completes.
> 
> Validate the compatible string before using it as a C string.

If the function is called it is because there is a match with the 
compatible string. It is pointless to check if it is valid because the 
location of the executing code is under the condition the compatible exists.


> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
> 
> ---
>   drivers/clocksource/timer-sp804.c | 12 ++++++++++--
>   1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/clocksource/timer-sp804.c b/drivers/clocksource/timer-sp804.c
> index d69858427359..8164ceefee06 100644
> --- a/drivers/clocksource/timer-sp804.c
> +++ b/drivers/clocksource/timer-sp804.c
> @@ -284,7 +284,11 @@ static int __init sp804_of_init(struct device_node *np, struct sp804_timer *time
>   	int irq, ret = -EINVAL;
>   	u32 irq_num = 0;
>   	struct clk *clk1, *clk2;
> -	const char *name = of_get_property(np, "compatible", NULL);
> +	const char *name;
> +
> +	ret = of_property_read_string(np, "compatible", &name);
> +	if (ret)
> +		return ret;
>   
>   	if (initialized) {
>   		pr_debug("%pOF: skipping further SP804 timer device\n", np);
> @@ -371,9 +375,13 @@ static int __init integrator_cp_of_init(struct device_node *np)
>   	static int init_count = 0;
>   	void __iomem *base;
>   	int irq, ret = -EINVAL;
> -	const char *name = of_get_property(np, "compatible", NULL);
> +	const char *name;
>   	struct clk *clk;
>   
> +	ret = of_property_read_string(np, "compatible", &name);
> +	if (ret)
> +		return ret;
> +
>   	base = of_iomap(np, 0);
>   	if (!base) {
>   		pr_err("Failed to iomap\n");


      reply	other threads:[~2026-04-03  8:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-03  6:55 Pengpeng Hou
2026-04-03  8:08 ` Daniel Lezcano [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=fac94f92-3e59-4bb4-ae94-88d0b6a54ccb@oss.qualcomm.com \
    --to=daniel.lezcano@oss.qualcomm.com \
    --cc=daniel.lezcano@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pengpeng@iscas.ac.cn \
    --cc=tglx@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

all inboxes | Powered by JetHome®