sctp: validate chunk len before actually using it
[cascardo/linux.git] / fs / ext4 / inode.c
index d8a4afc..9c06472 100644 (file)
@@ -647,11 +647,19 @@ found:
                /*
                 * We have to zeroout blocks before inserting them into extent
                 * status tree. Otherwise someone could look them up there and
-                * use them before they are really zeroed.
+                * use them before they are really zeroed. We also have to
+                * unmap metadata before zeroing as otherwise writeback can
+                * overwrite zeros with stale data from block device.
                 */
                if (flags & EXT4_GET_BLOCKS_ZERO &&
                    map->m_flags & EXT4_MAP_MAPPED &&
                    map->m_flags & EXT4_MAP_NEW) {
+                       ext4_lblk_t i;
+
+                       for (i = 0; i < map->m_len; i++) {
+                               unmap_underlying_metadata(inode->i_sb->s_bdev,
+                                                         map->m_pblk + i);
+                       }
                        ret = ext4_issue_zeroout(inode, map->m_lblk,
                                                 map->m_pblk, map->m_len);
                        if (ret) {
@@ -5070,7 +5078,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
        int orphan = 0;
        const unsigned int ia_valid = attr->ia_valid;
 
-       error = inode_change_ok(inode, attr);
+       error = setattr_prepare(dentry, attr);
        if (error)
                return error;