Skip to content

Commit 06d9847

Browse files
htejunoleg-nesterov
authored andcommitted
ptrace: s/tracehook_tracer_task()/ptrace_parent()/
tracehook.h is on the way out. Rename tracehook_tracer_task() to ptrace_parent() and move it from tracehook.h to ptrace.h. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Christoph Hellwig <hch@infradead.org> Cc: John Johansen <john.johansen@canonical.com> Cc: Stephen Smalley <sds@tycho.nsa.gov> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
1 parent 4b9d33e commit 06d9847

6 files changed

Lines changed: 23 additions & 23 deletions

File tree

‎fs/proc/array.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
172172
task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
173173
tpid = 0;
174174
if (pid_alive(p)) {
175-
struct task_struct *tracer = tracehook_tracer_task(p);
175+
struct task_struct *tracer = ptrace_parent(p);
176176
if (tracer)
177177
tpid = task_pid_nr_ns(tracer, ns);
178178
}

‎fs/proc/base.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static struct mm_struct *__check_mem_permission(struct task_struct *task)
216216
if (task_is_stopped_or_traced(task)) {
217217
int match;
218218
rcu_read_lock();
219-
match = (tracehook_tracer_task(task) == current);
219+
match = (ptrace_parent(task) == current);
220220
rcu_read_unlock();
221221
if (match && ptrace_may_access(task, PTRACE_MODE_ATTACH))
222222
return mm;

‎include/linux/ptrace.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,24 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
150150
int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
151151
unsigned long data);
152152

153+
/**
154+
* ptrace_parent - return the task that is tracing the given task
155+
* @task: task to consider
156+
*
157+
* Returns %NULL if no one is tracing @task, or the &struct task_struct
158+
* pointer to its tracer.
159+
*
160+
* Must called under rcu_read_lock(). The pointer returned might be kept
161+
* live only by RCU. During exec, this may be called with task_lock() held
162+
* on @task, still held from when check_unsafe_exec() was called.
163+
*/
164+
static inline struct task_struct *ptrace_parent(struct task_struct *task)
165+
{
166+
if (unlikely(task->ptrace))
167+
return rcu_dereference(task->parent);
168+
return NULL;
169+
}
170+
153171
/**
154172
* ptrace_event_enabled - test whether a ptrace event is enabled
155173
* @task: ptracee of interest

‎include/linux/tracehook.h‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,6 @@ static inline void tracehook_report_syscall_exit(struct pt_regs *regs, int step)
129129
ptrace_report_syscall(regs);
130130
}
131131

132-
/**
133-
* tracehook_tracer_task - return the task that is tracing the given task
134-
* @tsk: task to consider
135-
*
136-
* Returns NULL if no one is tracing @task, or the &struct task_struct
137-
* pointer to its tracer.
138-
*
139-
* Must called under rcu_read_lock(). The pointer returned might be kept
140-
* live only by RCU. During exec, this may be called with task_lock()
141-
* held on @task, still held from when tracehook_unsafe_exec() was called.
142-
*/
143-
static inline struct task_struct *tracehook_tracer_task(struct task_struct *tsk)
144-
{
145-
if (tsk->ptrace & PT_PTRACED)
146-
return rcu_dereference(tsk->parent);
147-
return NULL;
148-
}
149-
150132
/**
151133
* tracehook_signal_handler - signal handler setup is complete
152134
* @sig: number of signal being delivered

‎security/apparmor/domain.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static int may_change_ptraced_domain(struct task_struct *task,
6767
int error = 0;
6868

6969
rcu_read_lock();
70-
tracer = tracehook_tracer_task(task);
70+
tracer = ptrace_parent(task);
7171
if (tracer) {
7272
/* released below */
7373
cred = get_task_cred(tracer);

‎security/selinux/hooks.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,7 +2048,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)
20482048
u32 ptsid = 0;
20492049

20502050
rcu_read_lock();
2051-
tracer = tracehook_tracer_task(current);
2051+
tracer = ptrace_parent(current);
20522052
if (likely(tracer != NULL)) {
20532053
sec = __task_cred(tracer)->security;
20542054
ptsid = sec->sid;
@@ -5314,7 +5314,7 @@ static int selinux_setprocattr(struct task_struct *p,
53145314
Otherwise, leave SID unchanged and fail. */
53155315
ptsid = 0;
53165316
task_lock(p);
5317-
tracer = tracehook_tracer_task(p);
5317+
tracer = ptrace_parent(p);
53185318
if (tracer)
53195319
ptsid = task_sid(tracer);
53205320
task_unlock(p);

0 commit comments

Comments
 (0)