linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Muchun Song <muchun.song@linux.dev>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>,
	Linux MM <linux-mm@kvack.org>, Qian Cai <cai@lca.pw>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: fix pgdat->kswap accessed concurrently
Date: Sat, 20 Aug 2022 13:59:55 -0700	[thread overview]
Message-ID: <20220820135955.1520aa480fe04ab31d4fce1f@linux-foundation.org> (raw)
In-Reply-To: <1E87F09C-4904-49E2-B45C-C408DD5F6F62@linux.dev>

On Sat, 20 Aug 2022 15:33:04 +0800 Muchun Song <muchun.song@linux.dev> wrote:

> 
> 
> > +	if (IS_ERR(t)) {
> > 		/* failure at boot is fatal */
> > 		BUG_ON(system_state < SYSTEM_RUNNING);
> > 		pr_err("Failed to start kswapd on node %d\n", nid);
> > -		pgdat->kswapd = NULL;
> > +		WRITE_ONCE(pgdat->kswapd, NULL);
> > +	} else {
> > +		WRITE_ONCE(pgdat->kswapd, t);
> > 	}
> > }
> 
> IIUC, the race is like the followings:
> 
> CPU 0:					CPU 1:
> 
> kswapd_run()
> 	pgdat->kswapd = kthread_run()
> 	if (IS_ERR(pgdat->kswapd))
> 					kswapd_is_running
> 						// load pgdat->kswapd and it is NOT NULL.
> 		pgdat->kswapd = NULL
> 						task_is_running(pgdat->kswapd); // NULL pointer dereference
> 

But don't we still have a bug?  Sure, kswapd_is_running() will no
longer deref a null pointer.  But it now runs kswapd_is_running()
against a task which has exited - a use-after-free?


  reply	other threads:[~2022-08-20 20:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-20  3:25 Kefeng Wang
2022-08-20  7:33 ` Muchun Song
2022-08-20 20:59   ` Andrew Morton [this message]
2022-08-23  1:07     ` Kefeng Wang
2022-08-23 14:47       ` Kefeng Wang
2022-08-24  7:03         ` Muchun Song
2022-08-24  6:59     ` Muchun Song

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=20220820135955.1520aa480fe04ab31d4fce1f@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=cai@lca.pw \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=wangkefeng.wang@huawei.com \
    /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