linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* A racy reading spot on n->free_objects in slab.c
@ 2021-04-13 22:06 Gong, Sishuai
  2021-04-14  7:32 ` Christoph Lameter
  0 siblings, 1 reply; 4+ messages in thread
From: Gong, Sishuai @ 2021-04-13 22:06 UTC (permalink / raw)
  To: cl, penberg, rientjes, iamjoonsoo.kim, akpm, vbabka; +Cc: linux-mm

Hi,

We found a racy reading spot on shared variable n->free_objects in slab.c and it can be data-racing with several writers that update this variable. As shown below, in function cache_alloc_refill(), n->free_objects will be read without any protection. It could be possible that the read value immediately becomes out-of-date when another writer is changing it (e.g. free_block())

Currently, we haven’t found any explicit errors due to this data race but we noticed 1) most of the reading spots on n->free_objects in slab.c have been protected by locks and 2) the racy result can affect the control flow, thus we want to point out this reader.

------------------------------------------
Execution interleaving

Thread 1 (reader)						Thread 2 (writer)

cache_alloc_refill()						free_block()

shared = READ_ONCE(n->shared);
if (!n->free_objects && (!shared || !shared->avail))
								n->free_objects += nr_objects;
							// lock protected
goto direct_grow;
spin_lock(&n->list_lock);



Thanks,
Sishuai


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-14 15:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-13 22:06 A racy reading spot on n->free_objects in slab.c Gong, Sishuai
2021-04-14  7:32 ` Christoph Lameter
2021-04-14 11:06   ` Vlastimil Babka
2021-04-14 15:09     ` Gong, Sishuai

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