All of lore.kernel.org
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Oleg Nesterov <oleg@redhat.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>,
	Serge Hallyn <serge.hallyn@ubuntu.com>,
	linux-kernel@vger.kernel.org
Subject: Re: free_pid() && PIDNS_HASH_ADDING
Date: Sun, 08 Sep 2013 14:25:50 -0700	[thread overview]
Message-ID: <87bo43gg4h.fsf@xmission.com> (raw)
In-Reply-To: <20130908180137.GA4915@redhat.com> (Oleg Nesterov's message of "Sun, 8 Sep 2013 20:01:37 +0200")

Oleg Nesterov <oleg@redhat.com> writes:

> On 09/08, Oleg Nesterov wrote:
>>
>> Off topic. What if the first alloc_pid() succeeds and then later
>> copy_process() fails. In this case free_pid() is called but
>> PIDNS_HASH_ADDING was not cleared, we miss kern_unmount(), no?
>
> Perhaps something like below?

I am thinking more:

diff --git a/kernel/pid.c b/kernel/pid.c
index ab75add..ef59516 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -273,6 +273,10 @@ void free_pid(struct pid *pid)
                         */
                        wake_up_process(ns->child_reaper);
                        break;
+               case PIDNS_HASH_ADDING:
+                       /* Handle a fork failure of the first process */
+                       ns->nr_hashed = 0;
+                       /* fall through */
                case 0:
                        schedule_work(&ns->proc_work);
                        break;

At which point I ask myself what of the pathlogocical case where the
first fork fails but because we created the pid namespace with unshare
there is a concurrent fork from another process into the pid namespace
that succeeds.  Resulting in one pid in the pid namespace that is not
the reaper.

So we also need something like this.

@@ -324,6 +328,8 @@ struct pid *alloc_pid(struct pid_namespace *ns)
        spin_lock_irq(&pidmap_lock);
        if (!(ns->nr_hashed & PIDNS_HASH_ADDING))
                goto out_unlock;
+       if (!is_child_reaper(pid) && !ns->child_reaper)
+               goto out_unlock;
        for ( ; upid >= pid->numbers; --upid) {
                hlist_add_head_rcu(&upid->pid_chain,
                                &pid_hash[pid_hashfn(upid->nr, upid->ns)]);

but I think my locking is wrong to safely test ns->child_reaper.

Perhaps I should prevent setns if there is no reaper?

Ideas?

Eric

  reply	other threads:[~2013-09-08 21:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-29 21:11 [PATCH] Make sure to wake reaper Serge Hallyn
2013-08-29 22:08 ` Eric W. Biederman
2013-08-30  0:39 ` Eric W. Biederman
2013-08-30  1:10   ` Serge E. Hallyn
2013-08-30  5:07     ` Eric W. Biederman
2013-08-30 12:46       ` Serge E. Hallyn
2013-08-30 14:42   ` Serge E. Hallyn
2013-08-31  0:30     ` [REVIEW][PATCH] pidns: Fix hang in zap_pid_ns_processes by sending a potentially extra wakeup Eric W. Biederman
2013-09-08 17:56       ` Oleg Nesterov
2013-09-08 18:01         ` free_pid() && PIDNS_HASH_ADDING Oleg Nesterov
2013-09-08 21:25           ` Eric W. Biederman [this message]
2013-09-09 15:15             ` Oleg Nesterov
2013-09-09 17:54               ` Eric W. Biederman
2013-09-10 14:01                 ` [PATCH 0/1] pidns: fix free_pid() to handle the first fork failure Oleg Nesterov
2013-09-10 14:01                   ` [PATCH 1/1] " Oleg Nesterov
     [not found]       ` <CALkWK0kSBrN-ZHG0CEWwvjYQ86ArJtDmbKqJR_6f3_ZTN6xJQQ@mail.gmail.com>
2013-09-09  0:12         ` [REVIEW][PATCH] pidns: Fix hang in zap_pid_ns_processes by sending a potentially extra wakeup Eric W. Biederman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bo43gg4h.fsf@xmission.com \
    --to=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=serge.hallyn@ubuntu.com \
    --cc=serge@hallyn.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.