Messages in this thread | | | Date | Thu, 1 Mar 2012 20:41:20 +0100 | From | Oleg Nesterov <> | Subject | Re: [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.
| |