From: Eryu Guan Date: Thu, 22 Mar 2018 15:41:25 +0000 (-0400) Subject: ext4: protect i_disksize update by i_data_sem in direct write path X-Git-Tag: v4.1.12-124.31.3~327 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c098051d90e95c655ac2367ee935c2816006d692;p=users%2Fjedix%2Flinux-maple.git ext4: protect i_disksize update by i_data_sem in direct write path i_disksize update should be protected by i_data_sem, by either taking the lock explicitly or by using ext4_update_i_disksize() helper. But the i_disksize updates in ext4_direct_IO_write() are not protected at all, which may be racing with i_disksize updates in writeback path in delalloc buffer write path. This is found by code inspection, and I didn't hit any i_disksize corruption due to this bug. Thanks to Jan Kara for catching this bug and suggesting the fix! Reported-by: Jan Kara Suggested-by: Jan Kara Signed-off-by: Eryu Guan Signed-off-by: Theodore Ts'o Cc: stable@vger.kernel.org Orabug: 28940828 commit 73fdad00b208b139cf43f3163fbc0f67e4c6047c upstream Signed-off-by: Brian Maly Conflicts: fs/ext4/indirect.c code line mismatch Signed-off-by: Shan Hai Reviewed-by: Ashish Samant Signed-off-by: Brian Maly --- diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c index e862df31ddda..f5d37de17558 100644 --- a/fs/ext4/indirect.c +++ b/fs/ext4/indirect.c @@ -647,7 +647,6 @@ ssize_t ext4_ind_direct_IO(struct kiocb *iocb, struct iov_iter *iter, { struct file *file = iocb->ki_filp; struct inode *inode = file->f_mapping->host; - struct ext4_inode_info *ei = EXT4_I(inode); handle_t *handle; ssize_t ret; int orphan = 0; @@ -670,7 +669,7 @@ ssize_t ext4_ind_direct_IO(struct kiocb *iocb, struct iov_iter *iter, goto out; } orphan = 1; - ei->i_disksize = inode->i_size; + ext4_update_i_disksize(inode, inode->i_size); ext4_journal_stop(handle); } } @@ -738,7 +737,7 @@ locked: if (ret > 0) { loff_t end = offset + ret; if (end > inode->i_size) { - ei->i_disksize = end; + ext4_update_i_disksize(inode, end); i_size_write(inode, end); /* * We're going to return a positive `ret'