linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Reshetova, Elena" <elena.reshetova@intel.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"adobriyan@gmail.com" <adobriyan@gmail.com>,
	"serge@hallyn.com" <serge@hallyn.com>,
	"arozansk@redhat.com" <arozansk@redhat.com>,
	"dave@stgolabs.net" <dave@stgolabs.net>,
	"keescook@chromium.org" <keescook@chromium.org>,
	Hans Liljestrand <ishkamiel@gmail.com>,
	"David Windsor" <dwindsor@gmail.com>
Subject: RE: [PATCH 1/3] ipc: convert ipc_namespace.count from atomic_t to refcount_t
Date: Mon, 10 Jul 2017 06:48:22 +0000	[thread overview]
Message-ID: <2236FBA76BA1254E88B949DDB74E612B6FF2269B@IRSMSX102.ger.corp.intel.com> (raw)
In-Reply-To: <87bmottgo4.fsf@xmission.com>


> Elena Reshetova <elena.reshetova@intel.com> writes:
> 
> > refcount_t type and corresponding API should be
> > used instead of atomic_t when the variable is used as
> > a reference counter. This allows to avoid accidental
> > refcounter overflows that might lead to use-after-free
> > situations.
> 
> In this patch you can see all of the uses of the count.
> What accidental refcount overflows are possible?

Even if one can guarantee and prove that in the current implementation
there are no overflows possible, we can't say that for
sure for any future implementation. Bugs might always happen
unfortunately, but if we convert the refcounter to a safer
type we can be sure that overflows are not possible. 

Does it make sense to you?

Best Regards,
Elena.

> 
> Eric
> 
> > Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
> > Signed-off-by: Hans Liljestrand <ishkamiel@gmail.com>
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> > Signed-off-by: David Windsor <dwindsor@gmail.com>
> > ---
> >  include/linux/ipc_namespace.h | 5 +++--
> >  ipc/msgutil.c                 | 2 +-
> >  ipc/namespace.c               | 4 ++--
> >  3 files changed, 6 insertions(+), 5 deletions(-)
> >
> > diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
> > index 65327ee..e81445c 100644
> > --- a/include/linux/ipc_namespace.h
> > +++ b/include/linux/ipc_namespace.h
> > @@ -7,6 +7,7 @@
> >  #include <linux/notifier.h>
> >  #include <linux/nsproxy.h>
> >  #include <linux/ns_common.h>
> > +#include <linux/refcount.h>
> >
> >  struct user_namespace;
> >
> > @@ -19,7 +20,7 @@ struct ipc_ids {
> >  };
> >
> >  struct ipc_namespace {
> > -	atomic_t	count;
> > +	refcount_t	count;
> >  	struct ipc_ids	ids[3];
> >
> >  	int		sem_ctls[4];
> > @@ -118,7 +119,7 @@ extern struct ipc_namespace *copy_ipcs(unsigned long
> flags,
> >  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
> >  {
> >  	if (ns)
> > -		atomic_inc(&ns->count);
> > +		refcount_inc(&ns->count);
> >  	return ns;
> >  }
> >
> > diff --git a/ipc/msgutil.c b/ipc/msgutil.c
> > index bf74eaa..8459802 100644
> > --- a/ipc/msgutil.c
> > +++ b/ipc/msgutil.c
> > @@ -29,7 +29,7 @@ DEFINE_SPINLOCK(mq_lock);
> >   * and not CONFIG_IPC_NS.
> >   */
> >  struct ipc_namespace init_ipc_ns = {
> > -	.count		= ATOMIC_INIT(1),
> > +	.count		= REFCOUNT_INIT(1),
> >  	.user_ns = &init_user_ns,
> >  	.ns.inum = PROC_IPC_INIT_INO,
> >  #ifdef CONFIG_IPC_NS
> > diff --git a/ipc/namespace.c b/ipc/namespace.c
> > index b4d80f9..7af6e6b 100644
> > --- a/ipc/namespace.c
> > +++ b/ipc/namespace.c
> > @@ -50,7 +50,7 @@ static struct ipc_namespace *create_ipc_ns(struct
> user_namespace *user_ns,
> >  		goto fail_free;
> >  	ns->ns.ops = &ipcns_operations;
> >
> > -	atomic_set(&ns->count, 1);
> > +	refcount_set(&ns->count, 1);
> >  	ns->user_ns = get_user_ns(user_ns);
> >  	ns->ucounts = ucounts;
> >
> > @@ -144,7 +144,7 @@ static void free_ipc_ns(struct ipc_namespace *ns)
> >   */
> >  void put_ipc_ns(struct ipc_namespace *ns)
> >  {
> > -	if (atomic_dec_and_lock(&ns->count, &mq_lock)) {
> > +	if (refcount_dec_and_lock(&ns->count, &mq_lock)) {
> >  		mq_clear_sbinfo(ns);
> >  		spin_unlock(&mq_lock);
> >  		mq_put_mnt(ns);

  reply	other threads:[~2017-07-10  6:48 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-07  8:59 [PATCH 0/3] v2 ipc subsystem refcount coversions Elena Reshetova
2017-07-07  8:59 ` [PATCH 1/3] ipc: convert ipc_namespace.count from atomic_t to refcount_t Elena Reshetova
2017-07-09 21:59   ` Eric W. Biederman
2017-07-10  6:48     ` Reshetova, Elena [this message]
2017-07-10  8:37       ` Eric W. Biederman
2017-07-10  9:34         ` Alexey Dobriyan
2017-07-10 11:19           ` Eric W. Biederman
2017-07-10  9:56         ` Reshetova, Elena
2017-07-10 11:26           ` Eric W. Biederman
2017-07-10 12:11             ` Reshetova, Elena
2017-07-10 20:32               ` Eric W. Biederman
2017-07-12  9:21                 ` Reshetova, Elena
2017-07-19 22:35     ` Andrew Morton
2017-07-19 22:54       ` Davidlohr Bueso
2017-07-19 22:58         ` Andrew Morton
2017-07-19 23:11           ` Davidlohr Bueso
2017-07-19 23:20             ` Kees Cook
2017-07-20  0:32               ` Kees Cook
2017-07-20  9:34           ` Ingo Molnar
2017-07-20 12:34             ` Eric W. Biederman
2017-07-20 15:12               ` Kees Cook
2017-07-07  8:59 ` [PATCH 2/3] ipc: convert sem_undo_list.refcnt " Elena Reshetova
2017-07-07  8:59 ` [PATCH 3/3] ipc: convert kern_ipc_perm.refcount " Elena Reshetova
  -- strict thread matches above, loose matches on Subject: below --
2017-02-20 11:29 [PATCH 0/3] ipc subsystem refcounter conversions Elena Reshetova
2017-02-20 11:29 ` [PATCH 1/3] ipc: convert ipc_namespace.count from atomic_t to refcount_t Elena Reshetova
2017-05-27 19:41   ` Kees Cook
2017-05-28 12:10     ` Manfred Spraul

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=2236FBA76BA1254E88B949DDB74E612B6FF2269B@IRSMSX102.ger.corp.intel.com \
    --to=elena.reshetova@intel.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=arozansk@redhat.com \
    --cc=dave@stgolabs.net \
    --cc=dwindsor@gmail.com \
    --cc=ebiederm@xmission.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=ishkamiel@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=serge@hallyn.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;
as well as URLs for NNTP newsgroup(s).