[PATCH 3/4] pid: introduce find_get_pid_ns
From: Erin Shepherd
Date: Fri Nov 01 2024 - 09:56:18 EST
In some situations it is useful to be able to atomically get a PID
from a specific PID namespace.
Signed-off-by: Erin Shepherd <erin.shepherd@xxxxxx>
---
include/linux/pid.h | 1 +
kernel/pid.c | 10 ++++++++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/include/linux/pid.h b/include/linux/pid.h
index a3aad9b4074c..965f8b3ff9a8 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -124,6 +124,7 @@ extern struct pid *find_vpid(int nr);
/*
* Lookup a PID in the hash table, and return with it's count elevated.
*/
+extern struct pid *find_get_pid_ns(int nr, struct pid_namespace *ns);
extern struct pid *find_get_pid(int nr);
extern struct pid *find_ge_pid(int nr, struct pid_namespace *);
diff --git a/kernel/pid.c b/kernel/pid.c
index 2715afb77eab..2967f8a98330 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -470,16 +470,22 @@ struct task_struct *get_pid_task(struct pid *pid, enum pid_type type)
}
EXPORT_SYMBOL_GPL(get_pid_task);
-struct pid *find_get_pid(pid_t nr)
+struct pid *find_get_pid_ns(pid_t nr, struct pid_namespace *ns)
{
struct pid *pid;
rcu_read_lock();
- pid = get_pid(find_vpid(nr));
+ pid = get_pid(find_pid_ns(nr, ns));
rcu_read_unlock();
return pid;
}
+EXPORT_SYMBOL_GPL(find_get_pid_ns);
+
+struct pid *find_get_pid(pid_t nr)
+{
+ return find_get_pid_ns(nr, task_active_pid_ns(current));
+}
EXPORT_SYMBOL_GPL(find_get_pid);
pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
--
2.46.1