f2fs: should convert inline_data during the mkwrite

If mkwrite is called to an inode having inline_data, it can overwrite the data
index space as NEW_ADDR. (e.g., the first 4 bytes are coincidently zero)

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Jaegeuk Kim 2014-08-07 16:32:25 -07:00
parent e1c4204520
commit b067ba1f1b
4 changed files with 22 additions and 13 deletions

View file

@ -946,7 +946,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
f2fs_balance_fs(sbi);
repeat:
err = f2fs_convert_inline_data(inode, pos + len);
err = f2fs_convert_inline_data(inode, pos + len, NULL);
if (err)
goto fail;

View file

@ -1439,7 +1439,7 @@ extern const struct inode_operations f2fs_special_inode_operations;
*/
bool f2fs_may_inline(struct inode *);
int f2fs_read_inline_data(struct inode *, struct page *);
int f2fs_convert_inline_data(struct inode *, pgoff_t);
int f2fs_convert_inline_data(struct inode *, pgoff_t, struct page *);
int f2fs_write_inline_data(struct inode *, struct page *, unsigned int);
void truncate_inline_data(struct inode *, u64);
int recover_inline_data(struct inode *, struct page *);

View file

@ -41,6 +41,11 @@ static int f2fs_vm_page_mkwrite(struct vm_area_struct *vma,
sb_start_pagefault(inode->i_sb);
/* force to convert with normal data indices */
err = f2fs_convert_inline_data(inode, MAX_INLINE_DATA + 1, page);
if (err)
goto out;
/* block allocation */
f2fs_lock_op(sbi);
set_new_dnode(&dn, inode, NULL, NULL, 0);
@ -533,7 +538,7 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
if ((attr->ia_valid & ATTR_SIZE) &&
attr->ia_size != i_size_read(inode)) {
err = f2fs_convert_inline_data(inode, attr->ia_size);
err = f2fs_convert_inline_data(inode, attr->ia_size, NULL);
if (err)
return err;
@ -622,7 +627,7 @@ static int punch_hole(struct inode *inode, loff_t offset, loff_t len)
loff_t off_start, off_end;
int ret = 0;
ret = f2fs_convert_inline_data(inode, MAX_INLINE_DATA + 1);
ret = f2fs_convert_inline_data(inode, MAX_INLINE_DATA + 1, NULL);
if (ret)
return ret;
@ -678,7 +683,7 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
if (ret)
return ret;
ret = f2fs_convert_inline_data(inode, offset + len);
ret = f2fs_convert_inline_data(inode, offset + len, NULL);
if (ret)
return ret;

View file

@ -124,9 +124,10 @@ static int __f2fs_convert_inline_data(struct inode *inode, struct page *page)
return err;
}
int f2fs_convert_inline_data(struct inode *inode, pgoff_t to_size)
int f2fs_convert_inline_data(struct inode *inode, pgoff_t to_size,
struct page *page)
{
struct page *page;
struct page *new_page = page;
int err;
if (!f2fs_has_inline_data(inode))
@ -134,17 +135,20 @@ int f2fs_convert_inline_data(struct inode *inode, pgoff_t to_size)
else if (to_size <= MAX_INLINE_DATA)
return 0;
page = grab_cache_page(inode->i_mapping, 0);
if (!page)
return -ENOMEM;
if (!page || page->index != 0) {
new_page = grab_cache_page(inode->i_mapping, 0);
if (!new_page)
return -ENOMEM;
}
err = __f2fs_convert_inline_data(inode, page);
f2fs_put_page(page, 1);
err = __f2fs_convert_inline_data(inode, new_page);
if (!page || page->index != 0)
f2fs_put_page(new_page, 1);
return err;
}
int f2fs_write_inline_data(struct inode *inode,
struct page *page, unsigned size)
struct page *page, unsigned size)
{
void *src_addr, *dst_addr;
struct page *ipage;