By adding these hooks we enable procfs implementations to be able to use the .mmap_prepare, .mmap_complete hooks rather than the deprecated .mmap hook. 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 <lorenzo.stoakes@xxxxxxxxxx> --- fs/proc/inode.c | 13 ++++++++++--- include/linux/proc_fs.h | 5 +++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/fs/proc/inode.c b/fs/proc/inode.c index 129490151be1..d031267e2e4a 100644 --- a/fs/proc/inode.c +++ b/fs/proc/inode.c @@ -414,9 +414,16 @@ 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, + .mmap_complete = pde->proc_ops->proc_mmap_complete, + }; + + 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..3573192f813d 100644 --- a/include/linux/proc_fs.h +++ b/include/linux/proc_fs.h @@ -47,6 +47,11 @@ 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 *); + int (*proc_mmap_complete)(struct file *, struct vm_area_struct *, + const void *context); + void (*proc_mmap_abort)(const struct file *, const void *vm_private_data, + const void *context); unsigned long (*proc_get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); } __randomize_layout; -- 2.51.0