[Devel] [PATCH RH9 16/26] proc connector: add pid namespace awareness

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Thu Oct 7 15:53:56 MSK 2021


From: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>

This is precursor patch. Later VE pid ns will be used.

Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
Reviewed-by: Andrey Ryabinin <aryabinin at virtuozzo.com>

(cherry picked from vz8 commit af343320483fe4ec1a6cb23069d5d299e9312e3c)
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 drivers/connector/cn_proc.c | 54 ++++++++++++++++++++-----------------
 1 file changed, 30 insertions(+), 24 deletions(-)

diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
index 23005ca664da..d389259447d0 100644
--- a/drivers/connector/cn_proc.c
+++ b/drivers/connector/cn_proc.c
@@ -118,11 +118,11 @@ static bool fill_fork_event(struct proc_event *ev, struct task_struct *task,
 
 	rcu_read_lock();
 	parent = rcu_dereference(task->real_parent);
-	ev->event_data.fork.parent_pid = parent->pid;
-	ev->event_data.fork.parent_tgid = parent->tgid;
+	ev->event_data.fork.parent_pid = task_pid_nr_ns(parent, &init_pid_ns);
+	ev->event_data.fork.parent_tgid = task_tgid_nr_ns(parent, &init_pid_ns);
 	rcu_read_unlock();
-	ev->event_data.fork.child_pid = task->pid;
-	ev->event_data.fork.child_tgid = task->tgid;
+	ev->event_data.fork.child_pid = task_pid_nr_ns(task, &init_pid_ns);
+	ev->event_data.fork.child_tgid = task_tgid_nr_ns(task, &init_pid_ns);
 	return true;
 }
 
@@ -134,8 +134,8 @@ void proc_fork_connector(struct task_struct *task)
 static bool fill_exec_event(struct proc_event *ev, struct task_struct *task,
 			    int unused)
 {
-	ev->event_data.exec.process_pid = task->pid;
-	ev->event_data.exec.process_tgid = task->tgid;
+	ev->event_data.exec.process_pid = task_pid_nr_ns(task, &init_pid_ns);
+	ev->event_data.exec.process_tgid = task_tgid_nr_ns(task, &init_pid_ns);
 	return true;
 }
 
@@ -149,8 +149,8 @@ static bool fill_id_event(struct proc_event *ev, struct task_struct *task,
 {
 	const struct cred *cred;
 
-	ev->event_data.id.process_pid = task->pid;
-	ev->event_data.id.process_tgid = task->tgid;
+	ev->event_data.id.process_pid = task_pid_nr_ns(task, &init_pid_ns);
+	ev->event_data.id.process_tgid = task_tgid_nr_ns(task, &init_pid_ns);
 	rcu_read_lock();
 	cred = __task_cred(task);
 	if (which_id == PROC_EVENT_UID) {
@@ -175,8 +175,8 @@ void proc_id_connector(struct task_struct *task, int which_id)
 static bool fill_sid_event(struct proc_event *ev, struct task_struct *task,
 			   int unused)
 {
-	ev->event_data.sid.process_pid = task->pid;
-	ev->event_data.sid.process_tgid = task->tgid;
+	ev->event_data.sid.process_pid = task_pid_nr_ns(task, &init_pid_ns);
+	ev->event_data.sid.process_tgid = task_tgid_nr_ns(task, &init_pid_ns);
 	return true;
 }
 
@@ -188,11 +188,11 @@ void proc_sid_connector(struct task_struct *task)
 static bool fill_ptrace_event(struct proc_event *ev, struct task_struct *task,
 			   int ptrace_id)
 {
-	ev->event_data.ptrace.process_pid  = task->pid;
-	ev->event_data.ptrace.process_tgid = task->tgid;
+	ev->event_data.ptrace.process_pid  = task_pid_nr_ns(task, &init_pid_ns);
+	ev->event_data.ptrace.process_tgid = task_tgid_nr_ns(task, &init_pid_ns);
 	if (ptrace_id == PTRACE_ATTACH) {
-		ev->event_data.ptrace.tracer_pid  = current->pid;
-		ev->event_data.ptrace.tracer_tgid = current->tgid;
+		ev->event_data.ptrace.tracer_pid  = task_pid_nr_ns(current, &init_pid_ns);
+		ev->event_data.ptrace.tracer_tgid = task_tgid_nr_ns(current, &init_pid_ns);
 	} else if (ptrace_id == PTRACE_DETACH) {
 		ev->event_data.ptrace.tracer_pid  = 0;
 		ev->event_data.ptrace.tracer_tgid = 0;
@@ -210,8 +210,8 @@ void proc_ptrace_connector(struct task_struct *task, int ptrace_id)
 static bool fill_comm_event(struct proc_event *ev, struct task_struct *task,
 			    int unused)
 {
-	ev->event_data.comm.process_pid  = task->pid;
-	ev->event_data.comm.process_tgid = task->tgid;
+	ev->event_data.comm.process_pid  = task_pid_nr_ns(task, &init_pid_ns);
+	ev->event_data.comm.process_tgid = task_tgid_nr_ns(task, &init_pid_ns);
 	get_task_comm(ev->event_data.comm.comm, task);
 	return true;
 }
@@ -226,14 +226,18 @@ static bool fill_coredump_event(struct proc_event *ev, struct task_struct *task,
 {
 	struct task_struct *parent;
 
-	ev->event_data.coredump.process_pid = task->pid;
-	ev->event_data.coredump.process_tgid = task->tgid;
+	ev->event_data.coredump.process_pid =
+		task_pid_nr_ns(task, &init_pid_ns);
+	ev->event_data.coredump.process_tgid =
+		task_tgid_nr_ns(task, &init_pid_ns);
 
 	rcu_read_lock();
 	if (pid_alive(task)) {
 		parent = rcu_dereference(task->real_parent);
-		ev->event_data.coredump.parent_pid = parent->pid;
-		ev->event_data.coredump.parent_tgid = parent->tgid;
+		ev->event_data.coredump.parent_pid =
+			task_pid_nr_ns(parent, &init_pid_ns);
+		ev->event_data.coredump.parent_tgid =
+			task_tgid_nr_ns(parent, &init_pid_ns);
 	}
 	rcu_read_unlock();
 	return true;
@@ -249,16 +253,18 @@ static bool fill_exit_event(struct proc_event *ev, struct task_struct *task,
 {
 	struct task_struct *parent;
 
-	ev->event_data.exit.process_pid = task->pid;
-	ev->event_data.exit.process_tgid = task->tgid;
+	ev->event_data.exit.process_pid = task_pid_nr_ns(task, &init_pid_ns);
+	ev->event_data.exit.process_tgid = task_tgid_nr_ns(task, &init_pid_ns);
 	ev->event_data.exit.exit_code = task->exit_code;
 	ev->event_data.exit.exit_signal = task->exit_signal;
 
 	rcu_read_lock();
 	if (pid_alive(task)) {
 		parent = rcu_dereference(task->real_parent);
-		ev->event_data.exit.parent_pid = parent->pid;
-		ev->event_data.exit.parent_tgid = parent->tgid;
+		ev->event_data.exit.parent_pid = task_pid_nr_ns(parent,
+								&init_pid_ns);
+		ev->event_data.exit.parent_tgid = task_tgid_nr_ns(parent,
+								  &init_pid_ns);
 	}
 	rcu_read_unlock();
 	return true;
-- 
2.31.1



More information about the Devel mailing list