FAILED: patch "[PATCH] mm: do file ownership checks with the proper mount idmap" failed to apply to 5.15-stable tree
Subsystems (6)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x e187bc02f8fa4226d62814592cf064ee4557c470
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026071536-chirpy-unmindful-fd3a@gregkh' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From e187bc02f8fa4226d62814592cf064ee4557c470 Mon Sep 17 00:00:00 2001
From: Pedro Falcato <[email protected]>
Date: Thu, 25 Jun 2026 16:38:53 +0100
Subject: [PATCH] mm: do file ownership checks with the proper mount idmap
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.
include/linux/fs.h +5 -0
@@ -2444,6 +2444,11 @@ static inline struct mnt_idmap *file_mnt_idmap(const struct file *file)return mnt_idmap (file->f_path.mnt); } +static inline bool file_owner_or_capable (const 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
mm/filemap.c +1 -1
@@ -4704,7 +4704,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 ; }
mm/madvise.c +1 -2
@@ -336,8 +336,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 ; }
mm/mincore.c +1 -2
@@ -227,8 +227,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 ; }
Sasha Levin
maintainerPATCH 1/1 mm: do file ownership checks with the proper mount idmap
From: Pedro Falcato <[email protected]>
[ Upstream commit e187bc02f8fa4226d62814592cf064ee4557c470 ]
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.
--- include/linux/fs.h | 5 +++++ mm/madvise.c | 3 +-- mm/mincore.c | 3 +-- 3 files changed, 7 insertions(+), 4 deletions(-)
include/linux/fs.h +5 -0
@@ -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
mm/madvise.c +1 -2
@@ -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 ; }
mm/mincore.c +1 -2
@@ -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 ; }
Signature · 1 line
2.53.0