lkml.org 
[lkml]   [2012]   [Mar]   [8]   [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 v3
On 03/08, Cyrill Gorcunov wrote:
>
> On Thu, Mar 08, 2012 at 07:26:23PM +0100, Oleg Nesterov wrote:
> > I think that you should do
> >
> > down_write(&mm->mmap_sem);
> > if (mm->num_exe_file_vmas) {
> > fput(mm->exe_file);
> > mm->exe_file = exe_file;
> > exe_file = NULL;
> > }
> > up_write(&mm->mmap_sem);
> >
> > to keep the current "mm->exe_file goes away after the final
> > unmap(MAP_EXECUTABLE)" logic.
> >
> > OK, may be this doesn't work in c/r case because you are actually
> > going to remove the old mappings? But in this case the new exe_file
> > will go away anyway, afaics PR_SET_MM_EXE_FILE is called when you
> > still have the old mappings.
>
> Yes, exactly, I need to remove old mappings first (because VMAs
> we're about to restore may intersect with current map the host
> program has). And yes, once they all are removed I don't have
> /proc/pid/exe anymore. That's why I need num_exe_file_vmas == 0
> case.

OK, in this case PR_SET_MM_EXE_FILE should probably fail if
mm->num_exe_file_vmas != 0 ? This way it would be more or less
consistent or at least understandable. Just we add the new
special case: num_exe_file_vmas == 0 but exe_file != NULL
because c/r people are crazy.

> > And I don't think the unconditional
> >
> > down_write(&mm->mmap_sem);
> > set_mm_exe_file(mm, exe_file);
> > up_write(&mm->mmap_sem);
> >
> > is 100% right, this clears ->num_exe_file_vmas. This means that
> > (if you still have the old mapping) the new exe_file can go away
> > after added_exe_file_vma() + removed_exe_file_vma(). Normally this
> > should happen, but afaics this is possible. Note that even, say,
> > mprotect() can trigger added_exe_file_vma().
> >
>
> Wait, Oleg, I'm confused, in case if there *is* exitsting VM_EXECUTABLEs
> then we jump into first banch and simply replace old exe_file.

Yes. And then later you remove the old mapping (which do not match
the new file anyway) and the new exe_file goes away. Unlikely you
want this.

Oleg.



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