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>
__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
key_t key = params->key;
int msgflg = params->flg;
- BUILD_BUG_ON(offsetof(struct msg_queue, q_perm) != 0);
-
- msq = container_of(ipc_rcu_alloc(sizeof(*msq)), struct msg_queue,
- q_perm);
+ msq = msg_alloc();
if (!msq)
return -ENOMEM;