iomap: Fix overflow in iomap_page_mkwrite
Subsystems (2)
PATCH 1/1 iomap: Fix overflow in iomap_page_mkwrite
On architectures where ssize_t is wider than pgoff_t, the expression ((page->index + 1) << PAGE_SHIFT) can overflow. Rewrite to use the page offset, which we already compute here anyway.
--- fs/iomap/buffered-io.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/iomap/buffered-io.c +3 -4
@@ -1040,20 +1040,19 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops)lock_page (page); size =i_size_read (inode); -if ((page->mapping != inode->i_mapping) || - (page_offset (page) > size)) { + offset =page_offset (page); +if (page->mapping != inode->i_mapping || offset > size) {/* We overload EFAULT to mean page got truncated */ ret = -EFAULT ; goto out_unlock; }/* page is wholly or partially inside EOF */ -if (((page->index +1 ) <<PAGE_SHIFT ) > size) +if (offset > size -PAGE_SIZE ) length =offset_in_page (size);else length =PAGE_SIZE ; - offset =page_offset (page);while (length >0 ) { ret = iomap_apply(inode, offset, length, IOMAP_WRITE | IOMAP_FAULT, ops, page,
Signature · 1 line
2.20.1
Quoted 1 line · Andreas Gruenbacher
On architectures where
ssize_tis wider thanpgoff_t, the expression
ssize_t? But you're changing @offset, which is loff_t. I'm confused.
Also, which architectures are you talking about here?
--D
Quoted 39 lines
((
page->index+ 1) <<PAGE_SHIFT) can overflow. Rewrite to use the page offset, which we already compute here anyway.Signed-off-by Andreas Gruenbacher <[email protected]>--- fs/iomap/buffered-io.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)fs/iomap/buffered-io.c +3
-4@@ -1040,20 +1040,19 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops)lock_page (page); size =i_size_read (inode); -if ((page->mapping != inode->i_mapping) || - (page_offset (page) > size)) { + offset =page_offset (page); +if (page->mapping != inode->i_mapping || offset > size) {/* We overload EFAULT to mean page got truncated */ ret = -EFAULT ; goto out_unlock; }/* page is wholly or partially inside EOF */ -if (((page->index +1 ) <<PAGE_SHIFT ) > size) +if (offset > size -PAGE_SIZE ) length =offset_in_page (size);else length =PAGE_SIZE ; - offset =page_offset (page);while (length >0 ) { ret = iomap_apply(inode, offset, length, IOMAP_WRITE | IOMAP_FAULT, ops, page,Signature · 1 line
2.20.1
Quoted 4 lines · Darrick J. Wong
Quoted 1 line · Andreas Gruenbacher
On architectures where
ssize_tis wider thanpgoff_t, the expression
ssize_t? But you're changing @offset, which isloff_t. I'm confused.
Oops, should have been loff_t instead of ssize_t.
Quoted 1 line
Also, which architectures are you talking about here?
From the kernel headers:
#define pgoff_t unsigned long
typedef long long __kernel_loff_t;
typedef __kernel_loff_t loff_t;
So for example, sizeof(loff_t) > sizeof(pgoff_t) on x86.
Thanks,
Andreas
Darrick J. Wong
Reviewed-byQuoted 7 lines · Andreas Gruenbacher
Quoted 4 lines · Darrick J. Wong
Quoted 1 line · Andreas Gruenbacher
On architectures where
ssize_tis wider thanpgoff_t, the expression
ssize_t? But you're changing @offset, which isloff_t. I'm confused.Oops, should have been
loff_tinstead ofssize_t.
I'll fix it on commit.
Quoted 9 lines
Quoted 1 line
Also, which architectures are you talking about here?
From the kernel headers:
#define
pgoff_tunsigned long
typedef long long__kernel_loff_t;
typedef__kernel_loff_tloff_t;So for example,
sizeof(loff_t)>sizeof(pgoff_t)on x86.
Ok, that's what I thought.
--D
Quoted 3 lines
Thanks,
Andreas
Quoted 1 line · Darrick J. Wong
I'll fix it on commit.
Thanks.
So now the one remaining issue I have with those two functions is why we check for (offset > size) instead of (offset >= size) in
if (page->mapping != inode->i_mapping || offset > size)
When (offset == size), we're clearly outside the page, and so we should fail?
Thanks,
Andreas
Quoted 5 lines · Andreas Gruenbacher
On architectures where
ssize_tis wider thanpgoff_t, the expression ((page->index+ 1) <<PAGE_SHIFT) can overflow. Rewrite to use the page offset, which we already compute here anyway.Signed-off-by Andreas Gruenbacher <[email protected]>
Looks good except for the ssize_t vs loff_t in the changelog: