linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] mm/page_alloc.c: function call alloc_percpu() unchecked
       [not found] <20231012082535.7135-1-810974084@qq.com>
@ 2023-10-14 23:01 ` Andrew Morton
  0 siblings, 0 replies; only message in thread
From: Andrew Morton @ 2023-10-14 23:01 UTC (permalink / raw)
  To: Huai-Yuan Liu; +Cc: linux-mm, linux-kernel

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.



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-10-14 23:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20231012082535.7135-1-810974084@qq.com>
2023-10-14 23:01 ` [PATCH] mm/page_alloc.c: function call alloc_percpu() unchecked Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox