]> Git Repo - linux.git/commitdiff
pidns: disable pid allocation if pid_ns_prepare_proc() is failed in alloc_pid()
authorKirill Tkhai <[email protected]>
Mon, 8 May 2017 22:56:34 +0000 (15:56 -0700)
committerLinus Torvalds <[email protected]>
Tue, 9 May 2017 00:15:12 +0000 (17:15 -0700)
alloc_pidmap() advances pid_namespace::last_pid.  When first pid
allocation fails, then next created process will have pid 2 and
pid_ns_prepare_proc() won't be called.  So, pid_namespace::proc_mnt will
never be initialized (not to mention that there won't be a child
reaper).

I saw crash stack of such case on kernel 3.10:

    BUG: unable to handle kernel NULL pointer dereference at (null)
    IP: proc_flush_task+0x8f/0x1b0
    Call Trace:
        release_task+0x3f/0x490
        wait_consider_task.part.10+0x7ff/0xb00
        do_wait+0x11f/0x280
        SyS_wait4+0x7d/0x110

We may fix this by restore of last_pid in 0 or by prohibiting of futher
allocations.  Since there was a similar issue in Oleg Nesterov's commit
314a8ad0f18a ("pidns: fix free_pid() to handle the first fork failure").
and it was fixed via prohibiting allocation, let's follow this way, and
do the same.

Link: http://lkml.kernel.org/r/149201021004.4863.6762095011554287922.stgit@localhost.localdomain
Signed-off-by: Kirill Tkhai <[email protected]>
Acked-by: Cyrill Gorcunov <[email protected]>
Cc: Andrei Vagin <[email protected]>
Cc: Andreas Gruenbacher <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: Michael Kerrisk <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Paul Moore <[email protected]>
Cc: Eric Biederman <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Serge Hallyn <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
kernel/pid.c

index 0143ac0ddceb9c79a2c686e6b10b7265b7b5d925..fd1cde1e45760df67a6cc54fa97959061660ab3f 100644 (file)
@@ -321,8 +321,10 @@ struct pid *alloc_pid(struct pid_namespace *ns)
        }
 
        if (unlikely(is_child_reaper(pid))) {
-               if (pid_ns_prepare_proc(ns))
+               if (pid_ns_prepare_proc(ns)) {
+                       disable_pid_allocation(ns);
                        goto out_free;
+               }
        }
 
        get_pid_ns(ns);
This page took 0.054429 seconds and 4 git commands to generate.