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

From: Cyrill Gorcunov
Date: Fri Mar 02 2012 - 11:12:57 EST


On Fri, Mar 02, 2012 at 04:26:22PM +0100, Oleg Nesterov wrote:
...
> > 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.

Yes, Oleg, you're right of course! The set_mm_exe_file confused
me a bit (I didn't reply to your previous emails simply because
you were asking me to prove what exactly is broken when num_exe_file_vmas
greater 2 and we reassign new exe_file, and I didn't know what to reply
since I knew I was wrong in first assumption).

As a conclusion -- sure I need to check for num_exe_file_vmas to
not break current logic, thanks!

Cyrill
--
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/