ipc/msg: avoid ipc_rcu_alloc()
PATCH 42/96 ipc/msg: avoid ipc_rcu_alloc()
From: Kees Cook <[email protected]>
Subject: 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.
Signed-off-by Kees Cook <[email protected]>
Signed-off-by Manfred Spraul <[email protected]>
Cc Davidlohr Bueso <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
ipc/msg.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
ipc/msg.c renamed from ipc/msg.c~ipc-msg-avoid-ipc_rcu_alloc +13 -1
@@ -109,6 +109,19 @@ static void msg_rcu_free(struct rcu_head__msg_free (msq); } +static struct msg_queue *msg_alloc (void ) +{ +struct msg_queue *msq; + + msq =kvmalloc (sizeof (*msq),GFP_KERNEL ); +if (unlikely (!msq)) +return NULL ; + +atomic_set (&msq->q_perm.refcount,1 ); + +return msq; +} +/** * newque - Create a new msg queue * @ns: namespace
@@ -123,10 +136,7 @@ static int newque(struct ipc_namespace *key_t key = params->key;int msgflg = params->flg; -BUILD_BUG_ON (offsetof(struct msg_queue , q_perm) !=0 );