diff options
author | Elena Reshetova <elena.reshetova@intel.com> | 2017-09-08 19:17:38 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-09-08 21:26:51 -0400 |
commit | a2e0602c36ed9fe042714694dd5a889ecd8cb556 (patch) | |
tree | ce02930bac1f418d0920726c061ebeee5ca0ec53 /ipc | |
parent | 7483e5d420d9d5aa1732c5efb0da59e095a8b24e (diff) |
ipc: convert ipc_namespace.count from atomic_t to refcount_t
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.
Link: http://lkml.kernel.org/r/1499417992-3238-2-git-send-email-elena.reshetova@intel.com
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>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: <arozansk@redhat.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Manfred Spraul <manfred@colorfullife.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/msgutil.c | 2 | ||||
-rw-r--r-- | ipc/namespace.c | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/ipc/msgutil.c b/ipc/msgutil.c index bf74eaa5c39f..84598025a6ad 100644 --- a/ipc/msgutil.c +++ b/ipc/msgutil.c | |||
@@ -29,7 +29,7 @@ DEFINE_SPINLOCK(mq_lock); | |||
29 | * and not CONFIG_IPC_NS. | 29 | * and not CONFIG_IPC_NS. |
30 | */ | 30 | */ |
31 | struct ipc_namespace init_ipc_ns = { | 31 | struct ipc_namespace init_ipc_ns = { |
32 | .count = ATOMIC_INIT(1), | 32 | .count = REFCOUNT_INIT(1), |
33 | .user_ns = &init_user_ns, | 33 | .user_ns = &init_user_ns, |
34 | .ns.inum = PROC_IPC_INIT_INO, | 34 | .ns.inum = PROC_IPC_INIT_INO, |
35 | #ifdef CONFIG_IPC_NS | 35 | #ifdef CONFIG_IPC_NS |
diff --git a/ipc/namespace.c b/ipc/namespace.c index b4d80f9f7246..7af6e6b883b9 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, | |||
50 | goto fail_free; | 50 | goto fail_free; |
51 | ns->ns.ops = &ipcns_operations; | 51 | ns->ns.ops = &ipcns_operations; |
52 | 52 | ||
53 | atomic_set(&ns->count, 1); | 53 | refcount_set(&ns->count, 1); |
54 | ns->user_ns = get_user_ns(user_ns); | 54 | ns->user_ns = get_user_ns(user_ns); |
55 | ns->ucounts = ucounts; | 55 | ns->ucounts = ucounts; |
56 | 56 | ||
@@ -144,7 +144,7 @@ static void free_ipc_ns(struct ipc_namespace *ns) | |||
144 | */ | 144 | */ |
145 | void put_ipc_ns(struct ipc_namespace *ns) | 145 | void put_ipc_ns(struct ipc_namespace *ns) |
146 | { | 146 | { |
147 | if (atomic_dec_and_lock(&ns->count, &mq_lock)) { | 147 | if (refcount_dec_and_lock(&ns->count, &mq_lock)) { |
148 | mq_clear_sbinfo(ns); | 148 | mq_clear_sbinfo(ns); |
149 | spin_unlock(&mq_lock); | 149 | spin_unlock(&mq_lock); |
150 | mq_put_mnt(ns); | 150 | mq_put_mnt(ns); |