From: Jackie Liu <liu.yun@linux.dev>
To: chenhuacai@kernel.org
Cc: kernel@xen0n.name, loongarch@lists.linux.dev, liu.yun@linux.dev
Subject: [PATCH 2/2] loongarch/env: fix missing NULL check after kstrdup()
Date: Thu, 18 Sep 2025 14:44:48 +0800 [thread overview]
Message-ID: <20250918064448.91647-2-liu.yun@linux.dev> (raw)
In-Reply-To: <20250918064448.91647-1-liu.yun@linux.dev>
From: Jackie Liu <liuyun01@kylinos.cn>
The result of kstrdup() may be NULL when memory allocation fails.
In init_cpu_fullname(), the return value was used directly by strsep()
without validation, which could lead to NULL pointer dereference.
Add a proper check for the kstrdup() result and return -ENOMEM when
allocation fails.
Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
arch/loongarch/kernel/env.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/loongarch/kernel/env.c b/arch/loongarch/kernel/env.c
index c0a5dc9aeae2..b41a65ec45c3 100644
--- a/arch/loongarch/kernel/env.c
+++ b/arch/loongarch/kernel/env.c
@@ -49,6 +49,8 @@ static int __init init_cpu_fullname(void)
ret = of_property_read_string(root, "model", &model);
if (ret == 0) {
cpuname = kstrdup(model, GFP_KERNEL);
+ if (!cpuname)
+ return -ENOMEM;
loongson_sysconf.cpuname = strsep(&cpuname, " ");
}
of_node_put(root);
--
2.51.0
next prev parent reply other threads:[~2025-09-18 6:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-18 6:44 [PATCH 1/2] loongarch/vdso: add missing NULL check after kcalloc() Jackie Liu
2025-09-18 6:44 ` Jackie Liu [this message]
2025-09-18 7:15 ` [PATCH 2/2] loongarch/env: fix missing NULL check after kstrdup() Huacai Chen
2025-09-18 7:27 ` Jackie Liu
2025-09-18 7:17 ` [PATCH 1/2] loongarch/vdso: add missing NULL check after kcalloc() Huacai Chen
2025-09-18 7:24 ` Jackie Liu
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=20250918064448.91647-2-liu.yun@linux.dev \
--to=liu.yun@linux.dev \
--cc=chenhuacai@kernel.org \
--cc=kernel@xen0n.name \
--cc=loongarch@lists.linux.dev \
/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.