From: Kees Cook <keescook@chromium.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Xiaoming Ni <nixiaoming@huawei.com>,
paul@paul-moore.com, edumazet@google.com, paulmck@kernel.org,
dhowells@redhat.com, shakeelb@google.com,
jamorris@linux.microsoft.com, alex.huangjianhui@huawei.com,
dylix.dailei@huawei.com, chenzefeng2@huawei.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC] cred: Add WARN to detect wrong use of get/put_cred
Date: Fri, 12 Jun 2020 10:06:49 -0700 [thread overview]
Message-ID: <202006121001.149B5D20C5@keescook> (raw)
In-Reply-To: <20200612163345.GF2497@hirez.programming.kicks-ass.net>
On Fri, Jun 12, 2020 at 06:33:45PM +0200, Peter Zijlstra wrote:
> On Fri, Jun 12, 2020 at 06:28:15PM +0800, Xiaoming Ni 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.
>
> Why not not use refcount_t? It has all that goodness and more.
I thought these had been applied already, I guess not:
https://lore.kernel.org/lkml/20190306110549.7628-1-elena.reshetova@intel.com/
Can we try again?
--
Kees Cook
prev parent reply other threads:[~2020-06-12 17:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-12 10:28 [PATCH RFC] cred: Add WARN to detect wrong use of get/put_cred Xiaoming Ni
2020-06-12 16:16 ` David Laight
2020-06-12 16:32 ` Eric Dumazet
2020-06-12 16:33 ` Peter Zijlstra
2020-06-12 17:06 ` Kees Cook [this message]
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=202006121001.149B5D20C5@keescook \
--to=keescook@chromium.org \
--cc=alex.huangjianhui@huawei.com \
--cc=chenzefeng2@huawei.com \
--cc=dhowells@redhat.com \
--cc=dylix.dailei@huawei.com \
--cc=edumazet@google.com \
--cc=jamorris@linux.microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nixiaoming@huawei.com \
--cc=paul@paul-moore.com \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=shakeelb@google.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