From: "Jackie Liu" <liu.yun@linux.dev>
To: "Huacai Chen" <chenhuacai@kernel.org>
Cc: kernel@xen0n.name, loongarch@lists.linux.dev
Subject: Re: [PATCH 1/2] loongarch/vdso: add missing NULL check after kcalloc()
Date: Thu, 18 Sep 2025 07:24:04 +0000 [thread overview]
Message-ID: <ce8e83a9ce71d412153d069c0b742917d7b33e11@linux.dev> (raw)
In-Reply-To: <CAAhV-H62aEKNtwEjSnrxPSVuTzXS=eNmJ2+8fYRk3Q--V0mLig@mail.gmail.com>
2025年9月18日 15:17, "Huacai Chen" <chenhuacai@kernel.org mailto:chenhuacai@kernel.org?to=%22Huacai%20Chen%22%20%3Cchenhuacai%40kernel.org%3E > 写到:
Hi Huacai
>
> Hi, Jackie,
>
> Someone has already sent a patch and be applied, don't you know?
>
> https://lore.kernel.org/loongarch/CAAhV-H6hTFrUO5gTx6FYo89TAouEykTvKpLNkqFfhtsg0PVLiw@mail.gmail.com/T/#t
>
> Huacai
Ah, I just checked Linus's tree, While looking into other
memory allocation failures, I took the chance to try fixing this as well. Thanks
for pointing it out.
---
Jackie Liu
>
> On Thu, Sep 18, 2025 at 2:45 PM Jackie Liu <liu.yun@linux.dev> wrote:
>
> >
> > 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
> >
>
prev parent reply other threads:[~2025-09-18 7:24 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 ` [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 [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=ce8e83a9ce71d412153d069c0b742917d7b33e11@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