lkml.org 
[lkml]   [2012]   [Mar]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC] c/r: prctl: Add ability to set new mm_struct::exe_file
On 03/01, Cyrill Gorcunov wrote:
>
> So, Oleg, basically the new version will use opened fd in form
> like (note, I'll recheck for refs and locks more so this is
> a draft version to point idea)
>
> static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)
> {
> struct files_struct *files;
> struct file *file;
> int ret;
>
> /*
> * Make sure if someone is trying to obtain
> * the existing exe_file it will not get
> * results until we've finished.
> */
> down_write(&mm->mmap_sem);
>
> files = get_files_struct(current);
> if (!files)
> return -EINVAL;
>
> spin_lock(&files->file_lock);
>
> file = fcheck_files(files, fd);
> if (!file) {
> ret = -EBADFD;
> goto out_unlock;
> }
> get_file(file);
> spin_unlock(&files->file_lock);
>
> if (mm->num_exe_file_vmas)
> removed_exe_file_vma(mm);

Still can't understand. I think you need:

file = fget(fd);
if (!file)
return -EBADF;

down_write(&mm->mmap_sem);
if (mm->num_exe_file_vmas) {
fput(mm->exe_file);
mm->exe_file = file;
file = NULL;
}
up_write(&mm->mmap_sem);

if (!file)
return 0;

fput(file);
return -ESOMETHING;

and that is all.

Oleg.



\
 
 \ /
  Last update: 2012-03-01 20:51    [W:0.088 / U:0.252 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site