Re: [PATCH 5/5] uprobes: kill insert_vm_struct()->uprobe_mmap()

2012-07-13 Thread Srikar Dronamraju
* Oleg Nesterov  [2012-07-13 15:29:16]:

> On 07/13, Srikar Dronamraju wrote:
> >
> > * Oleg Nesterov  [2012-07-08 22:30:11]:
> >
> > > Kill insert_vm_struct()->uprobe_mmap(). It is not needed, nobody
> > > except arch/ia64/kernel/perfmon.c uses insert_vm_struct(vma) with
> > > vma->vm_file != NULL.
> > >
> >
> > Right, but somebody else might start using this later.
> 
> Unlikely, I think...
> 
> > I cant think of a use case though.
> 
> Yes.
> 
> > > And it is wrong. Again, get_user_pages() can not succeed before
> > > vma_link(vma) makes is visible to find_vma(). And even if this
> > > worked, we must not insert the new bp before this mapping is
> > > visible to vma_prio_tree_foreach() for uprobe_unregister().
> > >
> >
> > Agree, we are wrong to do it before vma_link.
> >
> >
> > > Signed-off-by: Oleg Nesterov 
> > > ---
> > >  mm/mmap.c |3 ---
> > >  1 files changed, 0 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/mm/mmap.c b/mm/mmap.c
> > > index e5a4614..4fe2697 100644
> > > --- a/mm/mmap.c
> > > +++ b/mm/mmap.c
> > > @@ -2345,9 +2345,6 @@ int insert_vm_struct(struct mm_struct * mm, struct 
> > > vm_area_struct * vma)
> > >security_vm_enough_memory_mm(mm, vma_pages(vma)))
> > >   return -ENOMEM;
> > >
> > > - if (vma->vm_file && uprobe_mmap(vma))
> > > - return -EINVAL;
> > > -
> > >   vma_link(mm, vma, prev, rb_link, rb_parent);
> > >   return 0;
> > >  }
> >
> > Can we do something like:
> >
> > vma_link(mm, vma, prev, rb_link, rb_parent);
> >
> > if (vma->vm_file && uprobe_mmap(vma)) {
> > /* FIXME: dont know if calling unmap_region is fine here */
> > unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
> > return -EINVAL;
> > }
> 
> Yes, I was thinking about the possible fix, but afaics this is not
> enough. At least this needs vm_unacct_memory(). And I am not sure
> about unmap_region...
> 
> The main problem is that I have no idea how could I test the fix.
> Once again, currently this file can't be probed.
> 
> So. Can't we kill this obviously wrong and unneeded (at least currently)
> code? Currently uprobe_mmap/munmap logic is not correct (I'll try to send
> more fixes after I return from vacation), it would be nice to remove the
> callsite.
> 
> If somebody else will use insert_vm_struct() to mmap the can-be-uprobed
> file then yes, we will need to add uprobe_mmap() somewhere. But until
> then, the right fix is not clear and not testable.

Yes, for now your solution should be the way to go.
May be we should probably add a TODO/Fixme comment in insert_vm_struct
saying anybody trying to use insert_vm_struct to look at uprobe_mmap().

-- 
Thanks and Regards
Srikar

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


Re: [PATCH 5/5] uprobes: kill insert_vm_struct()->uprobe_mmap()

2012-07-13 Thread Srikar Dronamraju
* Oleg Nesterov  [2012-07-08 22:30:11]:

> Kill insert_vm_struct()->uprobe_mmap(). It is not needed, nobody
> except arch/ia64/kernel/perfmon.c uses insert_vm_struct(vma) with
> vma->vm_file != NULL.
> 
> And it is wrong. Again, get_user_pages() can not succeed before
> vma_link(vma) makes is visible to find_vma(). And even if this
> worked, we must not insert the new bp before this mapping is
> visible to vma_prio_tree_foreach() for uprobe_unregister().
> 
> Signed-off-by: Oleg Nesterov 

Acked-by: Srikar Dronamraju 

> ---
>  mm/mmap.c |3 ---
>  1 files changed, 0 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/mmap.c b/mm/mmap.c
> index e5a4614..4fe2697 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -2345,9 +2345,6 @@ int insert_vm_struct(struct mm_struct * mm, struct 
> vm_area_struct * vma)
>security_vm_enough_memory_mm(mm, vma_pages(vma)))
>   return -ENOMEM;
> 
> - if (vma->vm_file && uprobe_mmap(vma))
> - return -EINVAL;
> -
>   vma_link(mm, vma, prev, rb_link, rb_parent);
>   return 0;
>  }
> -- 
> 1.5.5.1
> 

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


Re: [PATCH 5/5] uprobes: kill insert_vm_struct()->uprobe_mmap()

2012-07-13 Thread Oleg Nesterov
On 07/13, Srikar Dronamraju wrote:
>
> * Oleg Nesterov  [2012-07-08 22:30:11]:
>
> > Kill insert_vm_struct()->uprobe_mmap(). It is not needed, nobody
> > except arch/ia64/kernel/perfmon.c uses insert_vm_struct(vma) with
> > vma->vm_file != NULL.
> >
>
> Right, but somebody else might start using this later.

Unlikely, I think...

> I cant think of a use case though.

Yes.

> > And it is wrong. Again, get_user_pages() can not succeed before
> > vma_link(vma) makes is visible to find_vma(). And even if this
> > worked, we must not insert the new bp before this mapping is
> > visible to vma_prio_tree_foreach() for uprobe_unregister().
> >
>
> Agree, we are wrong to do it before vma_link.
>
>
> > Signed-off-by: Oleg Nesterov 
> > ---
> >  mm/mmap.c |3 ---
> >  1 files changed, 0 insertions(+), 3 deletions(-)
> >
> > diff --git a/mm/mmap.c b/mm/mmap.c
> > index e5a4614..4fe2697 100644
> > --- a/mm/mmap.c
> > +++ b/mm/mmap.c
> > @@ -2345,9 +2345,6 @@ int insert_vm_struct(struct mm_struct * mm, struct 
> > vm_area_struct * vma)
> >  security_vm_enough_memory_mm(mm, vma_pages(vma)))
> > return -ENOMEM;
> >
> > -   if (vma->vm_file && uprobe_mmap(vma))
> > -   return -EINVAL;
> > -
> > vma_link(mm, vma, prev, rb_link, rb_parent);
> > return 0;
> >  }
>
> Can we do something like:
>
>   vma_link(mm, vma, prev, rb_link, rb_parent);
>
>   if (vma->vm_file && uprobe_mmap(vma)) {
>   /* FIXME: dont know if calling unmap_region is fine here */
>   unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
>   return -EINVAL;
>   }

Yes, I was thinking about the possible fix, but afaics this is not
enough. At least this needs vm_unacct_memory(). And I am not sure
about unmap_region...

The main problem is that I have no idea how could I test the fix.
Once again, currently this file can't be probed.

So. Can't we kill this obviously wrong and unneeded (at least currently)
code? Currently uprobe_mmap/munmap logic is not correct (I'll try to send
more fixes after I return from vacation), it would be nice to remove the
callsite.

If somebody else will use insert_vm_struct() to mmap the can-be-uprobed
file then yes, we will need to add uprobe_mmap() somewhere. But until
then, the right fix is not clear and not testable.

Oleg.

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


Re: [PATCH 5/5] uprobes: kill insert_vm_struct()->uprobe_mmap()

2012-07-13 Thread Srikar Dronamraju
* Oleg Nesterov  [2012-07-08 22:30:11]:

> Kill insert_vm_struct()->uprobe_mmap(). It is not needed, nobody
> except arch/ia64/kernel/perfmon.c uses insert_vm_struct(vma) with
> vma->vm_file != NULL.
> 

Right, but somebody else might start using this later.
I cant think of a use case though.

> And it is wrong. Again, get_user_pages() can not succeed before
> vma_link(vma) makes is visible to find_vma(). And even if this
> worked, we must not insert the new bp before this mapping is
> visible to vma_prio_tree_foreach() for uprobe_unregister().
> 

Agree, we are wrong to do it before vma_link.


> Signed-off-by: Oleg Nesterov 
> ---
>  mm/mmap.c |3 ---
>  1 files changed, 0 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/mmap.c b/mm/mmap.c
> index e5a4614..4fe2697 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -2345,9 +2345,6 @@ int insert_vm_struct(struct mm_struct * mm, struct 
> vm_area_struct * vma)
>security_vm_enough_memory_mm(mm, vma_pages(vma)))
>   return -ENOMEM;
> 
> - if (vma->vm_file && uprobe_mmap(vma))
> - return -EINVAL;
> -
>   vma_link(mm, vma, prev, rb_link, rb_parent);
>   return 0;
>  }

Can we do something like:

vma_link(mm, vma, prev, rb_link, rb_parent);

if (vma->vm_file && uprobe_mmap(vma)) {
/* FIXME: dont know if calling unmap_region is fine here */
unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end); 
return -EINVAL;
}

return 0;

}

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


Re: [PATCH 5/5] uprobes: kill insert_vm_struct()-uprobe_mmap()

2012-07-13 Thread Srikar Dronamraju
* Oleg Nesterov o...@redhat.com [2012-07-08 22:30:11]:

 Kill insert_vm_struct()-uprobe_mmap(). It is not needed, nobody
 except arch/ia64/kernel/perfmon.c uses insert_vm_struct(vma) with
 vma-vm_file != NULL.
 

Right, but somebody else might start using this later.
I cant think of a use case though.

 And it is wrong. Again, get_user_pages() can not succeed before
 vma_link(vma) makes is visible to find_vma(). And even if this
 worked, we must not insert the new bp before this mapping is
 visible to vma_prio_tree_foreach() for uprobe_unregister().
 

Agree, we are wrong to do it before vma_link.


 Signed-off-by: Oleg Nesterov o...@redhat.com
 ---
  mm/mmap.c |3 ---
  1 files changed, 0 insertions(+), 3 deletions(-)
 
 diff --git a/mm/mmap.c b/mm/mmap.c
 index e5a4614..4fe2697 100644
 --- a/mm/mmap.c
 +++ b/mm/mmap.c
 @@ -2345,9 +2345,6 @@ int insert_vm_struct(struct mm_struct * mm, struct 
 vm_area_struct * vma)
security_vm_enough_memory_mm(mm, vma_pages(vma)))
   return -ENOMEM;
 
 - if (vma-vm_file  uprobe_mmap(vma))
 - return -EINVAL;
 -
   vma_link(mm, vma, prev, rb_link, rb_parent);
   return 0;
  }

Can we do something like:

vma_link(mm, vma, prev, rb_link, rb_parent);

if (vma-vm_file  uprobe_mmap(vma)) {
/* FIXME: dont know if calling unmap_region is fine here */
unmap_region(mm, vma, prev, vma-vm_start, vma-vm_end); 
return -EINVAL;
}

return 0;

}

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


Re: [PATCH 5/5] uprobes: kill insert_vm_struct()-uprobe_mmap()

2012-07-13 Thread Oleg Nesterov
On 07/13, Srikar Dronamraju wrote:

 * Oleg Nesterov o...@redhat.com [2012-07-08 22:30:11]:

  Kill insert_vm_struct()-uprobe_mmap(). It is not needed, nobody
  except arch/ia64/kernel/perfmon.c uses insert_vm_struct(vma) with
  vma-vm_file != NULL.
 

 Right, but somebody else might start using this later.

Unlikely, I think...

 I cant think of a use case though.

Yes.

  And it is wrong. Again, get_user_pages() can not succeed before
  vma_link(vma) makes is visible to find_vma(). And even if this
  worked, we must not insert the new bp before this mapping is
  visible to vma_prio_tree_foreach() for uprobe_unregister().
 

 Agree, we are wrong to do it before vma_link.


  Signed-off-by: Oleg Nesterov o...@redhat.com
  ---
   mm/mmap.c |3 ---
   1 files changed, 0 insertions(+), 3 deletions(-)
 
  diff --git a/mm/mmap.c b/mm/mmap.c
  index e5a4614..4fe2697 100644
  --- a/mm/mmap.c
  +++ b/mm/mmap.c
  @@ -2345,9 +2345,6 @@ int insert_vm_struct(struct mm_struct * mm, struct 
  vm_area_struct * vma)
   security_vm_enough_memory_mm(mm, vma_pages(vma)))
  return -ENOMEM;
 
  -   if (vma-vm_file  uprobe_mmap(vma))
  -   return -EINVAL;
  -
  vma_link(mm, vma, prev, rb_link, rb_parent);
  return 0;
   }

 Can we do something like:

   vma_link(mm, vma, prev, rb_link, rb_parent);

   if (vma-vm_file  uprobe_mmap(vma)) {
   /* FIXME: dont know if calling unmap_region is fine here */
   unmap_region(mm, vma, prev, vma-vm_start, vma-vm_end);
   return -EINVAL;
   }

Yes, I was thinking about the possible fix, but afaics this is not
enough. At least this needs vm_unacct_memory(). And I am not sure
about unmap_region...

The main problem is that I have no idea how could I test the fix.
Once again, currently this file can't be probed.

So. Can't we kill this obviously wrong and unneeded (at least currently)
code? Currently uprobe_mmap/munmap logic is not correct (I'll try to send
more fixes after I return from vacation), it would be nice to remove the
callsite.

If somebody else will use insert_vm_struct() to mmap the can-be-uprobed
file then yes, we will need to add uprobe_mmap() somewhere. But until
then, the right fix is not clear and not testable.

Oleg.

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


Re: [PATCH 5/5] uprobes: kill insert_vm_struct()-uprobe_mmap()

2012-07-13 Thread Srikar Dronamraju
* Oleg Nesterov o...@redhat.com [2012-07-08 22:30:11]:

 Kill insert_vm_struct()-uprobe_mmap(). It is not needed, nobody
 except arch/ia64/kernel/perfmon.c uses insert_vm_struct(vma) with
 vma-vm_file != NULL.
 
 And it is wrong. Again, get_user_pages() can not succeed before
 vma_link(vma) makes is visible to find_vma(). And even if this
 worked, we must not insert the new bp before this mapping is
 visible to vma_prio_tree_foreach() for uprobe_unregister().
 
 Signed-off-by: Oleg Nesterov o...@redhat.com

Acked-by: Srikar Dronamraju sri...@linux.vnet.ibm.com

 ---
  mm/mmap.c |3 ---
  1 files changed, 0 insertions(+), 3 deletions(-)
 
 diff --git a/mm/mmap.c b/mm/mmap.c
 index e5a4614..4fe2697 100644
 --- a/mm/mmap.c
 +++ b/mm/mmap.c
 @@ -2345,9 +2345,6 @@ int insert_vm_struct(struct mm_struct * mm, struct 
 vm_area_struct * vma)
security_vm_enough_memory_mm(mm, vma_pages(vma)))
   return -ENOMEM;
 
 - if (vma-vm_file  uprobe_mmap(vma))
 - return -EINVAL;
 -
   vma_link(mm, vma, prev, rb_link, rb_parent);
   return 0;
  }
 -- 
 1.5.5.1
 

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


Re: [PATCH 5/5] uprobes: kill insert_vm_struct()-uprobe_mmap()

2012-07-13 Thread Srikar Dronamraju
* Oleg Nesterov o...@redhat.com [2012-07-13 15:29:16]:

 On 07/13, Srikar Dronamraju wrote:
 
  * Oleg Nesterov o...@redhat.com [2012-07-08 22:30:11]:
 
   Kill insert_vm_struct()-uprobe_mmap(). It is not needed, nobody
   except arch/ia64/kernel/perfmon.c uses insert_vm_struct(vma) with
   vma-vm_file != NULL.
  
 
  Right, but somebody else might start using this later.
 
 Unlikely, I think...
 
  I cant think of a use case though.
 
 Yes.
 
   And it is wrong. Again, get_user_pages() can not succeed before
   vma_link(vma) makes is visible to find_vma(). And even if this
   worked, we must not insert the new bp before this mapping is
   visible to vma_prio_tree_foreach() for uprobe_unregister().
  
 
  Agree, we are wrong to do it before vma_link.
 
 
   Signed-off-by: Oleg Nesterov o...@redhat.com
   ---
mm/mmap.c |3 ---
1 files changed, 0 insertions(+), 3 deletions(-)
  
   diff --git a/mm/mmap.c b/mm/mmap.c
   index e5a4614..4fe2697 100644
   --- a/mm/mmap.c
   +++ b/mm/mmap.c
   @@ -2345,9 +2345,6 @@ int insert_vm_struct(struct mm_struct * mm, struct 
   vm_area_struct * vma)
  security_vm_enough_memory_mm(mm, vma_pages(vma)))
 return -ENOMEM;
  
   - if (vma-vm_file  uprobe_mmap(vma))
   - return -EINVAL;
   -
 vma_link(mm, vma, prev, rb_link, rb_parent);
 return 0;
}
 
  Can we do something like:
 
  vma_link(mm, vma, prev, rb_link, rb_parent);
 
  if (vma-vm_file  uprobe_mmap(vma)) {
  /* FIXME: dont know if calling unmap_region is fine here */
  unmap_region(mm, vma, prev, vma-vm_start, vma-vm_end);
  return -EINVAL;
  }
 
 Yes, I was thinking about the possible fix, but afaics this is not
 enough. At least this needs vm_unacct_memory(). And I am not sure
 about unmap_region...
 
 The main problem is that I have no idea how could I test the fix.
 Once again, currently this file can't be probed.
 
 So. Can't we kill this obviously wrong and unneeded (at least currently)
 code? Currently uprobe_mmap/munmap logic is not correct (I'll try to send
 more fixes after I return from vacation), it would be nice to remove the
 callsite.
 
 If somebody else will use insert_vm_struct() to mmap the can-be-uprobed
 file then yes, we will need to add uprobe_mmap() somewhere. But until
 then, the right fix is not clear and not testable.

Yes, for now your solution should be the way to go.
May be we should probably add a TODO/Fixme comment in insert_vm_struct
saying anybody trying to use insert_vm_struct to look at uprobe_mmap().

-- 
Thanks and Regards
Srikar

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


[PATCH 5/5] uprobes: kill insert_vm_struct()->uprobe_mmap()

2012-07-08 Thread Oleg Nesterov
Kill insert_vm_struct()->uprobe_mmap(). It is not needed, nobody
except arch/ia64/kernel/perfmon.c uses insert_vm_struct(vma) with
vma->vm_file != NULL.

And it is wrong. Again, get_user_pages() can not succeed before
vma_link(vma) makes is visible to find_vma(). And even if this
worked, we must not insert the new bp before this mapping is
visible to vma_prio_tree_foreach() for uprobe_unregister().

Signed-off-by: Oleg Nesterov 
---
 mm/mmap.c |3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index e5a4614..4fe2697 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2345,9 +2345,6 @@ int insert_vm_struct(struct mm_struct * mm, struct 
vm_area_struct * vma)
 security_vm_enough_memory_mm(mm, vma_pages(vma)))
return -ENOMEM;
 
-   if (vma->vm_file && uprobe_mmap(vma))
-   return -EINVAL;
-
vma_link(mm, vma, prev, rb_link, rb_parent);
return 0;
 }
-- 
1.5.5.1

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


[PATCH 5/5] uprobes: kill insert_vm_struct()-uprobe_mmap()

2012-07-08 Thread Oleg Nesterov
Kill insert_vm_struct()-uprobe_mmap(). It is not needed, nobody
except arch/ia64/kernel/perfmon.c uses insert_vm_struct(vma) with
vma-vm_file != NULL.

And it is wrong. Again, get_user_pages() can not succeed before
vma_link(vma) makes is visible to find_vma(). And even if this
worked, we must not insert the new bp before this mapping is
visible to vma_prio_tree_foreach() for uprobe_unregister().

Signed-off-by: Oleg Nesterov o...@redhat.com
---
 mm/mmap.c |3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index e5a4614..4fe2697 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2345,9 +2345,6 @@ int insert_vm_struct(struct mm_struct * mm, struct 
vm_area_struct * vma)
 security_vm_enough_memory_mm(mm, vma_pages(vma)))
return -ENOMEM;
 
-   if (vma-vm_file  uprobe_mmap(vma))
-   return -EINVAL;
-
vma_link(mm, vma, prev, rb_link, rb_parent);
return 0;
 }
-- 
1.5.5.1

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