Re: [PATCH][rc1] cgroup: catch bad css refcnt at css_put

From: KAMEZAWA Hiroyuki
Date: Mon Sep 28 2009 - 23:08:41 EST


On Mon, 28 Sep 2009 07:20:08 -0700
Paul Menage <menage@xxxxxxxxxx> wrote:

> On Mon, Sep 28, 2009 at 2:13 AM, KAMEZAWA Hiroyuki
> <kamezawa.hiroyu@xxxxxxxxxxxxxx> wrote:
> > This is a patch for checking css->refcnt's sanity at css_put().
> >
> > BTW, I noticed that...css->refcnt may overflow if used with memcg...
> > Now, refcnt is incremented per a page. Paul, do you have any idea ?
> > (Ah, yes. "don't use css->refcnt per page" is maybe reasonable but
> > Âit will be big change..)
> >
> > ==
> > __css_put() doesn't check a bug as refcnt goes to minus.
> > I think it should be caught. This patch adds a check for it.
> >
> > Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>
>
> Acked-by: Paul Menage <menage@xxxxxxxxxx>
>
Thanks.

> Looks reasonable, although there's no guarantee that it will warn on a
> buggy release rather than a correct release that occur after a buggy
> release.
>
yes, it's a problem of refcnt.

Thanks,
-Kame


> > ---
> > Âkernel/cgroup.c | Â Â5 ++++-
> > Â1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > Index: linux-2.6.32-rc1/kernel/cgroup.c
> > ===================================================================
> > --- linux-2.6.32-rc1.orig/kernel/cgroup.c
> > +++ linux-2.6.32-rc1/kernel/cgroup.c
> > @@ -3708,8 +3708,10 @@ static void check_for_release(struct cgr
> > Âvoid __css_put(struct cgroup_subsys_state *css)
> > Â{
> > Â Â Â Âstruct cgroup *cgrp = css->cgroup;
> > + Â Â Â int val;
> > Â Â Â Ârcu_read_lock();
> > - Â Â Â if (atomic_dec_return(&css->refcnt) == 1) {
> > + Â Â Â val = atomic_dec_return(&css->refcnt);
> > + Â Â Â if (val == 1) {
> > Â Â Â Â Â Â Â Âif (notify_on_release(cgrp)) {
> > Â Â Â Â Â Â Â Â Â Â Â Âset_bit(CGRP_RELEASABLE, &cgrp->flags);
> > Â Â Â Â Â Â Â Â Â Â Â Âcheck_for_release(cgrp);
> > @@ -3717,6 +3719,7 @@ void __css_put(struct cgroup_subsys_stat
> > Â Â Â Â Â Â Â Âcgroup_wakeup_rmdir_waiter(cgrp);
> > Â Â Â Â}
> > Â Â Â Ârcu_read_unlock();
> > + Â Â Â WARN_ON(val < 1);
> > Â}
> >
> > Â/*
> >
> >
>

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/