summaryrefslogtreecommitdiffstats
path: root/mm/filemap.c
diff options
context:
space:
mode:
authorTrond Myklebust <trond.myklebust@hammerspace.com>2024-09-13 22:04:18 +0200
committerChristian Brauner <brauner@kernel.org>2024-10-02 07:52:12 +0200
commit9d926f10b7ff4300a5dc36ecc52d061911d027d8 (patch)
treeebad93161c3946f29a55054347da3091ce60a667 /mm/filemap.c
parentMerge patch series "Introduce tracepoint for hugetlbfs" (diff)
downloadlinux-9d926f10b7ff4300a5dc36ecc52d061911d027d8.tar.xz
linux-9d926f10b7ff4300a5dc36ecc52d061911d027d8.zip
filemap: filemap_read() should check that the offset is positive or zero
We do check that the read offset is less than the filesystem limit, however for good measure we should also check that it is positive or zero, and return EINVAL if that is not the case. Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Link: https://lore.kernel.org/r/482ee0b8a30b62324adb9f7c551a99926f037393.1726257832.git.trond.myklebust@hammerspace.com Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'mm/filemap.c')
-rw-r--r--mm/filemap.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/mm/filemap.c b/mm/filemap.c
index 36d22968be9a..82aa94d2b709 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2620,6 +2620,8 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter,
loff_t isize, end_offset;
loff_t last_pos = ra->prev_pos;
+ if (unlikely(iocb->ki_pos < 0))
+ return -EINVAL;
if (unlikely(iocb->ki_pos >= inode->i_sb->s_maxbytes))
return 0;
if (unlikely(!iov_iter_count(iter)))