diff --git a/include/linux/fs.h b/include/linux/fs.h index 72a956d243c2..5b85d4e73219 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2743,6 +2743,11 @@ static inline struct user_namespace *file_mnt_user_ns(struct file *file) return mnt_user_ns(file->f_path.mnt); } +static inline bool file_owner_or_capable(struct file *file) +{ + return inode_owner_or_capable(file_mnt_user_ns(file), file_inode(file)); +} + /** * is_idmapped_mnt - check whether a mount is mapped * @mnt: the mount to check diff --git a/mm/madvise.c b/mm/madvise.c index ef9382f77624..367220e1fe52 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -544,8 +544,7 @@ static inline bool can_do_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(&init_user_ns, - 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 9122676b54d6..889d84477a77 100644 --- a/mm/mincore.c +++ b/mm/mincore.c @@ -166,8 +166,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(&init_user_ns, - file_inode(vma->vm_file)) || + return file_owner_or_capable(vma->vm_file) || file_permission(vma->vm_file, MAY_WRITE) == 0; }