lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20171122210739.29916-53-willy@infradead.org>
Date:   Wed, 22 Nov 2017 13:07:29 -0800
From:   Matthew Wilcox <willy@...radead.org>
To:     linux-fsdevel@...r.kernel.org, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org
Cc:     Matthew Wilcox <mawilcox@...rosoft.com>
Subject: [PATCH 52/62] ipc: Remove call to idr_preload

From: Matthew Wilcox <mawilcox@...rosoft.com>

The ipc code follows a different pattern to most IDR preload users;
the lock that it is holding is embedded in the object, not protecting
the IDR (the IDR is protected by an rwsem).  Instead of dropping the
lock, allocating memory and retrying, we reserve a slot in the tree
before grabbing the lock, then merely replace the NULL entry with the
initialised object.

Signed-off-by: Matthew Wilcox <mawilcox@...rosoft.com>
---
 ipc/util.c | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/ipc/util.c b/ipc/util.c
index ff045fec8d83..9a20354ce4fb 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -193,10 +193,10 @@ static struct kern_ipc_perm *ipc_findkey(struct ipc_ids *ids, key_t key)
 /*
  * Specify desired id for next allocated IPC object.
  */
-#define ipc_idr_alloc(ids, new)						\
-	idr_alloc(&(ids)->ipcs_idr, (new),				\
+#define ipc_idr_alloc(ids)						\
+	idr_alloc(&(ids)->ipcs_idr, NULL,				\
 		  (ids)->next_id < 0 ? 0 : ipcid_to_idx((ids)->next_id),\
-		  0, GFP_NOWAIT)
+		  0, GFP_KERNEL)
 
 static inline int ipc_buildid(int id, struct ipc_ids *ids,
 			      struct kern_ipc_perm *new)
@@ -214,8 +214,8 @@ static inline int ipc_buildid(int id, struct ipc_ids *ids,
 }
 
 #else
-#define ipc_idr_alloc(ids, new)					\
-	idr_alloc(&(ids)->ipcs_idr, (new), 0, 0, GFP_NOWAIT)
+#define ipc_idr_alloc(ids)					\
+	idr_alloc(&(ids)->ipcs_idr, NULL, 0, 0, GFP_KERNEL)
 
 static inline int ipc_buildid(int id, struct ipc_ids *ids,
 			      struct kern_ipc_perm *new)
@@ -254,34 +254,30 @@ int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int limit)
 	if (!ids->tables_initialized || ids->in_use >= limit)
 		return -ENOSPC;
 
-	idr_preload(GFP_KERNEL);
+	id = ipc_idr_alloc(ids);
+	if (id < 0)
+		return id;
 
 	refcount_set(&new->refcount, 1);
 	spin_lock_init(&new->lock);
 	new->deleted = false;
-	rcu_read_lock();
 	spin_lock(&new->lock);
 
 	current_euid_egid(&euid, &egid);
 	new->cuid = new->uid = euid;
 	new->gid = new->cgid = egid;
 
-	id = ipc_idr_alloc(ids, new);
-	idr_preload_end();
+	idr_replace(&ids->ipcs_idr, new, id);
 
-	if (id >= 0 && new->key != IPC_PRIVATE) {
+	if (new->key != IPC_PRIVATE) {
 		err = rhashtable_insert_fast(&ids->key_ht, &new->khtnode,
 					     ipc_kht_params);
 		if (err < 0) {
 			idr_remove(&ids->ipcs_idr, id);
-			id = err;
+			spin_unlock(&new->lock);
+			return err;
 		}
 	}
-	if (id < 0) {
-		spin_unlock(&new->lock);
-		rcu_read_unlock();
-		return id;
-	}
 
 	ids->in_use++;
 	if (id > ids->max_id)
-- 
2.15.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ