fix some conversion overflows
authorNick Piggin <npiggin@suse.de>
Fri, 20 Jul 2007 07:31:45 +0000 (00:31 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Fri, 20 Jul 2007 15:44:19 +0000 (08:44 -0700)
Fix page index to offset conversion overflows in buffer layer, ecryptfs,
and ocfs2.

It would be nice to convert the whole tree to page_offset, but for now
just fix the bugs.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: Michael Halcrow <mhalcrow@us.ibm.com>
Cc: Mark Fasheh <mark.fasheh@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/buffer.c
fs/ecryptfs/mmap.c
fs/ocfs2/mmap.c

index 02ebb1f1d3b0e2fa70298d21dbb1b88d4471a65d..0e5ec371ce727e8fcccd79d33108b9aca1f051ca 100644 (file)
@@ -2221,7 +2221,7 @@ block_page_mkwrite(struct vm_area_struct *vma, struct page *page,
        lock_page(page);
        size = i_size_read(inode);
        if ((page->mapping != inode->i_mapping) ||
-           ((page->index << PAGE_CACHE_SHIFT) > size)) {
+           (page_offset(page) > size)) {
                /* page got truncated out from underneath us */
                goto out_unlock;
        }
index 7d5a43cb0d5c81ee470ee8ec9f7a7cabc329b7e7..e4ab7bc14efede18f657dc477d1c92137bc37e27 100644 (file)
@@ -409,8 +409,7 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page,
        if (!PageUptodate(page))
                rc = ecryptfs_do_readpage(file, page, page->index);
        if (page->index != 0) {
-               loff_t end_of_prev_pg_pos =
-                       (((loff_t)page->index << PAGE_CACHE_SHIFT) - 1);
+               loff_t end_of_prev_pg_pos = page_offset(page) - 1;
 
                if (end_of_prev_pg_pos > i_size_read(page->mapping->host)) {
                        rc = ecryptfs_truncate(file->f_path.dentry,
@@ -736,7 +735,7 @@ static int ecryptfs_commit_write(struct file *file, struct page *page,
                goto out;
        }
        inode->i_blocks = lower_inode->i_blocks;
-       pos = (page->index << PAGE_CACHE_SHIFT) + to;
+       pos = page_offset(page) + to;
        if (pos > i_size_read(inode)) {
                i_size_write(inode, pos);
                ecryptfs_printk(KERN_DEBUG, "Expanded file size to "
index ee64749e2eebd55bb1c8ea95d19cfb30a447e0ea..98756156d29878b8df182497214b9640d45ac79d 100644 (file)
@@ -89,7 +89,7 @@ static int __ocfs2_page_mkwrite(struct inode *inode, struct buffer_head *di_bh,
 {
        int ret;
        struct address_space *mapping = inode->i_mapping;
-       loff_t pos = page->index << PAGE_CACHE_SHIFT;
+       loff_t pos = page_offset(page);
        unsigned int len = PAGE_CACHE_SIZE;
        pgoff_t last_index;
        struct page *locked_page = NULL;