linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Huai-Yuan Liu <810974084@qq.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/page_alloc.c: function call alloc_percpu() unchecked
Date: Sat, 14 Oct 2023 16:01:04 -0700	[thread overview]
Message-ID: <20231014160104.19912de669475deec235702d@linux-foundation.org> (raw)
In-Reply-To: <20231012082535.7135-1-810974084@qq.com>

On Thu, 12 Oct 2023 01:25:35 -0700 Huai-Yuan Liu <810974084@qq.com> wrote:

> The function call alloc_percpu() returns a pointer to the memory address,
> but it hasn't been checked. Our static analysis tool indicates that null
> pointer dereference may exist in pointer zone->per_cpu_pageset. It is
> always safe to judge the null pointer before use.
> 
> ...
>
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -5390,6 +5390,8 @@ void __meminit setup_zone_pageset(struct zone *zone)
>  		zone->per_cpu_zonestats = alloc_percpu(struct per_cpu_zonestat);
>  
>  	zone->per_cpu_pageset = alloc_percpu(struct per_cpu_pages);
> +	if (!zone->per_cpu_pageset)
> +		return;
>  	for_each_possible_cpu(cpu) {
>  		struct per_cpu_pages *pcp;
>  		struct per_cpu_zonestat *pzstats;

I suppose as it's __meminit, yes, we should be checking here.

In which case we should also be checking the alloc_percpu() two lines
earlier and we should be freeing zone->per_cpu_zonestats if this second
alloc_percpu() fails.  And we should be propagating the overall failure
back to higher layers whihc then handle it so the kernel won't immediately
crash anwyay.



           reply	other threads:[~2023-10-14 23:01 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20231012082535.7135-1-810974084@qq.com>]

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=20231014160104.19912de669475deec235702d@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=810974084@qq.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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