diff --git a/include/linux/fs.h b/include/linux/fs.h index 5a897ee50f29..e6b2e2749e37 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2481,6 +2481,11 @@ static inline struct mnt_idmap *file_mnt_idmap(struct file *file) return mnt_idmap(file->f_path.mnt); } +static inline bool file_owner_or_capable(struct file *file) +{ + return inode_owner_or_capable(file_mnt_idmap(file), file_inode(file)); +} + /** * is_idmapped_mnt - check whether a mount is mapped * @mnt: the mount to check diff --git a/mm/filemap.c b/mm/filemap.c index 7416868d0449..5a340cad44ed 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -4314,7 +4314,7 @@ static inline bool can_do_cachestat(struct file *f) { if (f->f_mode & FMODE_WRITE) return true; - if (inode_owner_or_capable(file_mnt_idmap(f), file_inode(f))) + if (file_owner_or_capable(f)) return true; return file_permission(f, MAY_WRITE) == 0; } diff --git a/mm/madvise.c b/mm/madvise.c index 3d6370d3199f..73ea053c9003 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -334,8 +334,7 @@ static inline bool can_do_file_pageout(struct vm_area_struct *vma) * otherwise we'd be including shared non-exclusive mappings, which * opens a side channel. */ - return inode_owner_or_capable(&nop_mnt_idmap, - file_inode(vma->vm_file)) || + return file_owner_or_capable(vma->vm_file) || file_permission(vma->vm_file, MAY_WRITE) == 0; } diff --git a/mm/mincore.c b/mm/mincore.c index dad3622cc963..2a55eed792b6 100644 --- a/mm/mincore.c +++ b/mm/mincore.c @@ -167,8 +167,7 @@ static inline bool can_do_mincore(struct vm_area_struct *vma) * for writing; otherwise we'd be including shared non-exclusive * mappings, which opens a side channel. */ - return inode_owner_or_capable(&nop_mnt_idmap, - file_inode(vma->vm_file)) || + return file_owner_or_capable(vma->vm_file) || file_permission(vma->vm_file, MAY_WRITE) == 0; }