From 4d3f0f3aeb8daeda58b7315824842c65e31eb538 Mon Sep 17 00:00:00 2001 From: Guilherme Sperb Machado Date: Wed, 25 Mar 2015 16:48:55 +0100 Subject: [PATCH] Since the struct nameidata became opaque in recent changes of the kernel, I included the declaration here. This is an attempt to correct compilation errors in kernel 3.19+ --- procprotect.c | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/procprotect.c b/procprotect.c index 6b8abe0..556f054 100644 --- a/procprotect.c +++ b/procprotect.c @@ -64,6 +64,24 @@ struct acl_entry { struct hlist_node hlist; }; +/* + Added by Guilherme Sperb Machado + According to recent changes in the kernel, the nameidata struct + became opaque. So, let's declare it in our implementation. + Source: https://github.com/torvalds/linux/commit/1f55a6ec940fb45e3edaa52b6e9fc40cf8e18dcb + */ +struct nameidata { + struct path path; + struct qstr last; + struct path root; + struct inode *inode; /* path.dentry.d_inode */ + unsigned int flags; + unsigned seq; + int last_type; + unsigned depth; + char *saved_names[MAX_NESTED_LINKS + 1]; +}; + #define HASH_SIZE (1<<10) struct hlist_head procprotect_hash[HASH_SIZE]; @@ -72,7 +90,7 @@ struct proc_dir_entry *proc_entry; static int run_acl(unsigned long ino) { struct acl_entry *entry; - hlist_for_each_entry_rcu_notrace(entry, + hlist_for_each_entry_rcu_notrace(entry, &procprotect_hash[ino & (HASH_SIZE-1)], hlist) { if (entry->ino==ino) { @@ -93,7 +111,7 @@ static int lookup_fast_entry(struct kretprobe_instance *ri, struct pt_regs *regs struct nameidata *nd = (struct nameidata *) regs->di; struct dentry *parent; struct inode *pinode; - + if (!nd) return ret; parent = nd->path.dentry; @@ -103,7 +121,7 @@ static int lookup_fast_entry(struct kretprobe_instance *ri, struct pt_regs *regs if (!pinode || !pinode->i_sb || !current || !current->nsproxy) return ret; if (pinode->i_sb->s_magic == PROC_SUPER_MAGIC - && current->nsproxy->mnt_ns!=init_task.nsproxy->mnt_ns) { + && current->nsproxy->mnt_ns!=init_task.nsproxy->mnt_ns) { ctx = (struct procprotect_ctx *) ri->data; ctx->inode = (struct inode **)regs->dx; ctx->flags = nd->flags; @@ -149,8 +167,8 @@ static int lookup_slow_entry(struct kretprobe_instance *ri, struct pt_regs *regs pinode= parent->d_inode; if (pinode->i_sb->s_magic == PROC_SUPER_MAGIC - && current->nsproxy->mnt_ns!=init_task.nsproxy->mnt_ns) { - + && current->nsproxy->mnt_ns!=init_task.nsproxy->mnt_ns) { + ctx = (struct procprotect_ctx *) ri->data; ctx->q = &nd->last; ctx->flags = nd->flags; @@ -204,7 +222,7 @@ static struct file *do_last_probe(struct nameidata *nd, struct path *path, struc struct inode *pinode = parent->d_inode; /*struct qstr *q = &nd->last;*/ - + if (pinode->i_sb->s_magic == PROC_SUPER_MAGIC && current->nsproxy->mnt_ns!=init_task.nsproxy->mnt_ns) { /*if (!strncmp(q->name,"sysrq-trigger",13)) { printk(KERN_CRIT "do_last sysrqtrigger: %d",op->open_flag); @@ -237,7 +255,7 @@ int once_only = 0; static int init_probes(void) { int ret; - dolast_probe.kp.addr = + dolast_probe.kp.addr = (kprobe_opcode_t *) kallsyms_lookup_name("do_last"); if (!dolast_probe.kp.addr) { @@ -249,7 +267,7 @@ static int init_probes(void) { printk("register_jprobe failed, returned %u\n", ret); return -1; } - fast_probe.kp.addr = + fast_probe.kp.addr = (kprobe_opcode_t *) kallsyms_lookup_name("lookup_fast"); if (!fast_probe.kp.addr) { @@ -257,7 +275,7 @@ static int init_probes(void) { return -1; } - slow_probe.kp.addr = + slow_probe.kp.addr = (kprobe_opcode_t *) kallsyms_lookup_name("lookup_slow"); if (!slow_probe.kp.addr) { @@ -286,7 +304,7 @@ static void add_entry(char *pathname) { struct path path; if (kern_path(pathname, 0, &path)) { printk(KERN_CRIT "Path lookup failed for %s",pathname); - } + } else { unsigned int ino = path.dentry->d_inode->i_ino; struct acl_entry *entry; @@ -317,10 +335,10 @@ static void __exit procprotect_exit(void) unregister_kretprobe(&fast_probe); unregister_kretprobe(&slow_probe); - unregister_jprobe(&dolast_probe); + unregister_jprobe(&dolast_probe); for (i=0;i