@@ -494,9 +494,10 @@ static void ext4_map_blocks_es_recheck(handle_t *handle,
494494 * Otherwise, call with ext4_ind_map_blocks() to handle indirect mapping
495495 * based files
496496 *
497- * On success, it returns the number of blocks being mapped or allocated. if
498- * create==0 and the blocks are pre-allocated and unwritten, the resulting @map
499- * is marked as unwritten. If the create == 1, it will mark @map as mapped.
497+ * On success, it returns the number of blocks being mapped or allocated.
498+ * If flags doesn't contain EXT4_GET_BLOCKS_CREATE the blocks are
499+ * pre-allocated and unwritten, the resulting @map is marked as unwritten.
500+ * If the flags contain EXT4_GET_BLOCKS_CREATE, it will mark @map as mapped.
500501 *
501502 * It returns 0 if plain look up failed (blocks have not been allocated), in
502503 * that case, @map is returned as unmapped but we still do fill map->m_len to
@@ -618,8 +619,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
618619 * Returns if the blocks have already allocated
619620 *
620621 * Note that if blocks have been preallocated
621- * ext4_ext_get_block() returns the create = 0
622- * with buffer head unmapped.
622+ * ext4_ext_map_blocks() returns with buffer head unmapped
623623 */
624624 if (retval > 0 && map -> m_flags & EXT4_MAP_MAPPED )
625625 /*
@@ -834,10 +834,22 @@ int ext4_get_block(struct inode *inode, sector_t iblock,
834834int ext4_get_block_unwritten (struct inode * inode , sector_t iblock ,
835835 struct buffer_head * bh_result , int create )
836836{
837+ int ret = 0 ;
838+
837839 ext4_debug ("ext4_get_block_unwritten: inode %lu, create flag %d\n" ,
838840 inode -> i_ino , create );
839- return _ext4_get_block (inode , iblock , bh_result ,
841+ ret = _ext4_get_block (inode , iblock , bh_result ,
840842 EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT );
843+
844+ /*
845+ * If the buffer is marked unwritten, mark it as new to make sure it is
846+ * zeroed out correctly in case of partial writes. Otherwise, there is
847+ * a chance of stale data getting exposed.
848+ */
849+ if (ret == 0 && buffer_unwritten (bh_result ))
850+ set_buffer_new (bh_result );
851+
852+ return ret ;
841853}
842854
843855/* Maximum number of blocks we map for direct IO at once. */
@@ -5146,9 +5158,12 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
51465158 "iget: bogus i_mode (%o)" , inode -> i_mode );
51475159 goto bad_inode ;
51485160 }
5149- if (IS_CASEFOLDED (inode ) && !ext4_has_feature_casefold (inode -> i_sb ))
5161+ if (IS_CASEFOLDED (inode ) && !ext4_has_feature_casefold (inode -> i_sb )) {
51505162 ext4_error_inode (inode , function , line , 0 ,
51515163 "casefold flag without casefold feature" );
5164+ ret = - EFSCORRUPTED ;
5165+ goto bad_inode ;
5166+ }
51525167 if ((err_str = check_igot_inode (inode , flags )) != NULL ) {
51535168 ext4_error_inode (inode , function , line , 0 , err_str );
51545169 ret = - EFSCORRUPTED ;
0 commit comments