Re: [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID

2019-08-07 Thread Christian Brauner
On Wed, Aug 07, 2019 at 05:48:29PM +0200, Oleg Nesterov wrote: > On 08/06, Adrian Reber wrote: > > > > @@ -2530,12 +2530,14 @@ noinline static int > > copy_clone_args_from_user(struct kernel_clone_args *kargs, > > struct clone_args __user *uargs, > >

Re: [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID

2019-08-07 Thread Christian Brauner
On Wed, Aug 07, 2019 at 06:08:56PM +0200, Oleg Nesterov wrote: > On 08/06, Adrian Reber wrote: > > > > @@ -2573,6 +2575,14 @@ noinline static int copy_clone_args_from_user(struct > > kernel_clone_args *kargs, > > .tls= args.tls, > > }; > > > > + if (size == sizeof(s

Re: [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID

2019-08-07 Thread Christian Brauner
On Wed, Aug 07, 2019 at 04:26:10PM +0200, Oleg Nesterov wrote: > On 08/06, Adrian Reber wrote: > > > > +struct pid *alloc_pid(struct pid_namespace *ns, int set_tid) > > { > > struct pid *pid; > > enum pid_type type; > > @@ -186,12 +186,35 @@ struct pid *alloc_pid(struct pid_namespace *ns)

Re: [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID

2019-08-07 Thread Christian Brauner
On Tue, Aug 06, 2019 at 09:15:50PM +0200, Adrian Reber wrote: > The main motivation to add set_tid to clone3() is CRIU. > > To restore a process with the same PID/TID CRIU currently uses > /proc/sys/kernel/ns_last_pid. It writes the desired (PID - 1) to > ns_last_pid and then (quickly) does a clon

Re: [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID

2019-08-07 Thread Dmitry Safonov
On 8/7/19 5:33 PM, Dmitry Safonov wrote: > On 8/7/19 5:21 PM, Oleg Nesterov wrote: >> On 08/07, Dmitry Safonov wrote: > [..] >>> What if the size is lesser than offsetof(struct clone_args, stack_size)? >>> Probably, there should be still a check that it's not lesser than what's >>> the required min

Re: [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID

2019-08-07 Thread Dmitry Safonov
On 8/7/19 5:21 PM, Oleg Nesterov wrote: > On 08/07, Dmitry Safonov wrote: [..] >> What if the size is lesser than offsetof(struct clone_args, stack_size)? >> Probably, there should be still a check that it's not lesser than what's >> the required minimum.. > > Not sure I understand... I mean, this

Re: [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID

2019-08-07 Thread Oleg Nesterov
On 08/07, Dmitry Safonov wrote: > > On 8/7/19 4:48 PM, Oleg Nesterov wrote: > > On 08/06, Adrian Reber wrote: > >> > >> @@ -2530,12 +2530,14 @@ noinline static int > >> copy_clone_args_from_user(struct kernel_clone_args *kargs, > >> struct clone_args __use

Re: [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID

2019-08-07 Thread Oleg Nesterov
On 08/06, Adrian Reber wrote: > > @@ -2573,6 +2575,14 @@ noinline static int copy_clone_args_from_user(struct > kernel_clone_args *kargs, > .tls= args.tls, > }; > > + if (size == sizeof(struct clone_args)) { > + /* Only check permissions if set_tid

Re: [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID

2019-08-07 Thread Dmitry Safonov
On 8/7/19 4:48 PM, Oleg Nesterov wrote: > On 08/06, Adrian Reber wrote: >> >> @@ -2530,12 +2530,14 @@ noinline static int copy_clone_args_from_user(struct >> kernel_clone_args *kargs, >>struct clone_args __user *uargs, >>

Re: [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID

2019-08-07 Thread Oleg Nesterov
On 08/06, Adrian Reber wrote: > > @@ -2530,12 +2530,14 @@ noinline static int copy_clone_args_from_user(struct > kernel_clone_args *kargs, > struct clone_args __user *uargs, > size_t size) > { > + struct p

Re: [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID

2019-08-07 Thread Oleg Nesterov
On 08/06, Adrian Reber wrote: > > +struct pid *alloc_pid(struct pid_namespace *ns, int set_tid) > { > struct pid *pid; > enum pid_type type; > @@ -186,12 +186,35 @@ struct pid *alloc_pid(struct pid_namespace *ns) > if (idr_get_cursor(&tmp->idr) > RESERVED_PIDS) >

[PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID

2019-08-06 Thread Adrian Reber
The main motivation to add set_tid to clone3() is CRIU. To restore a process with the same PID/TID CRIU currently uses /proc/sys/kernel/ns_last_pid. It writes the desired (PID - 1) to ns_last_pid and then (quickly) does a clone(). This works most of the time, but it is racy. It is also slow as it