From: Elena Reshetova <elena.reshetova@intel.com>
To: linux-kernel@vger.kernel.org
Cc: peterz@infradead.org, gregkh@linuxfoundation.org,
akpm@linux-foundation.org, ebiederm@xmission.com,
mingo@redhat.com, adobriyan@gmail.com, serge@hallyn.com,
arozansk@redhat.com, dave@stgolabs.net, keescook@chromium.org,
Elena Reshetova <elena.reshetova@intel.com>,
Hans Liljestrand <ishkamiel@gmail.com>,
David Windsor <dwindsor@gmail.com>
Subject: [PATCH 3/3] ipc: convert kern_ipc_perm.refcount from atomic_t to refcount_t
Date: Fri, 7 Jul 2017 11:59:52 +0300 [thread overview]
Message-ID: <1499417992-3238-4-git-send-email-elena.reshetova@intel.com> (raw)
In-Reply-To: <1499417992-3238-1-git-send-email-elena.reshetova@intel.com>
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.
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.h | 3 ++-
ipc/util.c | 6 +++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/include/linux/ipc.h b/include/linux/ipc.h
index fadd579..ae68980 100644
--- a/include/linux/ipc.h
+++ b/include/linux/ipc.h
@@ -4,6 +4,7 @@
#include <linux/spinlock.h>
#include <linux/uidgid.h>
#include <uapi/linux/ipc.h>
+#include <linux/refcount.h>
#define IPCMNI 32768 /* <= MAX_INT limit for ipc arrays (including sysctl changes) */
@@ -22,7 +23,7 @@ struct kern_ipc_perm {
void *security;
struct rcu_head rcu;
- atomic_t refcount;
+ refcount_t refcount;
} ____cacheline_aligned_in_smp __randomize_layout;
#endif /* _LINUX_IPC_H */
diff --git a/ipc/util.c b/ipc/util.c
index 1a2cb02..069bb22 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -232,7 +232,7 @@ int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int size)
idr_preload(GFP_KERNEL);
- atomic_set(&new->refcount, 1);
+ refcount_set(&new->refcount, 1);
spin_lock_init(&new->lock);
new->deleted = false;
rcu_read_lock();
@@ -397,13 +397,13 @@ void ipc_rmid(struct ipc_ids *ids, struct kern_ipc_perm *ipcp)
int ipc_rcu_getref(struct kern_ipc_perm *ptr)
{
- return atomic_inc_not_zero(&ptr->refcount);
+ return refcount_inc_not_zero(&ptr->refcount);
}
void ipc_rcu_putref(struct kern_ipc_perm *ptr,
void (*func)(struct rcu_head *head))
{
- if (!atomic_dec_and_test(&ptr->refcount))
+ if (!refcount_dec_and_test(&ptr->refcount))
return;
call_rcu(&ptr->rcu, func);
--
2.7.4
prev parent reply other threads:[~2017-07-07 9:00 UTC|newest]
Thread overview: 23+ 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
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 ` Elena Reshetova [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=1499417992-3238-4-git-send-email-elena.reshetova@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
all inboxes | Powered by JetHome®