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]
Date:	Wed, 30 Sep 2015 22:49:20 +0200
From:	Rasmus Villemoes <linux@...musvillemoes.dk>
To:	"Eric W. Biederman" <ebiederm@...ssion.com>,
	Oleg Nesterov <oleg@...hat.com>
Cc:	Rasmus Villemoes <linux@...musvillemoes.dk>,
	linux-kernel@...r.kernel.org
Subject: [RFC 1/4] pid_namespace: remove ->level and ->parent for !CONFIG_PID_NS

When !CONFIG_PID_NS, there is only ever one struct pid_namespace, and
for that we know that ->parent is NULL and ->level is 0. Telling the
compiler that allows it to generate slightly smaller code.

Removing the members from struct pid_namespace only saves a few bytes,
but it also helps ensure that everyone outside kernel/pid_namespace.c
use the new accessors pid_ns_{parent,level}.

Signed-off-by: Rasmus Villemoes <linux@...musvillemoes.dk>
---
 include/linux/pid_namespace.h | 18 ++++++++++++++++++
 kernel/acct.c                 |  4 ++--
 kernel/pid.c                  | 18 +++++++++---------
 3 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
index 918b117a7cd3..03a84a0cdc75 100644
--- a/include/linux/pid_namespace.h
+++ b/include/linux/pid_namespace.h
@@ -29,8 +29,10 @@ struct pid_namespace {
 	unsigned int nr_hashed;
 	struct task_struct *child_reaper;
 	struct kmem_cache *pid_cachep;
+#ifdef CONFIG_PID_NS
 	unsigned int level;
 	struct pid_namespace *parent;
+#endif
 #ifdef CONFIG_PROC_FS
 	struct vfsmount *proc_mnt;
 	struct dentry *proc_self;
@@ -58,6 +60,14 @@ static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
 		kref_get(&ns->kref);
 	return ns;
 }
+static inline struct pid_namespace *pid_ns_parent(struct pid_namespace *ns)
+{
+	return ns->parent;
+}
+static inline int pid_ns_level(struct pid_namespace *ns)
+{
+	return ns->level;
+}
 
 extern struct pid_namespace *copy_pid_ns(unsigned long flags,
 	struct user_namespace *user_ns, struct pid_namespace *ns);
@@ -72,6 +82,14 @@ static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
 {
 	return ns;
 }
+static inline struct pid_namespace *pid_ns_parent(struct pid_namespace *ns)
+{
+	return NULL;
+}
+static inline int pid_ns_level(struct pid_namespace *ns)
+{
+	return 0;
+}
 
 static inline struct pid_namespace *copy_pid_ns(unsigned long flags,
 	struct user_namespace *user_ns, struct pid_namespace *ns)
diff --git a/kernel/acct.c b/kernel/acct.c
index 74963d192c5d..43e570feea45 100644
--- a/kernel/acct.c
+++ b/kernel/acct.c
@@ -569,7 +569,7 @@ void acct_collect(long exitcode, int group_dead)
 
 static void slow_acct_process(struct pid_namespace *ns)
 {
-	for ( ; ns; ns = ns->parent) {
+	for ( ; ns; ns = pid_ns_parent(ns)) {
 		struct bsd_acct_struct *acct = acct_get(ns);
 		if (acct) {
 			do_acct_process(acct);
@@ -593,7 +593,7 @@ void acct_process(void)
 	 * alive and holds its namespace, which in turn holds
 	 * its parent.
 	 */
-	for (ns = task_active_pid_ns(current); ns != NULL; ns = ns->parent) {
+	for (ns = task_active_pid_ns(current); ns != NULL; ns = pid_ns_parent(ns)) {
 		if (ns->bacct)
 			break;
 	}
diff --git a/kernel/pid.c b/kernel/pid.c
index ca368793808e..909d3dcd8085 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -76,12 +76,12 @@ struct pid_namespace init_pid_ns = {
 	},
 	.last_pid = 0,
 	.nr_hashed = PIDNS_HASH_ADDING,
-	.level = 0,
 	.child_reaper = &init_task,
 	.user_ns = &init_user_ns,
 	.ns.inum = PROC_PID_INIT_INO,
 #ifdef CONFIG_PID_NS
 	.ns.ops = &pidns_operations,
+	.level = 0,
 #endif
 };
 EXPORT_SYMBOL_GPL(init_pid_ns);
@@ -308,8 +308,8 @@ struct pid *alloc_pid(struct pid_namespace *ns)
 		return ERR_PTR(retval);
 
 	tmp = ns;
-	pid->level = ns->level;
-	for (i = ns->level; i >= 0; i--) {
+	pid->level = pid_ns_level(ns);
+	for (i = pid_ns_level(ns); i >= 0; i--) {
 		nr = alloc_pidmap(tmp);
 		if (IS_ERR_VALUE(nr)) {
 			retval = nr;
@@ -318,7 +318,7 @@ struct pid *alloc_pid(struct pid_namespace *ns)
 
 		pid->numbers[i].nr = nr;
 		pid->numbers[i].ns = tmp;
-		tmp = tmp->parent;
+		tmp = pid_ns_parent(tmp);
 	}
 
 	if (unlikely(is_child_reaper(pid))) {
@@ -331,7 +331,7 @@ struct pid *alloc_pid(struct pid_namespace *ns)
 	for (type = 0; type < PIDTYPE_MAX; ++type)
 		INIT_HLIST_HEAD(&pid->tasks[type]);
 
-	upid = pid->numbers + ns->level;
+	upid = pid->numbers + pid_ns_level(ns);
 	spin_lock_irq(&pidmap_lock);
 	if (!(ns->nr_hashed & PIDNS_HASH_ADDING))
 		goto out_unlock;
@@ -349,7 +349,7 @@ out_unlock:
 	put_pid_ns(ns);
 
 out_free:
-	while (++i <= ns->level)
+	while (++i <= pid_ns_level(ns))
 		free_pidmap(pid->numbers + i);
 
 	kmem_cache_free(ns->pid_cachep, pid);
@@ -371,7 +371,7 @@ struct pid *find_pid_ns(int nr, struct pid_namespace *ns)
 			&pid_hash[pid_hashfn(nr, ns)], pid_chain)
 		if (pnr->nr == nr && pnr->ns == ns)
 			return container_of(pnr, struct pid,
-					numbers[ns->level]);
+					numbers[pid_ns_level(ns)]);
 
 	return NULL;
 }
@@ -502,8 +502,8 @@ pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
 	struct upid *upid;
 	pid_t nr = 0;
 
-	if (pid && ns->level <= pid->level) {
-		upid = &pid->numbers[ns->level];
+	if (pid && pid_ns_level(ns) <= pid->level) {
+		upid = &pid->numbers[pid_ns_level(ns)];
 		if (upid->ns == ns)
 			nr = upid->nr;
 	}
-- 
2.1.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ