On Tue, Oct 22, 2024 at 11:15:10PM +0200, Jann Horn wrote: > On Tue, Oct 22, 2024 at 10:41 PM Lorenzo Stoakes > <lorenzo.stoakes@xxxxxxxxxx> wrote: > > Incorrect invocation of VMA callbacks when the VMA is no longer in a > > consistent state is bug prone and risky to perform. > > > > With regards to the important vm_ops->close() callback We have gone to > > great lengths to try to track whether or not we ought to close VMAs. > > > > Rather than doing so and risking making a mistake somewhere, instead > > unconditionally close and reset vma->vm_ops to an empty dummy operations > > set with a NULL .close operator. > > > > We introduce a new function to do so - vma_close() - and simplify existing > > vms logic which tracked whether we needed to close or not. > > > > This simplifies the logic, avoids incorrect double-calling of the .close() > > callback and allows us to update error paths to simply call vma_close() > > unconditionally - making VMA closure idempotent. > > > > Reported-by: Jann Horn <jannh@xxxxxxxxxx> > > Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") > > Cc: stable <stable@xxxxxxxxxx> > > Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx> > > Reviewed-by: Jann Horn <jannh@xxxxxxxxxx> Thanks! > > [...] > > diff --git a/mm/vma.h b/mm/vma.h > > index 55457cb68200..75558b5e9c8c 100644 > > --- a/mm/vma.h > > +++ b/mm/vma.h > > @@ -42,7 +42,6 @@ struct vma_munmap_struct { > > int vma_count; /* Number of vmas that will be removed */ > > bool unlock; /* Unlock after the munmap */ > > bool clear_ptes; /* If there are outstanding PTE to be cleared */ > > - bool closed_vm_ops; /* call_mmap() was encountered, so vmas may be closed */ > > /* 1 byte hole */ > > nit: outdated comment, this hole is 2 bytes now Ack, will update. > > > > > unsigned long nr_pages; /* Number of pages being removed */ > > unsigned long locked_vm; /* Number of locked pages */