linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Gong, Sishuai" <sishuai@purdue.edu>
To: "cl@linux.com" <cl@linux.com>,
	"penberg@kernel.org" <penberg@kernel.org>,
	"rientjes@google.com" <rientjes@google.com>,
	"iamjoonsoo.kim@lge.com" <iamjoonsoo.kim@lge.com>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"vbabka@suse.cz" <vbabka@suse.cz>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>
Subject: A racy reading spot on n->free_objects in slab.c
Date: Tue, 13 Apr 2021 22:06:40 +0000	[thread overview]
Message-ID: <BD83F9C4-BC29-4206-A140-B066AEAC1B40@purdue.edu> (raw)

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


             reply	other threads:[~2021-04-13 22:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-13 22:06 Gong, Sishuai [this message]
2021-04-14  7:32 ` Christoph Lameter
2021-04-14 11:06   ` Vlastimil Babka
2021-04-14 15:09     ` Gong, Sishuai

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=BD83F9C4-BC29-4206-A140-B066AEAC1B40@purdue.edu \
    --to=sishuai@purdue.edu \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=vbabka@suse.cz \
    /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