Re: [PATCH 3/4] pid: introduce find_get_pid_ns

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Nov 1, 2024 at 2:56 PM Erin Shepherd <erin.shepherd@xxxxxx> wrote:
>
> 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>

Reviewed-by: Amir Goldstein <amir73il@xxxxxxxxx>

> ---
>  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
>
>





[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux