Re: [PATCH v10 1/2] fork: extend clone3() to support setting a PID

From: Christian Brauner
Date: Fri Nov 15 2019 - 08:08:10 EST


On Fri, Nov 15, 2019 at 11:49:10AM +0100, Oleg Nesterov wrote:
> On 11/15, Christian Brauner wrote:
> >
> > +static int set_tid_next(pid_t *set_tid, size_t *size, int idx)
> > +{
> > + int tid = 0;
> > +
> > + if (*size) {
> > + tid = set_tid[idx];
> > + if (tid < 1 || tid >= pid_max)
> > + return -EINVAL;
> > +
> > + /*
> > + * Also fail if a PID != 1 is requested and
> > + * no PID 1 exists.
> > + */
> > + if (tid != 1 && !tmp->child_reaper)
> > + return -EINVAL;
> > +
> > + if (!ns_capable(tmp->user_ns, CAP_SYS_ADMIN))
> > + return -EPERM;
> > +
> > + (*size)--;
> > + }
>
> this needs more args, struct pid_namespace *tmp + pid_t pid_max
> if (set_tid_size) {
> tid = set_tid[ns->level - i];
>
> retval = -EINVAL;
> if (tid < 1 || tid >= pid_max)
> goto out_free;

I'm not a fan of this pattern of _not_ setting error codes in the actual
error path t but I won't object.

Christian