Skip to content

Commit 52f9089

Browse files
keestorvalds
authored andcommitted
ipc/msg: avoid ipc_rcu_alloc()
Instead of using ipc_rcu_alloc() which only performs the refcount bump, open code it. This also allows for msg_queue structure layout to be randomized in the future. Link: http://lkml.kernel.org/r/20170525185107.12869-12-manfred@colorfullife.com Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Manfred Spraul <manfred@colorfullife.com> Cc: Davidlohr Bueso <dave@stgolabs.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 3e0c240 commit 52f9089

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

‎ipc/msg.c‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ static void msg_rcu_free(struct rcu_head *head)
109109
__msg_free(msq);
110110
}
111111

112+
static struct msg_queue *msg_alloc(void)
113+
{
114+
struct msg_queue *msq;
115+
116+
msq = kvmalloc(sizeof(*msq), GFP_KERNEL);
117+
if (unlikely(!msq))
118+
return NULL;
119+
120+
atomic_set(&msq->q_perm.refcount, 1);
121+
122+
return msq;
123+
}
124+
112125
/**
113126
* newque - Create a new msg queue
114127
* @ns: namespace
@@ -123,10 +136,7 @@ static int newque(struct ipc_namespace *ns, struct ipc_params *params)
123136
key_t key = params->key;
124137
int msgflg = params->flg;
125138

126-
BUILD_BUG_ON(offsetof(struct msg_queue, q_perm) != 0);
127-
128-
msq = container_of(ipc_rcu_alloc(sizeof(*msq)), struct msg_queue,
129-
q_perm);
139+
msq = msg_alloc();
130140
if (!msq)
131141
return -ENOMEM;
132142

0 commit comments

Comments
 (0)