lkml.org 
[lkml]   [2020]   [Jul]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Subject[PATCH 15/23] pid: Eextract child_reaper check from pidns_for_children_get()
    From
    Date
    This check if for prohibiting access to /proc/[pid]/ns/pid_for_children
    before first task of the pid namespace is created.

    /proc/namespaces/ code will use this check too, so we move it into
    a separate function.

    Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
    ---
    kernel/pid_namespace.c | 25 ++++++++++++++++++-------
    1 file changed, 18 insertions(+), 7 deletions(-)

    diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
    index d02dc1696edf..4a01328e8763 100644
    --- a/kernel/pid_namespace.c
    +++ b/kernel/pid_namespace.c
    @@ -343,6 +343,21 @@ static struct ns_common *pidns_get(struct task_struct *task)
    return ns ? &ns->ns : NULL;
    }

    +static bool pidns_can_get(struct ns_common *ns)
    +{
    + struct pid_namespace *pid_ns;
    + bool ret = true;
    +
    + pid_ns = container_of(ns, struct pid_namespace, ns);
    +
    + read_lock(&tasklist_lock);
    + if (!pid_ns->child_reaper)
    + ret = false;
    + read_unlock(&tasklist_lock);
    +
    + return ret;
    +}
    +
    static struct ns_common *pidns_for_children_get(struct task_struct *task)
    {
    struct pid_namespace *ns = NULL;
    @@ -354,13 +369,9 @@ static struct ns_common *pidns_for_children_get(struct task_struct *task)
    }
    task_unlock(task);

    - if (ns) {
    - read_lock(&tasklist_lock);
    - if (!ns->child_reaper) {
    - put_pid_ns(ns);
    - ns = NULL;
    - }
    - read_unlock(&tasklist_lock);
    + if (ns && !pidns_can_get(&ns->ns)) {
    + put_pid_ns(ns);
    + ns = NULL;
    }

    return ns ? &ns->ns : NULL;

    \
     
     \ /
      Last update: 2020-07-30 14:01    [W:2.575 / U:0.528 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site