From: Stefan Brüns Date: Tue, 6 Sep 2016 02:36:43 +0000 (+0200) Subject: ext4: Do not crash when trying to grow a directory using extents X-Git-Tag: v2016.11-rc1~93 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b96c3c7292214fb81b1b355bf5a6d53cf9996d1e;p=u-boot ext4: Do not crash when trying to grow a directory using extents The following command crashes u-boot: ./sandbox/u-boot -c 'i=0; host bind 0 ./sandbox/test/fs/3GB.ext4.img ; while test $i -lt 200 ; do echo $i; setexpr i $i + 1; ext4write host 0 0 /foobar${i} 0; done' Previously, the code updated the direct_block even for extents, and fortunately crashed before pushing garbage to the disk. Signed-off-by: Stefan Brüns Reviewed-by: Lukasz Majewski --- diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c index 680e0011cc..eebca7de91 100644 --- a/fs/ext4/ext4_common.c +++ b/fs/ext4/ext4_common.c @@ -453,8 +453,13 @@ restart: sizeof(struct ext2_dirent) + padding_factor; if ((fs->blksz - totalbytes - last_entry_dirlen) < new_entry_byte_reqd) { - printf("1st Block Full:Allocate new block\n"); + printf("Last Block Full:Allocate new block\n"); + if (le32_to_cpu(g_parent_inode->flags) & + EXT4_EXTENTS_FL) { + printf("Directory uses extents\n"); + goto fail; + } if (direct_blk_idx == INDIRECT_BLOCKS - 1) { printf("Directory exceeds limit\n"); goto fail;