On 10/22/24 22:40, Lorenzo Stoakes wrote: > After an attempted mmap() fails, we are no longer in a situation where we > can safely interact with VMA hooks. This is currently not enforced, meaning > that we need complicated handling to ensure we do not incorrectly call > these hooks. > > We can avoid the whole issue by treating the VMA as suspect the moment that > the file->f_ops->mmap() function reports an error by replacing whatever VMA > operations were installed with a dummy empty set of VMA operations. > > We do so through a new helper function internal to mm - mmap_file() - which > is both more logically named than the existing call_mmap() function and > correctly isolates handling of the vm_op reassignment to mm. > > All the existing invocations of call_mmap() outside of mm are ultimately > nested within the call_mmap() from mm, which we now replace. > > It is therefore safe to leave call_mmap() in place as a convenience > function (and to avoid churn). The invokers are: > > ovl_file_operations -> mmap -> ovl_mmap() -> backing_file_mmap() > coda_file_operations -> mmap -> coda_file_mmap() > shm_file_operations -> shm_mmap() > shm_file_operations_huge -> shm_mmap() > dma_buf_fops -> dma_buf_mmap_internal -> i915_dmabuf_ops > -> i915_gem_dmabuf_mmap() > > None of these callers interact with vm_ops or mappings in a problematic way > on error, quickly exiting out. > > 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: Vlastimil Babka <vbabka@xxxxxxx>