lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b8c90552-7be6-45bb-b586-ee21f63499c8@linux.dev>
Date: Thu, 23 Oct 2025 11:11:56 +0800
From: Hao Ge <hao.ge@...ux.dev>
To: Harry Yoo <harry.yoo@...cle.com>
Cc: Vlastimil Babka <vbabka@...e.cz>,
 Andrew Morton <akpm@...ux-foundation.org>, Christoph Lameter
 <cl@...two.org>, David Rientjes <rientjes@...gle.com>,
 Roman Gushchin <roman.gushchin@...ux.dev>,
 Suren Baghdasaryan <surenb@...gle.com>, Shakeel Butt
 <shakeel.butt@...ux.dev>, linux-mm@...ck.org, linux-kernel@...r.kernel.org,
 Hao Ge <gehao@...inos.cn>
Subject: Re: [PATCH] slab: Fix obj_ext is mistakenly considered NULL due to
 race condition

Hi Harry


On 2025/10/23 10:24, Harry Yoo wrote:
> On Thu, Oct 23, 2025 at 09:21:17AM +0800, Hao Ge wrote:
>> From: Hao Ge <gehao@...inos.cn>
>>
>> If two competing threads enter alloc_slab_obj_exts(), and the
>> thread that failed to allocate the object extension vector exits
>> after the one that succeeded, it will mistakenly assume slab->obj_ext
>> is still empty due to its own allocation failure. This will then trigger
>> warnings enforced by CONFIG_MEM_ALLOC_PROFILING_DEBUG checks in
>> the subsequent free path.
>>
>> Therefore, let's add an additional check when alloc_slab_obj_exts fails.
>>
>> Signed-off-by: Hao Ge <gehao@...inos.cn>
>> ---
>>   mm/slub.c | 9 ++++++---
>>   1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/mm/slub.c b/mm/slub.c
>> index d4403341c9df..42276f0cc920 100644
>> --- a/mm/slub.c
>> +++ b/mm/slub.c
>> @@ -2227,9 +2227,12 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p)
>>   	slab = virt_to_slab(p);
>>   	if (!slab_obj_exts(slab) &&
>>   	    alloc_slab_obj_exts(slab, s, flags, false)) {
>> -		pr_warn_once("%s, %s: Failed to create slab extension vector!\n",
>> -			     __func__, s->name);
>> -		return NULL;
>> +		/* Recheck if a racing thread has successfully allocated slab->obj_exts. */
>> +		if (!slab_obj_exts(slab)) {
>> +			pr_warn_once("%s, %s: Failed to create slab extension vector!\n",
>> +				     __func__, s->name);
>> +			return NULL;
>> +		}
>>   	}
> Maybe this patch is a bit paranoid... since if mark_failed_objexts_alloc()
> win cmpxchg() and then someone else allocates the object extension vector,
> the warning will still be printed anyway.


The process that successfully allocates slab_exts will call 
handle_failed_objexts_alloc, setting ref->ct = CODETAG_EMPTY

to prevent the warning from being triggered.


> But anyway, I think there is a better way to do this:
>
> diff --git a/mm/slub.c b/mm/slub.c
> index dd4c85ea1038..d08d7580349d 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -2052,9 +2052,9 @@ static inline void mark_objexts_empty(struct slabobj_ext *obj_exts)
>   	}
>   }
>   
> -static inline void mark_failed_objexts_alloc(struct slab *slab)
> +static inline bool mark_failed_objexts_alloc(struct slab *slab)
>   {
> -	cmpxchg(&slab->obj_exts, 0, OBJEXTS_ALLOC_FAIL);
> +	return cmpxchg(&slab->obj_exts, 0, OBJEXTS_ALLOC_FAIL) == 0;
>   }
>   
>   static inline void handle_failed_objexts_alloc(unsigned long obj_exts,
> @@ -2076,7 +2076,7 @@ static inline void handle_failed_objexts_alloc(unsigned long obj_exts,
>   #else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */
>   
>   static inline void mark_objexts_empty(struct slabobj_ext *obj_exts) {}
> -static inline void mark_failed_objexts_alloc(struct slab *slab) {}
> +static inline bool mark_failed_objexts_alloc(struct slab *slab) { return true; }
>   static inline void handle_failed_objexts_alloc(unsigned long obj_exts,
>   			struct slabobj_ext *vec, unsigned int objects) {}
>   
> @@ -2125,7 +2125,9 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
>   	}
>   	if (!vec) {
>   		/* Mark vectors which failed to allocate */
> -		mark_failed_objexts_alloc(slab);
> +		if (!mark_failed_objexts_alloc(slab) &&
> +			slab_obj_exts(slab))
> +			return 0;
>   
>   		return -ENOMEM;
>   	}
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ