Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1650745
| Path | csiph.com!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | Manfred Spraul <manfred@colorfullife.com> |
| Newsgroups | linux.kernel |
| Subject | [PATCH 09/20] ipc/sem: Avoid ipc_rcu_alloc() |
| Date | Thu, 25 May 2017 21:00:03 +0200 |
| Message-ID | <tL69l-3pt-29@gated-at.bofh.it> (permalink) |
| References | <tEZke-1sP-3@gated-at.bofh.it> <tL69k-3pt-3@gated-at.bofh.it> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=colorfullife-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=o30pGba0vqjzqsGq4K+al/etVPpzLsrZdtbsFzkO6hs=; b=EqEZlz1krncU0QFGMiZY1FdvQ3C8TZlJcYCzBGaAqEmKpsGJQNxhPpY055T3hk2tSX 55N83YYhro7LoSN6vsOkG+PJ8GSBSYKG+x9QjFDAu+3Ly8yT/+rcau53oDdrKzuimrJh 5Uj0601EF66W7aLGYM24BtlJkVIk2q4lfmBQvl+Wmc7EJqPxqSltHvQnnZFPj1GjDgZ0 l8UMLOs9OjeooWOfJg+yUF+IO9pHmWLtRBX27IHsDicecorSeCKkhWZKLVs9wpHXcEDW CcI2Y5kpU68wUwvR59Z8ikgvvfWwEBWMFfhQmIa47GOTLily3zzpzfwABzkukZgKr0So NvxA== |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=o30pGba0vqjzqsGq4K+al/etVPpzLsrZdtbsFzkO6hs=; b=OFblYrwkXPJZ+88/KVwJ9Dd9T3iZmVfpDO59knUb5g1aa/HIsQMfxhg9Ln+GG4hUqv dUBjE778KFZYSvG1oDfa75VoFzXCn9+lmJoCTtxthwoGoAmrG7elm/WJBl12nwt7jb9Y 84DB0q8IR3bIAhxpbrZSuIHYqjjkCH+J5ygA4IkPzfkciRQRg7MxOBHFF2x46BIFLEEM wkYlA1sazXShO655J2xuftw5eU3kSTzm99Pg34rtA0TGXz1wMOFLnIIU4OqXVPCpRH/N WS9Cr5HCVliEnGdj0uAH/8m9uWWCGIAlyJO1Gwu46cEsQ+KEe3gpCA8EEhvOe9vPnGvt c6QQ== |
| X-Gm-Message-State | AODbwcB2thZ1GgBuKxjjTCErqTKANFRM7gjleS0XMai+Cp0XwOTi1wJD xoEtDIUuqVxreSAa |
| X-Received | by 10.28.94.78 with SMTP id s75mr10403364wmb.4.1495738284841; Thu, 25 May 2017 11:51:24 -0700 (PDT) |
| X-Mailer | git-send-email 2.9.3 |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 69 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | LKML <linux-kernel@vger.kernel.org>, 1vier1@web.de, Davidlohr Bueso <dave@stgolabs.net>, mingo@kernel.org, peterz@infradead.org, fabf@skynet.be, Manfred Spraul <manfred@colorfullife.com> |
| X-Original-Date | Thu, 25 May 2017 20:50:56 +0200 |
| X-Original-Message-ID | <20170525185107.12869-10-manfred@colorfullife.com> |
| X-Original-References | <20170508222345.GA52073@beast> <20170525185107.12869-1-manfred@colorfullife.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1650745 |
Show key headers only | View raw
From: Kees Cook <keescook@chromium.org>
Instead of using ipc_rcu_alloc() which only performs the refcount
bump, open code it to perform better sem-specific checks. This
also allows for sem_array structure layout to be randomized in the
future.
Signed-off-by: Kees Cook <keescook@chromium.org>
[manfred@colorfullife.com: Rediff, because the memset was
temporarily inside ipc_rcu_alloc()]
Signed-off-by: Manfred Spraul <manfred@colorfullife.com>
---
ipc/sem.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/ipc/sem.c b/ipc/sem.c
index a04c4d6..445a5b5 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -451,6 +451,25 @@ static inline void sem_rmid(struct ipc_namespace *ns, struct sem_array *s)
ipc_rmid(&sem_ids(ns), &s->sem_perm);
}
+static struct sem_array *sem_alloc(size_t nsems)
+{
+ struct sem_array *sma;
+ size_t size;
+
+ if (nsems > (INT_MAX - sizeof(*sma)) / sizeof(sma->sems[0]))
+ return NULL;
+
+ size = sizeof(*sma) + nsems * sizeof(sma->sems[0]);
+ sma = kvmalloc(size, GFP_KERNEL);
+ if (unlikely(!sma))
+ return NULL;
+
+ memset(sma, 0, size);
+ atomic_set(&sma->sem_perm.refcount, 1);
+
+ return sma;
+}
+
/**
* newary - Create a new semaphore set
* @ns: namespace
@@ -463,7 +482,6 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params)
int id;
int retval;
struct sem_array *sma;
- int size;
key_t key = params->key;
int nsems = params->u.nsems;
int semflg = params->flg;
@@ -474,10 +492,7 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params)
if (ns->used_sems + nsems > ns->sc_semmns)
return -ENOSPC;
- BUILD_BUG_ON(offsetof(struct sem_array, sem_perm) != 0);
-
- size = sizeof(*sma) + nsems * sizeof(sma->sems[0]);
- sma = container_of(ipc_rcu_alloc(size), struct sem_array, sem_perm);
+ sma = sem_alloc(nsems);
if (!sma)
return -ENOMEM;
--
2.9.3
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/20 V3] Misc cleanups for ipc Manfred Spraul <manfred@colorfullife.com> - 2017-05-25 21:00 +0200
[PATCH 05/20] ipc/sem: Do not use ipc_rcu_free() Manfred Spraul <manfred@colorfullife.com> - 2017-05-25 21:00 +0200
[PATCH 08/20] ipc/util: Drop ipc_rcu_free() Manfred Spraul <manfred@colorfullife.com> - 2017-05-25 21:00 +0200
[PATCH 15/20] ipc/msg.c: Avoid ipc_rcu_putref for failed ipc_addid() Manfred Spraul <manfred@colorfullife.com> - 2017-05-25 21:00 +0200
[PATCH 19/20] ipc/sem: Drop __sem_free() Manfred Spraul <manfred@colorfullife.com> - 2017-05-25 21:00 +0200
[PATCH 20/20] ipc/util.h: Update documentation for ipc_getref() and ipc_putref() Manfred Spraul <manfred@colorfullife.com> - 2017-05-25 21:00 +0200
[PATCH 09/20] ipc/sem: Avoid ipc_rcu_alloc() Manfred Spraul <manfred@colorfullife.com> - 2017-05-25 21:00 +0200
[PATCH 17/20] ipc/shm: Remove special shm_alloc/free Manfred Spraul <manfred@colorfullife.com> - 2017-05-25 21:00 +0200
[PATCH 11/20] ipc/msg: Avoid ipc_rcu_alloc() Manfred Spraul <manfred@colorfullife.com> - 2017-05-25 21:00 +0200
[PATCH 12/20] ipc/util: Drop ipc_rcu_alloc() Manfred Spraul <manfred@colorfullife.com> - 2017-05-25 21:00 +0200
[PATCH 16/20] ipc: Move atomic_set() to where it is needed Manfred Spraul <manfred@colorfullife.com> - 2017-05-25 21:00 +0200
[PATCH 04/20] ipc: Drop non-RCU allocation Manfred Spraul <manfred@colorfullife.com> - 2017-05-25 21:00 +0200
Re: [PATCH 04/20] ipc: Drop non-RCU allocation Kees Cook <keescook@chromium.org> - 2017-05-25 21:40 +0200
[PATCH 03/20] include/linux/sem.h: Correctly document sem_ctime Manfred Spraul <manfred@colorfullife.com> - 2017-05-25 21:00 +0200
[PATCH 07/20] ipc/msg: Do not use ipc_rcu_free() Manfred Spraul <manfred@colorfullife.com> - 2017-05-25 21:00 +0200
[PATCH 10/20] ipc/shm: Avoid ipc_rcu_alloc() Manfred Spraul <manfred@colorfullife.com> - 2017-05-25 21:00 +0200
Re: [PATCH 0/20 V3] Misc cleanups for ipc Kees Cook <keescook@chromium.org> - 2017-05-25 21:50 +0200
Re: [PATCH 0/20 V3] Misc cleanups for ipc Manfred Spraul <manfred@colorfullife.com> - 2017-05-26 04:00 +0200
csiph-web