Add the helper pid_entry_access() to unify the permission checks during
->open()

This is a preparation patch.

Signed-off-by: Djalal Harouni <tix...@opendz.org>
---
 fs/proc/generic.c  | 22 ++++++++++++++++++++++
 fs/proc/internal.h |  2 ++
 2 files changed, 24 insertions(+)

diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index b7f268e..98ed927 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -23,6 +23,7 @@
 #include <linux/bitops.h>
 #include <linux/spinlock.h>
 #include <linux/completion.h>
+#include <linux/ptrace.h>
 #include <asm/uaccess.h>
 
 #include "internal.h"
@@ -596,3 +597,24 @@ void *PDE_DATA(const struct inode *inode)
        return __PDE_DATA(inode);
 }
 EXPORT_SYMBOL(PDE_DATA);
+
+int pid_entry_access(struct file *filp, unsigned int mode)
+{
+       int err = -ESRCH;
+       struct task_struct *task = get_proc_task(file_inode(filp));
+
+       if (!task)
+               return err;
+
+       err = mutex_lock_killable(&task->signal->cred_guard_mutex);
+       if (err)
+               goto out;
+
+       if (!ptrace_may_access(task, mode))
+               err = -EACCES;
+
+       mutex_unlock(&task->signal->cred_guard_mutex);
+out:
+       put_task_struct(task);
+       return err;
+}
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index e696284..4f828fa 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -202,6 +202,8 @@ static inline struct proc_dir_entry *pde_get(struct 
proc_dir_entry *pde)
 }
 extern void pde_put(struct proc_dir_entry *);
 
+extern int pid_entry_access(struct file *filp, unsigned int mode);
+
 /*
  * inode.c
  */
-- 
1.7.11.7

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

Reply via email to