LoongArch architecture development
 help / color / mirror / Atom feed
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 1/2] loongarch/vdso: add missing NULL check after kcalloc()
Date: Thu, 18 Sep 2025 14:44:47 +0800	[thread overview]
Message-ID: <20250918064448.91647-1-liu.yun@linux.dev> (raw)

From: Jackie Liu <liuyun01@kylinos.cn>

The kcalloc() call in init_vdso() allocates memory for code_mapping.pages,
but its return value was not validated before use. This could cause
NULL pointer dereference if allocation fails.

Add a check for the kcalloc() result and return -ENOMEM on failure.

Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 arch/loongarch/kernel/vdso.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/loongarch/kernel/vdso.c b/arch/loongarch/kernel/vdso.c
index 7b888d9085a0..088f8095210b 100644
--- a/arch/loongarch/kernel/vdso.c
+++ b/arch/loongarch/kernel/vdso.c
@@ -53,6 +53,8 @@ static int __init init_vdso(void)
 	vdso_info.size = PAGE_ALIGN(vdso_end - vdso_start);
 	vdso_info.code_mapping.pages =
 		kcalloc(vdso_info.size / PAGE_SIZE, sizeof(struct page *), GFP_KERNEL);
+	if (!vdso_info.code_mapping.pages)
+		return -ENOMEM;
 
 	pfn = __phys_to_pfn(__pa_symbol(vdso_info.vdso));
 	for (i = 0; i < vdso_info.size / PAGE_SIZE; i++)
-- 
2.51.0


             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 Jackie Liu [this message]
2025-09-18  6:44 ` [PATCH 2/2] loongarch/env: fix missing NULL check after kstrdup() Jackie Liu
2025-09-18  7:15   ` 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-1-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox