Skip to content

Commit 86ca59c

Browse files
author
Rafael Aquini
committed
cachestat: fix page cache statistics permission checking
JIRA: https://issues.redhat.com/browse/RHEL-84184 JIRA: https://issues.redhat.com/browse/RHEL-78989 CVE: CVE-2025-21691 Conflicts: * minor differences on the 2nd hunk due to RHEL-9 missing upstream commit 65c8941 ("convert cachestat(2)") that transposes fdput() with copy_to_user(), as well as missing commit 1da91ea ("introduce fd_file(), convert all accessors to it."). These changes, however are irrelevant for this backport work. This patch is a backport of the following upstream commit: commit 5f53766 Author: Linus Torvalds <torvalds@linux-foundation.org> Date: Tue Jan 21 09:27:22 2025 -0800 cachestat: fix page cache statistics permission checking When the 'cachestat()' system call was added in commit cf264e1 ("cachestat: implement cachestat syscall"), it was meant to be a much more convenient (and performant) version of mincore() that didn't need mapping things into the user virtual address space in order to work. But it ended up missing the "check for writability or ownership" fix for mincore(), done in commit 134fca9 ("mm/mincore.c: make mincore() more conservative"). This just adds equivalent logic to 'cachestat()', modified for the file context (rather than vma). Reported-by: Sudheendra Raghav Neela <sneela@tugraz.at> Fixes: cf264e1 ("cachestat: implement cachestat syscall") Tested-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Nhat Pham <nphamcs@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Rafael Aquini <raquini@redhat.com>
1 parent e4205cc commit 86ca59c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

mm/filemap.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4212,6 +4212,20 @@ static void filemap_cachestat(struct address_space *mapping,
42124212
rcu_read_unlock();
42134213
}
42144214

4215+
/*
4216+
* See mincore: reveal pagecache information only for files
4217+
* that the calling process has write access to, or could (if
4218+
* tried) open for writing.
4219+
*/
4220+
static inline bool can_do_cachestat(struct file *f)
4221+
{
4222+
if (f->f_mode & FMODE_WRITE)
4223+
return true;
4224+
if (inode_owner_or_capable(file_mnt_idmap(f), file_inode(f)))
4225+
return true;
4226+
return file_permission(f, MAY_WRITE) == 0;
4227+
}
4228+
42154229
/*
42164230
* The cachestat(2) system call.
42174231
*
@@ -4271,6 +4285,11 @@ SYSCALL_DEFINE4(cachestat, unsigned int, fd,
42714285
return -EOPNOTSUPP;
42724286
}
42734287

4288+
if (!can_do_cachestat(f.file)) {
4289+
fdput(f);
4290+
return -EPERM;
4291+
}
4292+
42744293
if (flags != 0) {
42754294
fdput(f);
42764295
return -EINVAL;

0 commit comments

Comments
 (0)