From: Theodore Ts'o Date: Fri, 20 Dec 2019 00:37:34 +0000 (-0500) Subject: e2fsck: abort if there is a corrupted directory block when rehashing X-Git-Tag: debian/1.44.5-1+deb10u3~4 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=3d0a5b1c88214ef4b5ea28f25c2aacc1358b585c;p=tools%2Fe2fsprogs.git e2fsck: abort if there is a corrupted directory block when rehashing In e2fsck pass 3a, when we are rehashing directories, at least in theory, all of the directories should have had corruptions with respect to directory entry structure fixed. However, it's possible (for example, if the user declined a fix) that we can reach this stage of processing with a corrupted directory entries. So check for that case and don't try to process a corrupted directory block so we don't run into trouble in mutate_name() if there is a zero-length file name. Addresses-Debian-Bug: 948508 Addresses: TALOS-2019-0973 Addresses: CVE-2019-5188 Signed-off-by: Theodore Ts'o (cherry picked from commit 8dd73c149f418238f19791f9d666089ef9734dff) --- diff --git a/e2fsck/rehash.c b/e2fsck/rehash.c index 7c4ab08..27e1429 100644 --- a/e2fsck/rehash.c +++ b/e2fsck/rehash.c @@ -159,6 +159,10 @@ static int fill_dir_block(ext2_filsys fs, dir_offset += rec_len; if (dirent->inode == 0) continue; + if ((name_len) == 0) { + fd->err = EXT2_ET_DIR_CORRUPTED; + return BLOCK_ABORT; + } if (!fd->compress && (name_len == 1) && (dirent->name[0] == '.')) continue; @@ -398,6 +402,11 @@ static int duplicate_search_and_fix(e2fsck_t ctx, ext2_filsys fs, continue; } new_len = ext2fs_dirent_name_len(ent->dir); + if (new_len == 0) { + /* should never happen */ + ext2fs_unmark_valid(fs); + continue; + } memcpy(new_name, ent->dir->name, new_len); mutate_name(new_name, &new_len); for (j=0; j < fd->num_array; j++) {