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

From: Oleg Nesterov
Date: Fri Mar 02 2012 - 10:33:24 EST


On 03/02, Cyrill Gorcunov wrote:
>
> On Thu, Mar 01, 2012 at 08:41:20PM +0100, Oleg Nesterov wrote:
> ...
> > 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.
>
> Hi Oleg, sure you were right. I even think testing for
> num_exe_file_vmas is not needed, since until real
> executable VMA is read and mapped it might remain
> zero. So I guess something like below should work.

No, you need to check num_exe_file_vmas != 0.

> +static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)
> +{
> + struct file *new_exe_file, *old_exe_file;
> +
> + new_exe_file = fget(fd);
> + if (!new_exe_file)
> + return -EBADF;
> +
> + down_write(&mm->mmap_sem);
> + old_exe_file = mm->exe_file;
> + mm->exe_file = new_exe_file;
> + up_write(&mm->mmap_sem);

This changes the current rule: mm->exe_file goes away once
num_exe_file_vmas becomes zero.

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/