]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
iomap: Fix use-after-free error in page_done callback
authorAndreas Gruenbacher <agruenba@redhat.com>
Tue, 30 Apr 2019 15:45:34 +0000 (08:45 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Wed, 1 May 2019 14:47:37 +0000 (07:47 -0700)
In iomap_write_end, we're not holding a page reference anymore when
calling the page_done callback, but the callback needs that reference to
access the page.  To fix that, move the put_page call in
__generic_write_end into the callers of __generic_write_end.  Then, in
iomap_write_end, put the page after calling the page_done callback.

Reported-by: Jan Kara <jack@suse.cz>
Fixes: 63899c6f8851 ("iomap: add a page_done callback")
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
fs/buffer.c
fs/iomap.c

index e0d4c6a5e2d2abc73d5f6341f1116f2f8285458c..0faa41fb4c884ec8f5645697a906667a4222583d 100644 (file)
@@ -2104,7 +2104,6 @@ void __generic_write_end(struct inode *inode, loff_t pos, unsigned copied,
        }
 
        unlock_page(page);
-       put_page(page);
 
        if (old_size < pos)
                pagecache_isize_extended(inode, old_size, pos);
@@ -2160,6 +2159,7 @@ int generic_write_end(struct file *file, struct address_space *mapping,
 {
        copied = block_write_end(file, mapping, pos, len, copied, page, fsdata);
        __generic_write_end(mapping->host, pos, copied, page);
+       put_page(page);
        return copied;
 }
 EXPORT_SYMBOL(generic_write_end);
index 4380d2c412f4527461bc87f2f104e4ffc40768bf..e6453c1c831e7093913dcfc9498777a3a5c67906 100644 (file)
@@ -772,6 +772,7 @@ iomap_write_end(struct inode *inode, loff_t pos, unsigned len,
        __generic_write_end(inode, pos, ret, page);
        if (iomap->page_done)
                iomap->page_done(inode, pos, copied, page, iomap);
+       put_page(page);
 
        if (ret < len)
                iomap_write_failed(inode, pos, len);