Commit 256fe416 authored by Jan Kara's avatar Jan Kara

udf: Do not update file length for failed writes to inline files

When write to inline file fails (or happens only partly), we still
updated length of inline data as if the whole write succeeded. Fix the
update of length of inline data to happen only if the write succeeds.

Reported-by: syzbot+0937935b993956ba28ab@syzkaller.appspotmail.com
CC: stable@vger.kernel.org
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent 02113fea
...@@ -149,26 +149,24 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from) ...@@ -149,26 +149,24 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
goto out; goto out;
down_write(&iinfo->i_data_sem); down_write(&iinfo->i_data_sem);
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB &&
loff_t end = iocb->ki_pos + iov_iter_count(from); inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) +
iocb->ki_pos + iov_iter_count(from))) {
if (inode->i_sb->s_blocksize <
(udf_file_entry_alloc_offset(inode) + end)) {
err = udf_expand_file_adinicb(inode); err = udf_expand_file_adinicb(inode);
if (err) { if (err) {
inode_unlock(inode); inode_unlock(inode);
udf_debug("udf_expand_adinicb: err=%d\n", err); udf_debug("udf_expand_adinicb: err=%d\n", err);
return err; return err;
} }
} else {
iinfo->i_lenAlloc = max(end, inode->i_size);
up_write(&iinfo->i_data_sem);
}
} else } else
up_write(&iinfo->i_data_sem); up_write(&iinfo->i_data_sem);
retval = __generic_file_write_iter(iocb, from); retval = __generic_file_write_iter(iocb, from);
out: out:
down_write(&iinfo->i_data_sem);
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB && retval > 0)
iinfo->i_lenAlloc = inode->i_size;
up_write(&iinfo->i_data_sem);
inode_unlock(inode); inode_unlock(inode);
if (retval > 0) { if (retval > 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment