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: <8bc1aebf-8395-416f-8c23-53cbd25d0eef@linux.dev>
Date: Sat, 9 Mar 2024 19:24:11 +0800
From: Chengming Zhou <chengming.zhou@...ux.dev>
To: linke li <lilinke99@...com>
Cc: Christoph Lameter <cl@...ux.com>, Pekka Enberg <penberg@...nel.org>,
 David Rientjes <rientjes@...gle.com>, Joonsoo Kim <iamjoonsoo.kim@....com>,
 Andrew Morton <akpm@...ux-foundation.org>, Vlastimil Babka <vbabka@...e.cz>,
 Roman Gushchin <roman.gushchin@...ux.dev>,
 Hyeonggon Yoo <42.hyeyoo@...il.com>, linux-mm@...ck.org,
 linux-kernel@...r.kernel.org
Subject: Re: [PATCH] mm/slub: mark racy accesses on slab->slabs

On 2024/3/9 15:48, linke li wrote:
> The reads of slab->slabs are racy because it may be changed by 
> put_cpu_partial concurrently. And in slabs_cpu_partial_show ->slabs is
> only used for output. Data-racy reads from shared variables that are used
> only for diagnostic purposes should typically use data_race(), since it 
> is normally not a problem if the values are off by a little.
> 
> This patch is aimed at reducing the number of benign races reported by 
> KCSAN in order to focus future debugging effort on harmful races.
> 
> Signed-off-by: linke li <lilinke99@...com>
> ---
>  mm/slub.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index 2ef88bbf56a3..7b20591e7f8a 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -6257,7 +6257,7 @@ static ssize_t slabs_cpu_partial_show(struct kmem_cache *s, char *buf)
>  		slab = slub_percpu_partial(per_cpu_ptr(s->cpu_slab, cpu));
>  
>  		if (slab)
> -			slabs += slab->slabs;
> +			slabs += data_race(slab->slabs);
>  	}
>  #endif
>  
> @@ -6271,7 +6271,7 @@ static ssize_t slabs_cpu_partial_show(struct kmem_cache *s, char *buf)
>  
>  		slab = slub_percpu_partial(per_cpu_ptr(s->cpu_slab, cpu));
>  		if (slab) {
> -			slabs = READ_ONCE(slab->slabs);
> +			slabs = data_race(slab->slabs);
>  			objects = (slabs * oo_objects(s->oo)) / 2;
>  			len += sysfs_emit_at(buf, len, " C%d=%d(%d)",
>  					     cpu, objects, slabs);

There is another unmarked access of "slab->slabs" in the show_slab_objects(),
which you can change too.

I'm not sure that it's really safe to access "slab->slabs" here without any protection?
Although it should be no problem in practice, alternative choice maybe putting partial
slabs count in the kmem_cache_cpu struct.

Thanks.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ