lkml.org 
[lkml]   [2009]   [May]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[RFC PATCH 3/3a] ptrace: add _ptrace_may_access()

* Oleg Nesterov <oleg@redhat.com> wrote:

> + task_lock(task);
> retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
> + task_unlock(task);
> if (retval)
> - goto bad;
> + goto unlock_creds;

Hm, that's a bit ugly - why dont you reuse ptrace_may_access(),
which does much of this already?

That way we could save a little bit of code size.

Something like the patch below allows the reuse of the locked
version of __ptrace_may_access and pushes the int->bool conversion
into an inline.

Note that this will also be a micro-optimization: the compiler will
be able to eliminate the inlined negation in the call sites (most of
which use the value directly) - and thus we save the negation.

( Untested - if you test it then it has my signoff. Patch also does
a small cleanup in _ptrace_may_access() )

Hm?

Ingo

diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
index 59e133d..2cc01ec 100644
--- a/include/linux/ptrace.h
+++ b/include/linux/ptrace.h
@@ -99,8 +99,13 @@ extern void exit_ptrace(struct task_struct *tracer);
#define PTRACE_MODE_ATTACH 2
/* Returns 0 on success, -errno on denial. */
extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
-/* Returns true on success, false on denial. */
-extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
+/* Also takes the task lock: */
+extern int _ptrace_may_access(struct task_struct *task, unsigned int mode);
+/* True on success, false on denial: */
+static inline bool ptrace_may_access(struct task_struct *task, unsigned int mode)
+{
+ return !_ptrace_may_access(task, mode);
+}

static inline int ptrace_reparented(struct task_struct *child)
{
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index e950805..f7efcc9 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -155,13 +155,15 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
return security_ptrace_may_access(task, mode);
}

-bool ptrace_may_access(struct task_struct *task, unsigned int mode)
+int _ptrace_may_access(struct task_struct *task, unsigned int mode)
{
int err;
+
task_lock(task);
err = __ptrace_may_access(task, mode);
task_unlock(task);
- return !err;
+
+ return err;
}

int ptrace_attach(struct task_struct *task)

\
 
 \ /
  Last update: 2009-05-06 10:05    [W:0.097 / U:22.916 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site