lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Mon, 20 Nov 2017 10:54:23 +0100
From:   Michal Hocko <mhocko@...nel.org>
To:     Marcos Paulo de Souza <marcos.souza.org@...il.com>
Cc:     Andrew Morton <akpm@...ux-foundation.org>,
        Ingo Molnar <mingo@...nel.org>, Rik van Riel <riel@...hat.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Oleg Nesterov <oleg@...hat.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH -next] fork.c: Check error and return early

On Thu 16-11-17 22:28:08, Marcos Paulo de Souza wrote:
> Thus reducing one indentation level while maintaining the same
> rationale.
> 
> Signed-off-by: Marcos Paulo de Souza <marcos.souza.org@...il.com>

looks reasonable to me
Acked-by: Michal Hocko <mhocko@...e.com>

> ---
>  kernel/fork.c | 51 +++++++++++++++++++++++++--------------------------
>  1 file changed, 25 insertions(+), 26 deletions(-)
> 
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 3cefe81b50f2..2113e252cb9d 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -2068,6 +2068,8 @@ long _do_fork(unsigned long clone_flags,
>  	      int __user *child_tidptr,
>  	      unsigned long tls)
>  {
> +	struct completion vfork;
> +	struct pid *pid;
>  	struct task_struct *p;
>  	int trace = 0;
>  	long nr;
> @@ -2093,43 +2095,40 @@ long _do_fork(unsigned long clone_flags,
>  	p = copy_process(clone_flags, stack_start, stack_size,
>  			 child_tidptr, NULL, trace, tls, NUMA_NO_NODE);
>  	add_latent_entropy();
> +
> +	if (IS_ERR(p))
> +		return PTR_ERR(p);
> +
>  	/*
>  	 * Do this prior waking up the new thread - the thread pointer
>  	 * might get invalid after that point, if the thread exits quickly.
>  	 */
> -	if (!IS_ERR(p)) {
> -		struct completion vfork;
> -		struct pid *pid;
> -
> -		trace_sched_process_fork(current, p);
> +	trace_sched_process_fork(current, p);
>  
> -		pid = get_task_pid(p, PIDTYPE_PID);
> -		nr = pid_vnr(pid);
> +	pid = get_task_pid(p, PIDTYPE_PID);
> +	nr = pid_vnr(pid);
>  
> -		if (clone_flags & CLONE_PARENT_SETTID)
> -			put_user(nr, parent_tidptr);
> -
> -		if (clone_flags & CLONE_VFORK) {
> -			p->vfork_done = &vfork;
> -			init_completion(&vfork);
> -			get_task_struct(p);
> -		}
> +	if (clone_flags & CLONE_PARENT_SETTID)
> +		put_user(nr, parent_tidptr);
>  
> -		wake_up_new_task(p);
> +	if (clone_flags & CLONE_VFORK) {
> +		p->vfork_done = &vfork;
> +		init_completion(&vfork);
> +		get_task_struct(p);
> +	}
>  
> -		/* forking complete and child started to run, tell ptracer */
> -		if (unlikely(trace))
> -			ptrace_event_pid(trace, pid);
> +	wake_up_new_task(p);
>  
> -		if (clone_flags & CLONE_VFORK) {
> -			if (!wait_for_vfork_done(p, &vfork))
> -				ptrace_event_pid(PTRACE_EVENT_VFORK_DONE, pid);
> -		}
> +	/* forking complete and child started to run, tell ptracer */
> +	if (unlikely(trace))
> +		ptrace_event_pid(trace, pid);
>  
> -		put_pid(pid);
> -	} else {
> -		nr = PTR_ERR(p);
> +	if (clone_flags & CLONE_VFORK) {
> +		if (!wait_for_vfork_done(p, &vfork))
> +			ptrace_event_pid(PTRACE_EVENT_VFORK_DONE, pid);
>  	}
> +
> +	put_pid(pid);
>  	return nr;
>  }
>  
> -- 
> 2.13.6
> 

-- 
Michal Hocko
SUSE Labs

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ