mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jiaxun Yang" <jiaxun.yang@flygoat.com>
To: "Yao Zi" <ziyao@disroot.org>,
	"Huacai Chen" <chenhuacai@kernel.org>,
	"Xuerui Wang" <kernel@xen0n.name>,
	"Miaoqian Lin" <linmq006@gmail.com>,
	"Hongliang Wang" <wanghongliang@loongson.cn>,
	"Binbin Zhou" <zhoubinbin@loongson.cn>
Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org,
	"Mingcong Bai" <jeffbai@aosc.io>,
	"Kexy Biscuit" <kexybiscuit@aosc.io>
Subject: Re: [PATCH] LoongArch: Avoid in-place string operation on FDT content
Date: Sat, 05 Jul 2025 15:05:47 +0100	[thread overview]
Message-ID: <2ad0ae43-0331-4860-8f39-34ebfe02cae8@app.fastmail.com> (raw)
In-Reply-To: <20250705125710.59994-1-ziyao@disroot.org>



在2025年7月5日周六 下午1:57,Yao Zi写道:
> In init_cpu_fullname, a constant pointer to model property is retrieved.
> It's later modified by the strsep function, which is illegal and
> corrupts kernel's FDT copy. This is shown by dmesg,
>
> 	OF: fdt: not creating '/sys/firmware/fdt': CRC check failed
>
> Create a mutable copy of the model property and do in-place operations
> on it instead. loongson_sysconf.cpuname lives across the kernel
> lifetime, thus manually releasing isn't necessary.
>
> Also move of_node_put() for the root node after the usage of its
> property, since of_node_put() decreases the reference counter thus usage
> after the call is unsafe.
>
> Fixes: 44a01f1f726a ("LoongArch: Parsing CPU-related information from DTS")

Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>

> Signed-off-by: Yao Zi <ziyao@disroot.org>
> ---
>  arch/loongarch/kernel/env.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/arch/loongarch/kernel/env.c b/arch/loongarch/kernel/env.c
> index 27144de5c5fe..fba141472ab9 100644
> --- a/arch/loongarch/kernel/env.c
> +++ b/arch/loongarch/kernel/env.c
> @@ -40,15 +40,18 @@ void __init init_environ(void)
>  static int __init init_cpu_fullname(void)
>  {
>  	struct device_node *root;
> +	const char *model;
>  	int cpu, ret;
> -	char *model;
> +	char *tmp;
> 
>  	/* Parsing cpuname from DTS model property */
>  	root = of_find_node_by_path("/");
> -	ret = of_property_read_string(root, "model", (const char **)&model);
> +	ret = of_property_read_string(root, "model", &model);
> +	if (ret == 0) {
> +		tmp = kstrdup(model, GFP_KERNEL);
> +		loongson_sysconf.cpuname = strsep(&tmp, " ");
> +	}
>  	of_node_put(root);
> -	if (ret == 0)
> -		loongson_sysconf.cpuname = strsep(&model, " ");
> 
>  	if (loongson_sysconf.cpuname && !strncmp(loongson_sysconf.cpuname, 
> "Loongson", 8)) {
>  		for (cpu = 0; cpu < NR_CPUS; cpu++)
> -- 
> 2.49.0

-- 
- Jiaxun

  reply	other threads:[~2025-07-05 14:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-05 12:57 Yao Zi
2025-07-05 14:05 ` Jiaxun Yang [this message]
2025-07-08 12:37   ` Huacai Chen

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=2ad0ae43-0331-4860-8f39-34ebfe02cae8@app.fastmail.com \
    --to=jiaxun.yang@flygoat.com \
    --cc=chenhuacai@kernel.org \
    --cc=jeffbai@aosc.io \
    --cc=kernel@xen0n.name \
    --cc=kexybiscuit@aosc.io \
    --cc=linmq006@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=wanghongliang@loongson.cn \
    --cc=zhoubinbin@loongson.cn \
    --cc=ziyao@disroot.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®