Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 256867
b: refs/heads/master
c: f701e5b
h: refs/heads/master
i:
  256865: 0f4ac9c
  256863: 7d9d9c2
v: v3
  • Loading branch information
Vladimir Zapolskiy authored and Oleg Nesterov committed Jul 18, 2011
1 parent 2024980 commit 3a8e29b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d184d6eb1dc3c9869e25a8e422be5c55ab0db4ac
refs/heads/master: f701e5b73a1a79ea62ffd45d9e2bed4c7d5c1fd2
35 changes: 35 additions & 0 deletions trunk/drivers/connector/cn_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <linux/init.h>
#include <linux/connector.h>
#include <linux/gfp.h>
#include <linux/ptrace.h>
#include <asm/atomic.h>
#include <asm/unaligned.h>

Expand Down Expand Up @@ -166,6 +167,40 @@ void proc_sid_connector(struct task_struct *task)
cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
}

void proc_ptrace_connector(struct task_struct *task, int ptrace_id)
{
struct cn_msg *msg;
struct proc_event *ev;
struct timespec ts;
__u8 buffer[CN_PROC_MSG_SIZE];
struct task_struct *tracer;

if (atomic_read(&proc_event_num_listeners) < 1)
return;

msg = (struct cn_msg *)buffer;
ev = (struct proc_event *)msg->data;
get_seq(&msg->seq, &ev->cpu);
ktime_get_ts(&ts); /* get high res monotonic timestamp */
put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
ev->what = PROC_EVENT_PTRACE;
ev->event_data.ptrace.process_pid = task->pid;
ev->event_data.ptrace.process_tgid = task->tgid;
if (ptrace_id == PTRACE_ATTACH) {
ev->event_data.ptrace.tracer_pid = current->pid;
ev->event_data.ptrace.tracer_tgid = current->tgid;
} else if (ptrace_id == PTRACE_DETACH) {
ev->event_data.ptrace.tracer_pid = 0;
ev->event_data.ptrace.tracer_tgid = 0;
} else
return;

memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
msg->ack = 0; /* not used */
msg->len = sizeof(*ev);
cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
}

void proc_exit_connector(struct task_struct *task)
{
struct cn_msg *msg;
Expand Down
13 changes: 13 additions & 0 deletions trunk/include/linux/cn_proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct proc_event {
PROC_EVENT_UID = 0x00000004,
PROC_EVENT_GID = 0x00000040,
PROC_EVENT_SID = 0x00000080,
PROC_EVENT_PTRACE = 0x00000100,
/* "next" should be 0x00000400 */
/* "last" is the last process event: exit */
PROC_EVENT_EXIT = 0x80000000
Expand Down Expand Up @@ -95,6 +96,13 @@ struct proc_event {
__kernel_pid_t process_tgid;
} sid;

struct ptrace_proc_event {
__kernel_pid_t process_pid;
__kernel_pid_t process_tgid;
__kernel_pid_t tracer_pid;
__kernel_pid_t tracer_tgid;
} ptrace;

struct exit_proc_event {
__kernel_pid_t process_pid;
__kernel_pid_t process_tgid;
Expand All @@ -109,6 +117,7 @@ void proc_fork_connector(struct task_struct *task);
void proc_exec_connector(struct task_struct *task);
void proc_id_connector(struct task_struct *task, int which_id);
void proc_sid_connector(struct task_struct *task);
void proc_ptrace_connector(struct task_struct *task, int which_id);
void proc_exit_connector(struct task_struct *task);
#else
static inline void proc_fork_connector(struct task_struct *task)
Expand All @@ -124,6 +133,10 @@ static inline void proc_id_connector(struct task_struct *task,
static inline void proc_sid_connector(struct task_struct *task)
{}

static inline void proc_ptrace_connector(struct task_struct *task,
int ptrace_id)
{}

static inline void proc_exit_connector(struct task_struct *task)
{}
#endif /* CONFIG_PROC_EVENTS */
Expand Down
7 changes: 6 additions & 1 deletion trunk/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <linux/uaccess.h>
#include <linux/regset.h>
#include <linux/hw_breakpoint.h>
#include <linux/cn_proc.h>


static int ptrace_trapping_sleep_fn(void *flags)
Expand Down Expand Up @@ -305,9 +306,12 @@ static int ptrace_attach(struct task_struct *task, long request,
unlock_creds:
mutex_unlock(&task->signal->cred_guard_mutex);
out:
if (!retval)
if (!retval) {
wait_on_bit(&task->jobctl, JOBCTL_TRAPPING_BIT,
ptrace_trapping_sleep_fn, TASK_UNINTERRUPTIBLE);
proc_ptrace_connector(task, PTRACE_ATTACH);
}

return retval;
}

Expand Down Expand Up @@ -415,6 +419,7 @@ static int ptrace_detach(struct task_struct *child, unsigned int data)
}
write_unlock_irq(&tasklist_lock);

proc_ptrace_connector(child, PTRACE_DETACH);
if (unlikely(dead))
release_task(child);

Expand Down

0 comments on commit 3a8e29b

Please sign in to comment.