Re: [RFC PATCH] namespaces: fix leak on fork() failure

From: Mike Galbraith
Date: Sun Apr 29 2012 - 05:49:09 EST


On Sun, 2012-04-29 at 00:57 -0700, Eric W. Biederman wrote:

> Mike's proposed change to switch_task_namespace is most definitely not
> correct. This will potentially get called on unshare and so we don't
> limit ourselves to just an exit pid_namespace. The result is that we
> could free the proc mount long before it is safe.

!new && !(p->flags & PF_EXITING) should prevent that..

> At the same time the leak that Mike detected is most definitely real.
>
> > Perhaps it would be more clean to add the explicit
> >
> > bad_fork_cleanup_namespaces:
> > + if (unlikely(clone_flags & CLONE_NEWPID))
> > + pid_ns_release_proc(...);
> > exit_task_namespaces(p);
> >
> >
> > code into this error path in copy_process?
>
> For now Oleg your minimal patch looks good.

..but yeah, that looks much nicer.

> Part of me would like to call proc_flush_task instead of
> pid_ns_release_proc but we have no assurance task_pid and task_tgid are
> valid when we get here so proc_flush_task is out.

I only discovered pid_ns_release_proc() exists after didn't work :)

-Mike

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/