Commit 9405c03e authored by Elena Reshetova's avatar Elena Reshetova Committed by Linus Torvalds

ipc: convert kern_ipc_perm.refcount 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

Link: default avatarElena Reshetova <>
Signed-off-by: default avatarHans Liljestrand <>
Signed-off-by: Kees Cook's avatarKees Cook <>
Signed-off-by: default avatarDavid Windsor <>
Cc: Peter Zijlstra <>
Cc: Greg Kroah-Hartman <>
Cc: "Eric W. Biederman" <>
Cc: Ingo Molnar <>
Cc: Alexey Dobriyan <>
Cc: Serge Hallyn <>
Cc: <>
Cc: Davidlohr Bueso <>
Cc: Manfred Spraul <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent f74370b8
......@@ -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 */
......@@ -232,7 +232,7 @@ int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int size)
atomic_set(&new->refcount, 1);
refcount_set(&new->refcount, 1);
new->deleted = false;
......@@ -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))
call_rcu(&ptr->rcu, func);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment