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: <550701BE.40100@yandex-team.ru>
Date:	Mon, 16 Mar 2015 19:15:58 +0300
From:	Konstantin Khlebnikov <khlebnikov@...dex-team.ru>
To:	Oleg Nesterov <oleg@...hat.com>
CC:	linux-mm@...ck.org, Andrew Morton <akpm@...ux-foundation.org>,
	linux-kernel@...r.kernel.org, Davidlohr Bueso <dbueso@...e.de>,
	Al Viro <viro@...iv.linux.org.uk>
Subject: Re: [PATCH] mm: rcu-protected get_mm_exe_file()

On 16.03.2015 17:07, Oleg Nesterov wrote:
> On 03/16, Konstantin Khlebnikov wrote:
>>
>> +/**
>> + * set_mm_exe_file - change a reference to the mm's executable file
>> + *
>> + * This changes mm's executale file (shown as symlink /proc/[pid]/exe).
>> + *
>> + * Main users are mmput(), sys_execve() and sys_prctl(PR_SET_MM_MAP/EXE_FILE).
>> + * Callers prevent concurrent invocations: in mmput() nobody alive left,
>> + * in execve task is single-threaded, prctl holds mmap_sem exclusively.
>> + */
>>   void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file)
>>   {
>> +	struct file *old_exe_file = rcu_dereference_protected(mm->exe_file,
>> +			!atomic_read(&mm->mm_users) || current->in_execve ||
>> +			lock_is_held(&mm->mmap_sem));
>> +
>>   	if (new_exe_file)
>>   		get_file(new_exe_file);
>> -	if (mm->exe_file)
>> -		fput(mm->exe_file);
>> -	mm->exe_file = new_exe_file;
>> +	rcu_assign_pointer(mm->exe_file, new_exe_file);
>> +	if (old_exe_file)
>> +		fput(old_exe_file);
>>   }
>
> Yes, I think this is correct, __fput() does call_rcu(file_free_rcu). And
> much better than the new lock ;)
>
> Acked-by: Oleg Nesterov <oleg@...hat.com>
>
>
>
> So I think the patch is fine, but personally I dislike the "prctl holds
> mmap_sem exclusively" and rcu_dereference_protected().
>
> I mean, I think we can do another cleanup on top of this change.
>
> 	1. set_mm_exe_file() should be called by exit/exec only, so
> 	   it should use
>
> 		rcu_dereference_protected(mm->exe_file,
> 					atomic_read(&mm->mm_users) <= 1);
>
> 	2. prctl() should not use it, it can do
>
> 	   get_file(new_exe);
> 	   old_exe = xchg(&mm->exe_file);
> 	   if (old_exe)
> 	   	fput(old_exe);

I think smp_mb() is required before xchg() or
probably this stuff should be hidden inside yet another magic RCU macro
( with two screens of comments =)

>
> 	3. and we can remove down_write(mmap_sem) from prctl paths.
>
> 	   Actually we can do this even without xchg() above, but we might
> 	   want to kill MMF_EXE_FILE_CHANGED and test_and_set_bit() check.
>
> What do you think?
>
> Oleg.
>


-- 
Konstantin
--
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