Message ID | 20240820235730.2852400-11-Liam.Howlett@oracle.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Avoid MAP_FIXED gap exposure | expand |
On Tue, Aug 20, 2024 at 07:57:19PM GMT, Liam R. Howlett wrote: > From: "Liam R. Howlett" <Liam.Howlett@Oracle.com> > > Adding support for a NULL vma means the init_vma_munmap() can be > initialized for a less error-prone process when calling > vms_complete_munmap_vmas() later on. > > Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com> Thought I already R-b'd this :) Anyway, Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> > --- > mm/mmap.c | 2 +- > mm/vma.h | 11 ++++++++--- > 2 files changed, 9 insertions(+), 4 deletions(-) > > diff --git a/mm/mmap.c b/mm/mmap.c > index e7e6bf09b558..2b7445a002dc 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -1393,11 +1393,11 @@ unsigned long mmap_region(struct file *file, unsigned long addr, > > /* Find the first overlapping VMA */ > vma = vma_find(&vmi, end); > + init_vma_munmap(&vms, &vmi, vma, addr, end, uf, /* unlock = */ false); > if (vma) { > mt_init_flags(&mt_detach, vmi.mas.tree->ma_flags & MT_FLAGS_LOCK_MASK); > mt_on_stack(mt_detach); > mas_init(&mas_detach, &mt_detach, /* addr = */ 0); > - init_vma_munmap(&vms, &vmi, vma, addr, end, uf, /* unlock = */ false); > /* Prepare to unmap any existing mapping in the area */ > if (vms_gather_munmap_vmas(&vms, &mas_detach)) > return -ENOMEM; > diff --git a/mm/vma.h b/mm/vma.h > index e78b24d1cf83..0e214bbf443e 100644 > --- a/mm/vma.h > +++ b/mm/vma.h > @@ -95,9 +95,14 @@ static inline void init_vma_munmap(struct vma_munmap_struct *vms, > { > vms->vmi = vmi; > vms->vma = vma; > - vms->mm = vma->vm_mm; > - vms->start = start; > - vms->end = end; > + if (vma) { > + vms->mm = vma->vm_mm; > + vms->start = start; > + vms->end = end; > + } else { > + vms->mm = NULL; > + vms->start = vms->end = 0; > + } > vms->unlock = unlock; > vms->uf = uf; > vms->vma_count = 0; > -- > 2.43.0 >
* Lorenzo Stoakes <lorenzo.stoakes@oracle.com> [240821 06:07]: > On Tue, Aug 20, 2024 at 07:57:19PM GMT, Liam R. Howlett wrote: > > From: "Liam R. Howlett" <Liam.Howlett@Oracle.com> > > > > Adding support for a NULL vma means the init_vma_munmap() can be > > initialized for a less error-prone process when calling > > vms_complete_munmap_vmas() later on. > > > > Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com> > > Thought I already R-b'd this :) Anyway, > > Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> I probably lost it in my porting of patches somehow. Thanks > > > --- > > mm/mmap.c | 2 +- > > mm/vma.h | 11 ++++++++--- > > 2 files changed, 9 insertions(+), 4 deletions(-) > > > > diff --git a/mm/mmap.c b/mm/mmap.c > > index e7e6bf09b558..2b7445a002dc 100644 > > --- a/mm/mmap.c > > +++ b/mm/mmap.c > > @@ -1393,11 +1393,11 @@ unsigned long mmap_region(struct file *file, unsigned long addr, > > > > /* Find the first overlapping VMA */ > > vma = vma_find(&vmi, end); > > + init_vma_munmap(&vms, &vmi, vma, addr, end, uf, /* unlock = */ false); > > if (vma) { > > mt_init_flags(&mt_detach, vmi.mas.tree->ma_flags & MT_FLAGS_LOCK_MASK); > > mt_on_stack(mt_detach); > > mas_init(&mas_detach, &mt_detach, /* addr = */ 0); > > - init_vma_munmap(&vms, &vmi, vma, addr, end, uf, /* unlock = */ false); > > /* Prepare to unmap any existing mapping in the area */ > > if (vms_gather_munmap_vmas(&vms, &mas_detach)) > > return -ENOMEM; > > diff --git a/mm/vma.h b/mm/vma.h > > index e78b24d1cf83..0e214bbf443e 100644 > > --- a/mm/vma.h > > +++ b/mm/vma.h > > @@ -95,9 +95,14 @@ static inline void init_vma_munmap(struct vma_munmap_struct *vms, > > { > > vms->vmi = vmi; > > vms->vma = vma; > > - vms->mm = vma->vm_mm; > > - vms->start = start; > > - vms->end = end; > > + if (vma) { > > + vms->mm = vma->vm_mm; > > + vms->start = start; > > + vms->end = end; > > + } else { > > + vms->mm = NULL; > > + vms->start = vms->end = 0; > > + } > > vms->unlock = unlock; > > vms->uf = uf; > > vms->vma_count = 0; > > -- > > 2.43.0 > >
diff --git a/mm/mmap.c b/mm/mmap.c index e7e6bf09b558..2b7445a002dc 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1393,11 +1393,11 @@ unsigned long mmap_region(struct file *file, unsigned long addr, /* Find the first overlapping VMA */ vma = vma_find(&vmi, end); + init_vma_munmap(&vms, &vmi, vma, addr, end, uf, /* unlock = */ false); if (vma) { mt_init_flags(&mt_detach, vmi.mas.tree->ma_flags & MT_FLAGS_LOCK_MASK); mt_on_stack(mt_detach); mas_init(&mas_detach, &mt_detach, /* addr = */ 0); - init_vma_munmap(&vms, &vmi, vma, addr, end, uf, /* unlock = */ false); /* Prepare to unmap any existing mapping in the area */ if (vms_gather_munmap_vmas(&vms, &mas_detach)) return -ENOMEM; diff --git a/mm/vma.h b/mm/vma.h index e78b24d1cf83..0e214bbf443e 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -95,9 +95,14 @@ static inline void init_vma_munmap(struct vma_munmap_struct *vms, { vms->vmi = vmi; vms->vma = vma; - vms->mm = vma->vm_mm; - vms->start = start; - vms->end = end; + if (vma) { + vms->mm = vma->vm_mm; + vms->start = start; + vms->end = end; + } else { + vms->mm = NULL; + vms->start = vms->end = 0; + } vms->unlock = unlock; vms->uf = uf; vms->vma_count = 0;