linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serue@us.ibm.com>
To: linux-kernel@vger.kernel.org, Kirill Korotaev <dev@sw.ru>,
	herbert@13thfloor.at, devel@openvz.org, sam@vilain.net,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	xemul@sw.ru, devel@openvz.org, James Morris <jmorris@namei.org>
Subject: [RFC][PATCH 5/5] uts namespaces: Enable UTS namespaces debugging
Date: Fri,  7 Apr 2006 13:36:00 -0500 (CDT)	[thread overview]
Message-ID: <20060407183600.EBD9219B903@sergelap.hallyn.com> (raw)
In-Reply-To: 20060407095132.455784000@sergelap

Adds a /uts directory in debugfs which exposes the current UTS
namespace. If a file in this directory is changed, it will
unshare and modify the UTS namespace of the current process.

Clearly this is purely for testing purposes.  Testing namespaces
in this fashion allows us to postpone concensus on a namespace
unsharing mechanism.

Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
---
 fs/debugfs/Makefile |    2 -
 fs/debugfs/uts.c    |  170 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/Kconfig.debug   |   11 +++
 3 files changed, 182 insertions(+), 1 deletions(-)
 create mode 100644 fs/debugfs/uts.c

67f3dc966381313f31ee3643183161a8c230199b
diff --git a/fs/debugfs/Makefile b/fs/debugfs/Makefile
index 840c456..e5df8b9 100644
--- a/fs/debugfs/Makefile
+++ b/fs/debugfs/Makefile
@@ -1,4 +1,4 @@
 debugfs-objs	:= inode.o file.o
 
 obj-$(CONFIG_DEBUG_FS)	+= debugfs.o
-
+obj-$(CONFIG_DEBUG_UTS_NS) += uts.o
diff --git a/fs/debugfs/uts.c b/fs/debugfs/uts.c
new file mode 100644
index 0000000..45b29af
--- /dev/null
+++ b/fs/debugfs/uts.c
@@ -0,0 +1,170 @@
+/*
+ *  uts.c - adds a uts/ directory to debug UTS namespaces
+ *
+ *  Copyright (C) 2006 IBM
+ *
+ *  Author: Cedric Le Goater <clg@fr.ibm.com>
+ *
+ *	This program is free software; you can redistribute it and/or
+ *	modify it under the terms of the GNU General Public License as
+ *	published by the Free Software Foundation, version 2 of the
+ *	License.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/pagemap.h>
+#include <linux/debugfs.h>
+#include <linux/utsname.h>
+
+static struct dentry *uts_dentry;
+static struct dentry *uts_dentry_sysname;
+static struct dentry *uts_dentry_nodename;
+static struct dentry *uts_dentry_release;
+static struct dentry *uts_dentry_version;
+static struct dentry *uts_dentry_machine;
+static struct dentry *uts_dentry_domainname;
+
+static inline char* uts_buffer(struct dentry *dentry)
+{
+	if (dentry == uts_dentry_sysname)
+		return utsname()->sysname;
+	else if (dentry == uts_dentry_nodename)
+		return utsname()->nodename;
+	else if (dentry == uts_dentry_release)
+		return utsname()->release;
+	else if (dentry == uts_dentry_version)
+		return utsname()->version;
+	else if (dentry == uts_dentry_machine)
+		return utsname()->machine;
+	else if (dentry == uts_dentry_domainname)
+		return utsname()->domainname;
+	else
+		return NULL;
+}
+
+static ssize_t uts_read_file(struct file *file, char __user *user_buf,
+			     size_t count, loff_t *ppos)
+{
+	size_t len;
+	char* buf;
+
+	if (*ppos < 0)
+		return -EINVAL;
+	if (*ppos >= count)
+		return 0;
+
+	buf = uts_buffer(file->f_dentry);
+	if (!buf)
+		return -ENOENT;
+
+	len = strlen(buf);
+	if (len > count)
+		len = count;
+	if (len)
+		if (copy_to_user(user_buf, buf, len))
+			return -EFAULT;
+	if (len < count) {
+		if (put_user('\n', ((char __user *) user_buf) + len))
+			return -EFAULT;
+		len++;
+	}
+
+	*ppos += count;
+	return count;
+}
+
+
+static ssize_t uts_write_file(struct file * file, const char __user * user_buf,
+			      size_t count, loff_t *ppos)
+
+{
+	size_t len;
+	const char __user *p;
+	char c;
+	char* buf;
+
+	if (!unshare_uts_ns())
+		return -ENOMEM;
+
+	buf = uts_buffer(file->f_dentry);
+	if (!buf)
+		return -ENOENT;
+
+	len = 0;
+	p = user_buf;
+	while (len < count) {
+		if (get_user(c, p++))
+			return -EFAULT;
+		if (c == 0 || c == '\n')
+			break;
+		len++;
+	}
+
+	if (len >= __NEW_UTS_LEN)
+		len = __NEW_UTS_LEN - 1;
+
+	if (copy_from_user(buf, user_buf, len))
+		return -EFAULT;
+
+	buf[len] = 0;
+
+	*ppos += count;
+	return count;
+}
+
+static int uts_open(struct inode *inode, struct file *file)
+{
+	return 0;
+}
+
+static struct file_operations uts_file_operations = {
+	.read =		uts_read_file,
+	.write =	uts_write_file,
+	.open =		uts_open,
+};
+
+static int __init uts_init(void)
+{
+	uts_dentry = debugfs_create_dir("uts", NULL);
+
+	uts_dentry_sysname = debugfs_create_file("sysname", 0666,
+						 uts_dentry, NULL,
+						 &uts_file_operations);
+	uts_dentry_nodename = debugfs_create_file("nodename", 0666,
+						  uts_dentry, NULL,
+						  &uts_file_operations);
+	uts_dentry_release = debugfs_create_file("release", 0666,
+						 uts_dentry, NULL,
+						 &uts_file_operations);
+	uts_dentry_version = debugfs_create_file("version", 0666,
+						 uts_dentry, NULL,
+						 &uts_file_operations);
+	uts_dentry_machine = debugfs_create_file("machine", 0666,
+						 uts_dentry, NULL,
+						 &uts_file_operations);
+	uts_dentry_domainname = debugfs_create_file("domainname", 0666,
+						    uts_dentry, NULL,
+						    &uts_file_operations);
+	return 0;
+}
+
+static void __exit uts_exit(void)
+{
+	debugfs_remove(uts_dentry_sysname);
+	debugfs_remove(uts_dentry_nodename);
+	debugfs_remove(uts_dentry_release);
+	debugfs_remove(uts_dentry_version);
+	debugfs_remove(uts_dentry_machine);
+	debugfs_remove(uts_dentry_domainname);
+	debugfs_remove(uts_dentry);
+}
+
+module_init(uts_init);
+module_exit(uts_exit);
+
+
+MODULE_DESCRIPTION("UTS namespace debugfs");
+MODULE_AUTHOR("Cedric Le Goater <clg@fr.ibm.com>");
+MODULE_LICENSE("GPL");
+
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index d57fd91..5ed09b8 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -223,3 +223,14 @@ config RCU_TORTURE_TEST
 	  at boot time (you probably don't).
 	  Say M if you want the RCU torture tests to build as a module.
 	  Say N if you are unsure.
+
+config DEBUG_UTS_NS
+	tristate "UTS Namespaces debugging"
+	depends on UTS_NS
+	select DEBUG_FS
+	default n
+	help
+	  This option provides a kernel module that adds a uts/ directory
+	  in debugfs which can be used to unshare and modify the uts namespace
+	  of the current process and children. If unsure, say N.
+
-- 
1.2.4



  reply	other threads:[~2006-04-07 18:37 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-07 18:36 [RFC][PATCH 0/5] uts namespaces: Introduction Serge E. Hallyn
2006-04-07 18:36 ` Serge E. Hallyn [this message]
2006-04-07 18:36 ` [RFC][PATCH 2/5] uts namespaces: Switch to using uts namespaces Serge E. Hallyn
2006-04-07 19:17   ` Sam Ravnborg
2006-04-07 19:25     ` Serge E. Hallyn
2006-04-11 12:26   ` Kirill Korotaev
2006-04-11 21:04     ` Sam Vilain
2006-04-12  5:01       ` Serge E. Hallyn
2006-04-12  6:00         ` Eric W. Biederman
2006-04-19 15:00           ` Serge E. Hallyn
2006-04-07 18:36 ` [RFC][PATCH 3/5] uts namespaces: Use init uts_namespace when appropriate Serge E. Hallyn
2006-04-07 18:36 ` [RFC][PATCH 4/5] utsname namespaces: sysctl hack Serge E. Hallyn
2006-04-19 15:17   ` Kirill Korotaev
2006-04-19 15:21     ` Serge E. Hallyn
2006-04-19 15:50       ` Kirill Korotaev
2006-04-19 16:54         ` Cedric Le Goater
2006-04-19 17:10           ` Eric W. Biederman
2006-04-19 17:10         ` Serge E. Hallyn
2006-04-19 15:52       ` Eric W. Biederman
2006-04-19 16:23         ` Dave Hansen
2006-04-19 16:52           ` Eric W. Biederman
2006-04-19 17:19             ` Dave Hansen
2006-04-19 17:37               ` Eric W. Biederman
2006-04-19 17:48               ` Eric W. Biederman
2006-04-19 15:29     ` Eric W. Biederman
2006-04-19 17:51       ` Serge E. Hallyn
2006-04-19 18:27         ` Eric W. Biederman
2006-04-19 20:24           ` Serge E. Hallyn
2006-04-19 21:44           ` Sam Vilain
2006-04-20 17:05             ` Serge E. Hallyn
2006-04-25 22:00             ` Serge E. Hallyn
2006-04-26  4:09               ` Sam Vilain
2006-04-26 10:28                 ` Christoph Hellwig
2006-04-27 12:32                 ` Eric W. Biederman
2006-04-07 18:36 ` [RFC][PATCH 1/5] uts namespaces: Implement utsname namespaces Serge E. Hallyn
2006-04-07 19:13   ` Sam Ravnborg
2006-04-07 19:20     ` Serge E. Hallyn
2006-04-07 19:39     ` Serge E. Hallyn
2006-04-07 20:47   ` James Morris
2006-04-07 22:13     ` Serge E. Hallyn
2006-04-08 13:44   ` Andi Kleen
2006-04-08 13:45   ` Andi Kleen
2006-04-08 20:28     ` Serge E. Hallyn
2006-04-09  6:00       ` Andi Kleen
2006-04-09 19:08         ` Eric W. Biederman
2006-04-07 19:06 ` [RFC][PATCH 0/5] uts namespaces: Introduction Eric W. Biederman
2006-04-07 19:28   ` Serge E. Hallyn
2006-04-07 19:39     ` Eric W. Biederman
2006-04-11 12:32 ` Kirill Korotaev
2006-04-11 14:01   ` Serge E. Hallyn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060407183600.EBD9219B903@sergelap.hallyn.com \
    --to=serue@us.ibm.com \
    --cc=dev@sw.ru \
    --cc=devel@openvz.org \
    --cc=ebiederm@xmission.com \
    --cc=herbert@13thfloor.at \
    --cc=jmorris@namei.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sam@vilain.net \
    --cc=xemul@sw.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).