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]
Message-ID: <53EB8DAC.1040605@redhat.com>
Date:	Wed, 13 Aug 2014 12:09:16 -0400
From:	Rik van Riel <riel@...hat.com>
To:	Oleg Nesterov <oleg@...hat.com>
CC:	linux-kernel@...r.kernel.org, akpm@...ux-foundation.org,
	peterz@...radead.org, paulmck@...ux.vnet.ibm.com
Subject: Re: [PATCH] fix sighand use after free

On 08/13/2014 11:58 AM, Oleg Nesterov wrote:
> On 08/13, Rik van Riel wrote:
>>
>> Subject: fix sighand use after free
>>
>> __lock_task_sighand carefully takes the rcu_read_lock, gets
>> tsk->sighand with rcu_dereference, and verifies that the task
>> is still using the sighand_struct after taking the spinlock.
>>
>> This works much better if the sighand struct is actually rcu
>> freed.
> 
> I promise, I'll send the doc patch soon ;)
> 
>> --- a/kernel/fork.c
>> +++ b/kernel/fork.c
>> @@ -1017,7 +1017,7 @@ void __cleanup_sighand(struct sighand_struct *sighand)
>>  {
>>  	if (atomic_dec_and_test(&sighand->count)) {
>>  		signalfd_cleanup(sighand);
>> -		kmem_cache_free(sighand_cachep, sighand);
>> +		rcu_free(sighand_cachep, sighand);
> 
> Please note that sighand_cachep is SLAB_DESTROY_BY_RCU.

SLAB_DESTROY_BY_RCU means that the slab page is not given
back to the system until after the RCU grace period has
expired.

However, the objects inside the slab can still be reused
immediately!

In the case of the sighand struct, we have this possible race:

     thread A       thread B              thread C

                    gets task A->sighand
     kmem_cache_free sighand
                                          re-alloc sighand
                    spin_lock sighand
                                          spin_lock_init sighand
                    spin_unlock sighand

Now task C has a sighand which can never be locked.

> Hmm. and what is rcu_free() ?

Ugh, that should have been kfree_rcu of course, with
appropriate rcu space in the struct.

Now I wonder why my test compile succeeded...

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ