Commit d21142ec authored by Tejun Heo's avatar Tejun Heo Committed by Oleg Nesterov

ptrace: kill task_ptrace()

task_ptrace(task) simply dereferences task->ptrace and isn't even used
consistently only adding confusion.  Kill it and directly access
->ptrace instead.

This doesn't introduce any behavior change.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
parent 544b2c91
...@@ -145,17 +145,6 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr, ...@@ -145,17 +145,6 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr, int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
unsigned long data); unsigned long data);
/**
* task_ptrace - return %PT_* flags that apply to a task
* @task: pointer to &task_struct in question
*
* Returns the %PT_* flags that apply to @task.
*/
static inline int task_ptrace(struct task_struct *task)
{
return task->ptrace;
}
/** /**
* ptrace_event - possibly stop for a ptrace event notification * ptrace_event - possibly stop for a ptrace event notification
* @mask: %PT_* bit to check in @current->ptrace * @mask: %PT_* bit to check in @current->ptrace
......
...@@ -63,7 +63,7 @@ struct linux_binprm; ...@@ -63,7 +63,7 @@ struct linux_binprm;
*/ */
static inline int tracehook_expect_breakpoints(struct task_struct *task) static inline int tracehook_expect_breakpoints(struct task_struct *task)
{ {
return (task_ptrace(task) & PT_PTRACED) != 0; return (task->ptrace & PT_PTRACED) != 0;
} }
/* /*
...@@ -71,7 +71,7 @@ static inline int tracehook_expect_breakpoints(struct task_struct *task) ...@@ -71,7 +71,7 @@ static inline int tracehook_expect_breakpoints(struct task_struct *task)
*/ */
static inline void ptrace_report_syscall(struct pt_regs *regs) static inline void ptrace_report_syscall(struct pt_regs *regs)
{ {
int ptrace = task_ptrace(current); int ptrace = current->ptrace;
if (!(ptrace & PT_PTRACED)) if (!(ptrace & PT_PTRACED))
return; return;
...@@ -155,7 +155,7 @@ static inline void tracehook_report_syscall_exit(struct pt_regs *regs, int step) ...@@ -155,7 +155,7 @@ static inline void tracehook_report_syscall_exit(struct pt_regs *regs, int step)
static inline int tracehook_unsafe_exec(struct task_struct *task) static inline int tracehook_unsafe_exec(struct task_struct *task)
{ {
int unsafe = 0; int unsafe = 0;
int ptrace = task_ptrace(task); int ptrace = task->ptrace;
if (ptrace & PT_PTRACED) { if (ptrace & PT_PTRACED) {
if (ptrace & PT_PTRACE_CAP) if (ptrace & PT_PTRACE_CAP)
unsafe |= LSM_UNSAFE_PTRACE_CAP; unsafe |= LSM_UNSAFE_PTRACE_CAP;
...@@ -178,7 +178,7 @@ static inline int tracehook_unsafe_exec(struct task_struct *task) ...@@ -178,7 +178,7 @@ static inline int tracehook_unsafe_exec(struct task_struct *task)
*/ */
static inline struct task_struct *tracehook_tracer_task(struct task_struct *tsk) static inline struct task_struct *tracehook_tracer_task(struct task_struct *tsk)
{ {
if (task_ptrace(tsk) & PT_PTRACED) if (tsk->ptrace & PT_PTRACED)
return rcu_dereference(tsk->parent); return rcu_dereference(tsk->parent);
return NULL; return NULL;
} }
...@@ -202,7 +202,7 @@ static inline void tracehook_report_exec(struct linux_binfmt *fmt, ...@@ -202,7 +202,7 @@ static inline void tracehook_report_exec(struct linux_binfmt *fmt,
struct pt_regs *regs) struct pt_regs *regs)
{ {
if (!ptrace_event(PT_TRACE_EXEC, PTRACE_EVENT_EXEC, 0) && if (!ptrace_event(PT_TRACE_EXEC, PTRACE_EVENT_EXEC, 0) &&
unlikely(task_ptrace(current) & PT_PTRACED)) unlikely(current->ptrace & PT_PTRACED))
send_sig(SIGTRAP, current, 0); send_sig(SIGTRAP, current, 0);
} }
...@@ -285,7 +285,7 @@ static inline void tracehook_report_clone(struct pt_regs *regs, ...@@ -285,7 +285,7 @@ static inline void tracehook_report_clone(struct pt_regs *regs,
unsigned long clone_flags, unsigned long clone_flags,
pid_t pid, struct task_struct *child) pid_t pid, struct task_struct *child)
{ {
if (unlikely(task_ptrace(child))) { if (unlikely(child->ptrace)) {
/* /*
* It doesn't matter who attached/attaching to this * It doesn't matter who attached/attaching to this
* task, the pending SIGSTOP is right in any case. * task, the pending SIGSTOP is right in any case.
...@@ -403,7 +403,7 @@ static inline void tracehook_signal_handler(int sig, siginfo_t *info, ...@@ -403,7 +403,7 @@ static inline void tracehook_signal_handler(int sig, siginfo_t *info,
static inline int tracehook_consider_ignored_signal(struct task_struct *task, static inline int tracehook_consider_ignored_signal(struct task_struct *task,
int sig) int sig)
{ {
return (task_ptrace(task) & PT_PTRACED) != 0; return (task->ptrace & PT_PTRACED) != 0;
} }
/** /**
...@@ -422,7 +422,7 @@ static inline int tracehook_consider_ignored_signal(struct task_struct *task, ...@@ -422,7 +422,7 @@ static inline int tracehook_consider_ignored_signal(struct task_struct *task,
static inline int tracehook_consider_fatal_signal(struct task_struct *task, static inline int tracehook_consider_fatal_signal(struct task_struct *task,
int sig) int sig)
{ {
return (task_ptrace(task) & PT_PTRACED) != 0; return (task->ptrace & PT_PTRACED) != 0;
} }
#define DEATH_REAP -1 #define DEATH_REAP -1
......
...@@ -765,7 +765,7 @@ static void reparent_leader(struct task_struct *father, struct task_struct *p, ...@@ -765,7 +765,7 @@ static void reparent_leader(struct task_struct *father, struct task_struct *p,
p->exit_signal = SIGCHLD; p->exit_signal = SIGCHLD;
/* If it has exited notify the new parent about this child's death. */ /* If it has exited notify the new parent about this child's death. */
if (!task_ptrace(p) && if (!p->ptrace &&
p->exit_state == EXIT_ZOMBIE && thread_group_empty(p)) { p->exit_state == EXIT_ZOMBIE && thread_group_empty(p)) {
do_notify_parent(p, p->exit_signal); do_notify_parent(p, p->exit_signal);
if (task_detached(p)) { if (task_detached(p)) {
...@@ -795,7 +795,7 @@ static void forget_original_parent(struct task_struct *father) ...@@ -795,7 +795,7 @@ static void forget_original_parent(struct task_struct *father)
do { do {
t->real_parent = reaper; t->real_parent = reaper;
if (t->parent == father) { if (t->parent == father) {
BUG_ON(task_ptrace(t)); BUG_ON(t->ptrace);
t->parent = t->real_parent; t->parent = t->real_parent;
} }
if (t->pdeath_signal) if (t->pdeath_signal)
...@@ -1565,7 +1565,7 @@ static int wait_consider_task(struct wait_opts *wo, int ptrace, ...@@ -1565,7 +1565,7 @@ static int wait_consider_task(struct wait_opts *wo, int ptrace,
* Notification and reaping will be cascaded to the real * Notification and reaping will be cascaded to the real
* parent when the ptracer detaches. * parent when the ptracer detaches.
*/ */
if (likely(!ptrace) && unlikely(task_ptrace(p))) { if (likely(!ptrace) && unlikely(p->ptrace)) {
/* it will become visible, clear notask_error */ /* it will become visible, clear notask_error */
wo->notask_error = 0; wo->notask_error = 0;
return 0; return 0;
...@@ -1608,7 +1608,7 @@ static int wait_consider_task(struct wait_opts *wo, int ptrace, ...@@ -1608,7 +1608,7 @@ static int wait_consider_task(struct wait_opts *wo, int ptrace,
* own children, it should create a separate process which * own children, it should create a separate process which
* takes the role of real parent. * takes the role of real parent.
*/ */
if (likely(!ptrace) && task_ptrace(p) && if (likely(!ptrace) && p->ptrace &&
same_thread_group(p->parent, p->real_parent)) same_thread_group(p->parent, p->real_parent))
return 0; return 0;
......
...@@ -1592,7 +1592,7 @@ int do_notify_parent(struct task_struct *tsk, int sig) ...@@ -1592,7 +1592,7 @@ int do_notify_parent(struct task_struct *tsk, int sig)
/* do_notify_parent_cldstop should have been called instead. */ /* do_notify_parent_cldstop should have been called instead. */
BUG_ON(task_is_stopped_or_traced(tsk)); BUG_ON(task_is_stopped_or_traced(tsk));
BUG_ON(!task_ptrace(tsk) && BUG_ON(!tsk->ptrace &&
(tsk->group_leader != tsk || !thread_group_empty(tsk))); (tsk->group_leader != tsk || !thread_group_empty(tsk)));
info.si_signo = sig; info.si_signo = sig;
...@@ -1631,7 +1631,7 @@ int do_notify_parent(struct task_struct *tsk, int sig) ...@@ -1631,7 +1631,7 @@ int do_notify_parent(struct task_struct *tsk, int sig)
psig = tsk->parent->sighand; psig = tsk->parent->sighand;
spin_lock_irqsave(&psig->siglock, flags); spin_lock_irqsave(&psig->siglock, flags);
if (!task_ptrace(tsk) && sig == SIGCHLD && if (!tsk->ptrace && sig == SIGCHLD &&
(psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN || (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN ||
(psig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT))) { (psig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT))) {
/* /*
...@@ -1731,7 +1731,7 @@ static void do_notify_parent_cldstop(struct task_struct *tsk, ...@@ -1731,7 +1731,7 @@ static void do_notify_parent_cldstop(struct task_struct *tsk,
static inline int may_ptrace_stop(void) static inline int may_ptrace_stop(void)
{ {
if (!likely(task_ptrace(current))) if (!likely(current->ptrace))
return 0; return 0;
/* /*
* Are we in the middle of do_coredump? * Are we in the middle of do_coredump?
...@@ -1989,7 +1989,7 @@ static bool do_signal_stop(int signr) ...@@ -1989,7 +1989,7 @@ static bool do_signal_stop(int signr)
if (!(sig->flags & SIGNAL_STOP_STOPPED)) if (!(sig->flags & SIGNAL_STOP_STOPPED))
sig->group_exit_code = signr; sig->group_exit_code = signr;
else else
WARN_ON_ONCE(!task_ptrace(current)); WARN_ON_ONCE(!current->ptrace);
sig->group_stop_count = 0; sig->group_stop_count = 0;
...@@ -2014,7 +2014,7 @@ static bool do_signal_stop(int signr) ...@@ -2014,7 +2014,7 @@ static bool do_signal_stop(int signr)
} }
} }
if (likely(!task_ptrace(current))) { if (likely(!current->ptrace)) {
int notify = 0; int notify = 0;
/* /*
...@@ -2093,7 +2093,7 @@ static void do_jobctl_trap(void) ...@@ -2093,7 +2093,7 @@ static void do_jobctl_trap(void)
static int ptrace_signal(int signr, siginfo_t *info, static int ptrace_signal(int signr, siginfo_t *info,
struct pt_regs *regs, void *cookie) struct pt_regs *regs, void *cookie)
{ {
if (!task_ptrace(current)) if (!current->ptrace)
return signr; return signr;
ptrace_signal_deliver(regs, cookie); ptrace_signal_deliver(regs, cookie);
...@@ -2179,7 +2179,7 @@ int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, ...@@ -2179,7 +2179,7 @@ int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka,
do_notify_parent_cldstop(current, false, why); do_notify_parent_cldstop(current, false, why);
leader = current->group_leader; leader = current->group_leader;
if (task_ptrace(leader) && !real_parent_is_ptracer(leader)) if (leader->ptrace && !real_parent_is_ptracer(leader))
do_notify_parent_cldstop(leader, true, why); do_notify_parent_cldstop(leader, true, why);
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
......
...@@ -339,8 +339,7 @@ static struct task_struct *select_bad_process(unsigned int *ppoints, ...@@ -339,8 +339,7 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
* then wait for it to finish before killing * then wait for it to finish before killing
* some other task unnecessarily. * some other task unnecessarily.
*/ */
if (!(task_ptrace(p->group_leader) & if (!(p->group_leader->ptrace & PT_TRACE_EXIT))
PT_TRACE_EXIT))
return ERR_PTR(-1UL); return ERR_PTR(-1UL);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment