diff options
author | Kees Cook <keescook@chromium.org> | 2017-07-12 23:35:07 +0200 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-13 01:26:02 +0200 |
commit | 52f908904e7e05b6300162faa48152df073be645 (patch) | |
tree | f8b38e4c0c3cac282bcf71c61189b4e459f9359c /ipc | |
parent | ipc/shm: avoid ipc_rcu_alloc() (diff) | |
download | linux-52f908904e7e05b6300162faa48152df073be645.tar.xz linux-52f908904e7e05b6300162faa48152df073be645.zip |
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>
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/msg.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/ipc/msg.c b/ipc/msg.c index 25d43e27ef12..10094a731b8e 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; |