From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Balbir Singh <balbir@linux.vnet.ibm.com>,
Hugh Dickins <hugh@veritas.com>, Li Zefan <lizf@cn.fujitsu.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
"menage@google.com" <menage@google.com>
Subject: Re: [PATCH][mmotm]memcg: handle null dereference of mm->owner
Date: Fri, 5 Sep 2008 17:40:21 +0900 [thread overview]
Message-ID: <20080905174021.9fa29b01.kamezawa.hiroyu@jp.fujitsu.com> (raw)
In-Reply-To: <20080905165017.b2715fe4.nishimura@mxp.nes.nec.co.jp>
On Fri, 5 Sep 2008 16:50:17 +0900
Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> wrote:
> Hi.
>
> mm_update_next_owner() may clear mm->owner to NULL
> if it races with swapoff, page migration, etc.
> (This behavior was introduced by mm-owner-fix-race-between-swap-and-exit.patch.)
>
> But memcg doesn't take account of this situation, and causes:
>
> BUG: unable to handle kernel NULL pointer dereference at 0000000000000630
>
> This fixes it.
>
Thank you for catching this.
BTW, I have a question to Balbir and Paul. (I'm sorry I missed the discussion.)
Recently I wonder why we need MM_OWNER.
- What's bad with thread's cgroup ?
- Why we can't disallow per-thread cgroup under memcg ?)
Thanks,
-Kame
>
> Signed-off-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
>
> ---
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 2979d22..ec2c16b 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -244,6 +244,14 @@ static struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont)
>
> struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)
> {
> + /*
> + * mm_update_next_owner() may clear mm->owner to NULL
> + * if it races with swapoff, page migration, etc.
> + * So this can be called with p == NULL.
> + */
> + if (unlikely(!p))
> + return NULL;
> +
> return container_of(task_subsys_state(p, mem_cgroup_subsys_id),
> struct mem_cgroup, css);
> }
> @@ -534,6 +542,11 @@ static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,
> if (likely(!memcg)) {
> rcu_read_lock();
> mem = mem_cgroup_from_task(rcu_dereference(mm->owner));
> + if (unlikely(!mem)) {
> + rcu_read_unlock();
> + kmem_cache_free(page_cgroup_cache, pc);
> + return 0;
> + }
> /*
> * For every charge from the cgroup, increment reference count
> */
> @@ -790,6 +803,10 @@ int mem_cgroup_shrink_usage(struct mm_struct *mm, gfp_t gfp_mask)
>
> rcu_read_lock();
> mem = mem_cgroup_from_task(rcu_dereference(mm->owner));
> + if (unlikely(!mem)) {
> + rcu_read_unlock();
> + return 0;
> + }
> css_get(&mem->css);
> rcu_read_unlock();
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2008-09-05 8:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-05 7:50 Daisuke Nishimura
2008-09-05 8:40 ` KAMEZAWA Hiroyuki [this message]
2008-09-05 9:45 ` Balbir Singh
2008-09-05 16:03 ` Paul Menage
2008-09-07 15:33 ` Balbir Singh
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=20080905174021.9fa29b01.kamezawa.hiroyu@jp.fujitsu.com \
--to=kamezawa.hiroyu@jp.fujitsu.com \
--cc=akpm@linux-foundation.org \
--cc=balbir@linux.vnet.ibm.com \
--cc=hugh@veritas.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lizf@cn.fujitsu.com \
--cc=menage@google.com \
--cc=nishimura@mxp.nes.nec.co.jp \
/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