[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANn89i+yWQ_rO29NDuXZ7XWho_gTShUpujUN+jZop46W7e2qyw@mail.gmail.com>
Date: Fri, 12 Jun 2020 09:32:39 -0700
From: Eric Dumazet <edumazet@...gle.com>
To: Xiaoming Ni <nixiaoming@...wei.com>
Cc: Paul Moore <paul@...l-moore.com>,
Peter Zijlstra <peterz@...radead.org>,
"Paul E. McKenney" <paulmck@...nel.org>,
David Howells <dhowells@...hat.com>,
Kees Cook <keescook@...omium.org>,
Shakeel Butt <shakeelb@...gle.com>,
jamorris@...ux.microsoft.com, alex.huangjianhui@...wei.com,
dylix.dailei@...wei.com, chenzefeng2@...wei.com,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH RFC] cred: Add WARN to detect wrong use of get/put_cred
On Fri, Jun 12, 2020 at 3:28 AM Xiaoming Ni <nixiaoming@...wei.com> wrote:
>
> Cred release and usage check code flow:
> 1. put_cred()
> if (atomic_dec_and_test(&(cred)->usage))
> __put_cred(cred);
>
> 2. __put_cred()
> BUG_ON(atomic_read(&cred->usage) != 0);
> call_rcu(&cred->rcu, put_cred_rcu);
>
> 3. put_cred_rcu()
> if (atomic_read(&cred->usage) != 0)
> panic("CRED: put_cred_rcu() sees %p with usage %d\n",
> cred, atomic_read(&cred->usage));
> kmem_cache_free(cred_jar, cred);
>
> If panic is triggered on put_cred_rcu(), there are two possibilities
> 1. Call get_cred() after __put_cred(), usage > 0
> 2. Call put_cred() after __put_cred(), usage < 0
> Since put_cred_rcu is an asynchronous behavior, it is no longer the first
> scene when panic, there is no information about the murderer in the panic
> call stack...
>
> So, add WARN() in get_cred()/put_cred(), and pray to catch the murderer
> at the first scene.
>
> Signed-off-by: Xiaoming Ni <nixiaoming@...wei.com>
> ---
It seems you reinvented refcount_t ?
Powered by blists - more mailing lists