diff options
| -rw-r--r-- | mm/filemap.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/mm/filemap.c b/mm/filemap.c index dc83baab85a1..05adf0392625 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -4384,6 +4384,20 @@ resched: } /* + * See mincore: reveal pagecache information only for files + * that the calling process has write access to, or could (if + * tried) open for writing. + */ +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))) + return true; + return file_permission(f, MAY_WRITE) == 0; +} + +/* * The cachestat(2) system call. * * cachestat() returns the page cache statistics of a file in the @@ -4442,6 +4456,11 @@ SYSCALL_DEFINE4(cachestat, unsigned int, fd, return -EOPNOTSUPP; } + if (!can_do_cachestat(fd_file(f))) { + fdput(f); + return -EPERM; + } + if (flags != 0) { fdput(f); return -EINVAL; |
