Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/vma: remove __vma_check_mmap_hook()

Commit c50ca15dd496 ("mm: add vm_ops->mapped hook") introduced
__vma_check_mmap_hook() in order to assert that a driver doesn't
incorrectly implement both an f_op->mmap() and a vm_ops->mapped hook, the
latter of which would not ultimately get invoked.

However, this did not correctly account for stacked drivers (or drivers
that otherwise use the compatibility layer) which might recursively call
an mmap_prepare hook via the compatibility layer.

Thus the nested mmap_prepare() invocation might result in a VMA which has
vm_ops->mapped set with an overlaying mmap() hook, causing the
__vma_check_mmap_hook() to fail in vfs_mmap(), wrongly failing the
operation.

This patch resolves this by simply removing the check, as we can't be
certain that an mmap() hook doesn't at some point invoke the compatibility
layer, and it's not worth trying to track it.

Link: https://lore.kernel.org/20260413105713.92625-1-ljs@kernel.org
Fixes: c50ca15dd496 ("mm: add vm_ops->mapped hook")
Reported-by: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Closes: https://lore.kernel.org/all/adx2ws5z0NMIe5Yj@shinmob/
Signed-off-by: Lorenzo Stoakes <ljs@kernel.org>
Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Tested-by: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes and committed by
Andrew Morton
3d3544a6 3bac0116

+1 -18
+1 -8
include/linux/fs.h
··· 2062 2062 const struct vm_area_struct *vma); 2063 2063 int __compat_vma_mmap(struct vm_area_desc *desc, struct vm_area_struct *vma); 2064 2064 int compat_vma_mmap(struct file *file, struct vm_area_struct *vma); 2065 - int __vma_check_mmap_hook(struct vm_area_struct *vma); 2066 2065 2067 2066 static inline int vfs_mmap(struct file *file, struct vm_area_struct *vma) 2068 2067 { 2069 - int err; 2070 - 2071 2068 if (file->f_op->mmap_prepare) 2072 2069 return compat_vma_mmap(file, vma); 2073 2070 2074 - err = file->f_op->mmap(file, vma); 2075 - if (err) 2076 - return err; 2077 - 2078 - return __vma_check_mmap_hook(vma); 2071 + return file->f_op->mmap(file, vma); 2079 2072 } 2080 2073 2081 2074 static inline int vfs_mmap_prepare(struct file *file, struct vm_area_desc *desc)
-10
mm/util.c
··· 1281 1281 } 1282 1282 EXPORT_SYMBOL(compat_vma_mmap); 1283 1283 1284 - int __vma_check_mmap_hook(struct vm_area_struct *vma) 1285 - { 1286 - /* vm_ops->mapped is not valid if mmap() is specified. */ 1287 - if (vma->vm_ops && WARN_ON_ONCE(vma->vm_ops->mapped)) 1288 - return -EINVAL; 1289 - 1290 - return 0; 1291 - } 1292 - EXPORT_SYMBOL(__vma_check_mmap_hook); 1293 - 1294 1284 static void set_ps_flags(struct page_snapshot *ps, const struct folio *folio, 1295 1285 const struct page *page) 1296 1286 {