提交 52f90890 编写于 作者: K Kees Cook 提交者: Linus Torvalds

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.comSigned-off-by: NKees Cook <keescook@chromium.org>
Signed-off-by: NManfred Spraul <manfred@colorfullife.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 3e0c2404
...@@ -109,6 +109,19 @@ static void msg_rcu_free(struct rcu_head *head) ...@@ -109,6 +109,19 @@ static void msg_rcu_free(struct rcu_head *head)
__msg_free(msq); __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 * newque - Create a new msg queue
* @ns: namespace * @ns: namespace
...@@ -123,10 +136,7 @@ static int newque(struct ipc_namespace *ns, struct ipc_params *params) ...@@ -123,10 +136,7 @@ static int newque(struct ipc_namespace *ns, struct ipc_params *params)
key_t key = params->key; key_t key = params->key;
int msgflg = params->flg; int msgflg = params->flg;
BUILD_BUG_ON(offsetof(struct msg_queue, q_perm) != 0); msq = msg_alloc();
msq = container_of(ipc_rcu_alloc(sizeof(*msq)), struct msg_queue,
q_perm);
if (!msq) if (!msq)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册