[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1401110850-3552-3-git-send-email-tixxdz@opendz.org>
Date: Mon, 26 May 2014 14:27:23 +0100
From: Djalal Harouni <tixxdz@...ndz.org>
To: Kees Cook <keescook@...omium.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Alexey Dobriyan <adobriyan@...il.com>,
"Eric W. Biederman" <ebiederm@...ssion.com>,
Al Viro <viro@...iv.linux.org.uk>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Ingo Molnar <mingo@...nel.org>,
Oleg Nesterov <oleg@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Andy Lutomirski <luto@...capital.net>
Cc: LKML <linux-kernel@...r.kernel.org>, linux-fsdevel@...r.kernel.org,
Djalal Harouni <tixxdz@...ndz.org>
Subject: [PATCH 2/9] procfs: add pid_entry_access() for proper checks on /proc/<pid>/*
Add the helper pid_entry_access() to unify the permission checks during
->open()
This is a preparation patch.
Signed-off-by: Djalal Harouni <tixxdz@...ndz.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 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