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] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 5 May 2017 19:17:31 +0200
From:   Vegard Nossum <vegard.nossum@...cle.com>
To:     Oleg Nesterov <oleg@...hat.com>
Cc:     linux-kernel@...r.kernel.org,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Frederic Weisbecker <fweisbec@...il.com>,
        Jamie Iles <jamie.iles@...cle.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Thomas Gleixner <tglx@...utronix.de>,
        Andy Lutomirski <luto@...nel.org>
Subject: Re: [PATCH] kthread: fix use-after-free if kthread fork fails

On 05/05/17 18:44, Oleg Nesterov wrote:
> 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?

clone_flags is not available in dup_task_struct(), but we could move
those lines higher in copy_process(). The reason we didn't do it was
that we thought it was a little fragile/unobvious that this has to
happen before free_task() is called and that it was safer to clear it in
dup_task_struct() (which also contains zeroing of other fields).

The newly attached patch has been tested and seems to work, if you
prefer it.


Vegard

View attachment "set_child_tid.patch" of type "text/x-patch" (1094 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ