Re: [RFC] c/r: prctl: Add ability to set new mm_struct::exe_file

From: Oleg Nesterov
Date: Thu Mar 01 2012 - 14:48:22 EST


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.

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