From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1425003AbdEYSv4 (ORCPT ); Thu, 25 May 2017 14:51:56 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:35028 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965324AbdEYSvw (ORCPT ); Thu, 25 May 2017 14:51:52 -0400 From: Manfred Spraul To: mtk.manpages@gmail.com, Andrew Morton , Kees Cook Cc: LKML , 1vier1@web.de, Davidlohr Bueso , mingo@kernel.org, peterz@infradead.org, fabf@skynet.be, Manfred Spraul Subject: [PATCH 11/20] ipc/msg: Avoid ipc_rcu_alloc() Date: Thu, 25 May 2017 20:50:58 +0200 Message-Id: <20170525185107.12869-12-manfred@colorfullife.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170525185107.12869-1-manfred@colorfullife.com> References: <20170508222345.GA52073@beast> <20170525185107.12869-1-manfred@colorfullife.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kees Cook 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 Signed-off-by: Manfred Spraul --- ipc/msg.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ipc/msg.c b/ipc/msg.c index 25d43e2..10094a7 100644 --- a/ipc/msg.c +++ b/ipc/msg.c @@ -109,6 +109,19 @@ static void msg_rcu_free(struct rcu_head *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 *ns, struct ipc_params *params) 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; -- 2.9.3