mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-09-22 09:34:56 +02:00
mm: do file ownership checks with the proper mount idmap
[ Upstream commite187bc02f8] Ever since idmapped mounts were introduced, inode ownership checks (for side-channel protection) in mincore() and madvise(MADV_PAGEOUT) were done against the nop_mnt_idmap, which completely ignores the file's mount's idmap. This results in odd edgecases like: 1) mount/bind-mount with an idmap userA:userB:1 2) userB runs an owner_or_capable() check on file that is owned by userA on-disk/in-memory, but owned by userB after idmap translation 3) owner_or_capable() mysteriously fails as the correct idmap wasn't supplied In the case of mincore/madvise MADV_PAGEOUT, this is usually benign, because file_permission(file, MAY_WRITE) will probably succeed, as it uses the proper idmap internally, but it does not need to be the case on e.g a 0444 file where even the owner itself doesn't have permissions to write to it. Since this is clearly not trivial to get right, introduce a file_owner_or_capable() that can carry the correct semantics, and switch the various users in mm to it. The issue was found by manual code inspection & an off-list discussion with Jan Kara. Link: https://lore.kernel.org/20260625153853.913949-1-pfalcato@suse.de Fixes:9caccd4154("fs: introduce MOUNT_ATTR_IDMAP") Signed-off-by: Pedro Falcato <pfalcato@suse.de> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Christian Brauner (Amutable) <brauner@kernel.org> Acked-by: David Hildenbrand (Arm) <david@kernel.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Jann Horn <jannh@google.com> Cc: Liam R. Howlett <liam@infradead.org> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Vlastimil Babka <vbabka@kernel.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> [ dropped const from file_owner_or_capable()'s parameter since 6.6's file_mnt_idmap() takes a non-const struct file * ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
e2baf8ea13
commit
744b23aa43
@@ -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
|
||||
|
||||
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
+1
-2
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user