1 #include <linux/module.h>
2 #include <linux/moduleparam.h>
3 #include <linux/types.h>
4 #include <linux/kernel.h>
5 #include <linux/fs_struct.h>
8 #include <linux/reboot.h>
9 #include <linux/delay.h>
10 #include <linux/proc_fs.h>
11 #include <asm/uaccess.h>
12 #include <linux/sysrq.h>
13 #include <linux/timer.h>
14 #include <linux/time.h>
15 #include <linux/lglock.h>
16 #include <linux/init.h>
17 #include <linux/idr.h>
18 #include <linux/namei.h>
19 #include <linux/bitops.h>
20 #include <linux/mnt_namespace.h>
21 #include <linux/path.h>
22 #include <linux/dcache.h>
23 #include <linux/spinlock.h>
24 #include <linux/completion.h>
25 #include <linux/sched.h>
26 #include <linux/seq_file.h>
27 #include <linux/kprobes.h>
28 #include <linux/kallsyms.h>
29 #include <linux/nsproxy.h>
32 #define VERSION_STR "0.0.1"
35 #error "This code does not support your architecture"
38 MODULE_AUTHOR("Sapan Bhatia <sapanb@cs.princeton.edu>");
39 MODULE_DESCRIPTION("Hack to enable mount namespace switching via setns. Based on a patch by Eric Biederman.");
40 MODULE_LICENSE("GPL");
41 MODULE_VERSION(VERSION_STR);
43 static int setns_entry(struct kretprobe_instance *ri, struct pt_regs *regs) {
44 int nstype = regs->si;
45 printk(KERN_CRIT "nstype: %d",nstype);
47 if (nstype==666) regs->si = 0;
51 static int setns_ret(struct kretprobe_instance *ri, struct pt_regs *regs)
53 int nstype = regs->si;
54 printk(KERN_CRIT "nstype 2: %d",nstype);
59 static struct kretprobe setns_probe = {
60 .entry_handler = (kprobe_opcode_t *) setns_entry,
61 .handler = (kprobe_opcode_t *) setns_ret,
66 static void __exit mntsu_exit(void)
68 unregister_kretprobe(&setns_probe);
69 printk("Procprotect: Stopped mntsu.\n");
72 static int __init mntsu_init(void)
75 printk("Mntsu: starting mntsu version %s.\n",
79 (kprobe_opcode_t *) kallsyms_lookup_name("sys_setns");
80 if (!setns_probe.kp.addr) {
81 printk("Couldn't find %s to plant kretprobe\n", "do_execve");
85 if ((ret = register_kretprobe(&setns_probe)) <0) {
86 printk("register_kretprobe failed, returned %d\n", ret);
89 printk("Planted kretprobe at %p, handler addr %p\n",
90 setns_probe.kp.addr, setns_probe.handler);
95 static void *mntns_get(struct task_struct *task)
97 struct mnt_namespace *ns;
99 ns = task->nsproxy->mnt_ns;
100 atomic_inc(&ns->count);
105 static void mntns_put(void *ns)
110 static int mntns_install(struct nsproxy *nsproxy, void *ns)
112 struct fs_struct *fs = current->fs;
113 struct mnt_namespace *mnt_ns = ns;
119 atomic_inc(&mnt_ns->count);
120 put_mnt_ns(nsproxy->mnt_ns);
121 nsproxy->mnt_ns = mnt_ns;
124 root.mnt = mnt_ns->root;
125 root.dentry = mnt_ns->root->mnt.mnt_root;
127 while(d_mountpoint(root.dentry) && follow_down(&root))
130 /* Update the pwd and root */
142 const struct proc_ns_operations mntns_operations = {
146 .install = mntns_install,
149 module_init(mntsu_init);
150 module_exit(mntsu_exit);