By adding this hook we enable procfs implementations to be able to use the
.mmap_prepare hook rather than the deprecated .mmap one.

We treat this as if it were any other nested mmap hook and utilise the
.mmap_prepare compatibility layer if necessary.

Signed-off-by: Lorenzo Stoakes <[email protected]>
---
 fs/proc/inode.c         | 12 +++++++++---
 include/linux/proc_fs.h |  1 +
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 129490151be1..609abbc84bf4 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -414,9 +414,15 @@ static long proc_reg_compat_ioctl(struct file *file, 
unsigned int cmd, unsigned
 
 static int pde_mmap(struct proc_dir_entry *pde, struct file *file, struct 
vm_area_struct *vma)
 {
-       __auto_type mmap = pde->proc_ops->proc_mmap;
-       if (mmap)
-               return mmap(file, vma);
+       const struct file_operations f_op = {
+               .mmap = pde->proc_ops->proc_mmap,
+               .mmap_prepare = pde->proc_ops->proc_mmap_prepare,
+       };
+
+       if (f_op.mmap)
+               return f_op.mmap(file, vma);
+       else if (f_op.mmap_prepare)
+               return __compat_vma_mmap_prepare(&f_op, file, vma);
        return -EIO;
 }
 
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index f139377f4b31..e5f65ebd62b8 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -47,6 +47,7 @@ struct proc_ops {
        long    (*proc_compat_ioctl)(struct file *, unsigned int, unsigned 
long);
 #endif
        int     (*proc_mmap)(struct file *, struct vm_area_struct *);
+       int     (*proc_mmap_prepare)(struct vm_area_desc *);
        unsigned long (*proc_get_unmapped_area)(struct file *, unsigned long, 
unsigned long, unsigned long, unsigned long);
 } __randomize_layout;
 
-- 
2.51.0


Reply via email to