Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1636485

Re: [PATCH] kthread: fix use-after-free if kthread fork fails

From Oleg Nesterov <oleg@redhat.com>
Newsgroups linux.kernel
Subject Re: [PATCH] kthread: fix use-after-free if kthread fork fails
Date 2017-05-05 18:50 +0200
Message-ID <tDOAx-4hv-3@gated-at.bofh.it> (permalink)
References <tDOhc-46o-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 05/05, Vegard Nossum wrote:
>
> If a kthread forks (e.g. usermodehelper since commit 1da5c46fa965) but
> fails in copy_process() between calling dup_task_struct() and setting
> p->set_child_tid, then the value of p->set_child_tid will be inherited
> from the parent and get prematurely freed by free_kthread_struct().

Aaah... thanks!

> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -518,6 +518,13 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
>  	atomic_set(&tsk->stack_refcount, 1);
>  #endif
>  
> +	/*
> +	 * Forking kthreads (e.g. usermodehelper) should not inherit this
> +	 * field since it's a pointer to a 'struct kthread' which is not
> +	 * reference counted.
> +	 */
> +	tsk->set_child_tid = NULL;
> +

Can't we just move both

	p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
	/*
	 * Clear TID on mm_release()?
	 */
	p->clear_child_tid = (clone_flags & CLONE_CHILD_CLEARTID) ? child_tidptr : NULL;

lines here?

Oleg.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] kthread: fix use-after-free if kthread fork fails Vegard Nossum <vegard.nossum@oracle.com> - 2017-05-05 18:30 +0200
  Re: [PATCH] kthread: fix use-after-free if kthread fork fails Oleg Nesterov <oleg@redhat.com> - 2017-05-05 18:50 +0200
    Re: [PATCH] kthread: fix use-after-free if kthread fork fails Vegard Nossum <vegard.nossum@oracle.com> - 2017-05-05 19:20 +0200
      Re: [PATCH] kthread: fix use-after-free if kthread fork fails Oleg Nesterov <oleg@redhat.com> - 2017-05-06 22:00 +0200

csiph-web