Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FC574746C5; Tue, 21 Jul 2026 21:05:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784667914; cv=none; b=m+VXzpMJQlFaKrHzdkOIe1A5N+OwqA5gmQuTXT+mRlB3cx7n/v5yH2nBlczXlAeJ1naOnlvkxPQqgHzcp+V1tsbthGjnKQ58TyuUrmXNksppiQtrgVgpvOoY+HxJuT7RtCCZcg1CXd92+cyYJWeiOWVLbrnkYhrhM6lxPNQcGnY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784667914; c=relaxed/simple; bh=HiscL/fYs6qJYakHSYWxcYpQxfpR2WfY033py4Gey5s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b+Wh4t+WFB3Tj2ZIHCAgQp9nYriIbboEmI9GVYKvwRKIL4gELagDNjO2/HjLmxZsYH44qlPBiFzM3eOS9I23UrhqBYZRnZMtWkIgpU6ozzoxrQ/CZdc5YgVTSOOoHLRbcLW+wCKq9F8/aodxltJUl4SXUn9+T3gHCIrSzhHpCic= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=D01iPVf3; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="D01iPVf3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E9FE1F00A3D; Tue, 21 Jul 2026 21:05:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784667911; bh=7jU6D42yZcwOfexR/NNjttbZ7K54G8x41YfHAEn5sEY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=D01iPVf3kB8V2LUDWCI4u+LVl54l5VI89B9bOJX72W3x7j1sYtK5C7/uAYV/b9YMR jXS45ng72RRxuut7n98fY8xBnat9tE0HSp/mjQ2guqfBCPGyOUBHCOXahNGdIRvkKn lNj6uNo8dhU8b8f5egP+ivj7VD9cCFqQjIKj78xk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Pedro Falcato , Jan Kara , "Christian Brauner (Amutable)" , "David Hildenbrand (Arm)" , Al Viro , Jann Horn , "Liam R. Howlett" , "Matthew Wilcox (Oracle)" , Vlastimil Babka , Andrew Morton , Sasha Levin Subject: [PATCH 6.6 1238/1266] mm: do file ownership checks with the proper mount idmap Date: Tue, 21 Jul 2026 17:27:55 +0200 Message-ID: <20260721152509.517316602@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152441.786066624@linuxfoundation.org> References: <20260721152441.786066624@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pedro Falcato [ 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. Link: https://lore.kernel.org/20260625153853.913949-1-pfalcato@suse.de Fixes: 9caccd41541a ("fs: introduce MOUNT_ATTR_IDMAP") Signed-off-by: Pedro Falcato Reviewed-by: Jan Kara Reviewed-by: Christian Brauner (Amutable) Acked-by: David Hildenbrand (Arm) Cc: Al Viro Cc: Jann Horn Cc: Liam R. Howlett Cc: Matthew Wilcox (Oracle) Cc: Vlastimil Babka Cc: Signed-off-by: Andrew Morton [ 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 Signed-off-by: Greg Kroah-Hartman --- include/linux/fs.h | 5 +++++ mm/filemap.c | 2 +- mm/madvise.c | 3 +-- mm/mincore.c | 3 +-- 4 files changed, 8 insertions(+), 5 deletions(-) --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2481,6 +2481,11 @@ static inline struct mnt_idmap *file_mnt 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 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -4314,7 +4314,7 @@ static inline bool can_do_cachestat(stru { 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; } --- a/mm/madvise.c +++ b/mm/madvise.c @@ -334,8 +334,7 @@ static inline bool can_do_file_pageout(s * 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; } --- a/mm/mincore.c +++ b/mm/mincore.c @@ -167,8 +167,7 @@ static inline bool can_do_mincore(struct * 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; }