f2fs: fix potential overflow
authorChao Yu <yuchao0@huawei.com>
Thu, 7 Nov 2019 09:29:00 +0000 (17:29 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 23 Jan 2020 07:19:37 +0000 (08:19 +0100)
commit 1f0d5c911b64165c9754139a26c8c2fad352c132 upstream.

We expect 64-bit calculation result from below statement, however
in 32-bit machine, looped left shift operation on pgoff_t type
variable may cause overflow issue, fix it by forcing type cast.

page->index << PAGE_SHIFT;

Fixes: 26de9b117130 ("f2fs: avoid unnecessary updating inode during fsync")
Fixes: 0a2aa8fbb969 ("f2fs: refactor __exchange_data_block for speed up")
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/f2fs/data.c
fs/f2fs/file.c

index 0206c8c20784ce01aaa7c0a51e17aa2c273721c8..b2cccd4083b8d1864d739dd67737fcb0c0782d02 100644 (file)
@@ -1267,7 +1267,7 @@ static int f2fs_write_data_page(struct page *page,
        loff_t i_size = i_size_read(inode);
        const pgoff_t end_index = ((unsigned long long) i_size)
                                                        >> PAGE_SHIFT;
-       loff_t psize = (page->index + 1) << PAGE_SHIFT;
+       loff_t psize = (loff_t)(page->index + 1) << PAGE_SHIFT;
        unsigned offset = 0;
        bool need_balance_fs = false;
        int err = 0;
index f46ac1651bd5da83ebf1a4c30ccc8e08b7eb8d03..e3c438c8b8ce086f754d1079aa3f08ca06c03cb1 100644 (file)
@@ -980,7 +980,7 @@ static int __clone_blkaddrs(struct inode *src_inode, struct inode *dst_inode,
                                }
                                dn.ofs_in_node++;
                                i++;
-                               new_size = (dst + i) << PAGE_SHIFT;
+                               new_size = (loff_t)(dst + i) << PAGE_SHIFT;
                                if (dst_inode->i_size < new_size)
                                        f2fs_i_size_write(dst_inode, new_size);
                        } while (--ilen && (do_replace[i] || blkaddr[i] == NULL_ADDR));