Blame SOURCES/e2fsprogs-1.45.5-e2fsck-abort-if-there-is-a-corrupted-directory-block.patch

a9c310
From 8a51e038d172c3405466ddb60d712c2ac934b954 Mon Sep 17 00:00:00 2001
a9c310
From: Theodore Ts'o <tytso@mit.edu>
a9c310
Date: Thu, 19 Dec 2019 19:37:34 -0500
a9c310
Subject: [PATCH 07/10] e2fsck: abort if there is a corrupted directory block
a9c310
 when rehashing
a9c310
a9c310
In e2fsck pass 3a, when we are rehashing directories, at least in
a9c310
theory, all of the directories should have had corruptions with
a9c310
respect to directory entry structure fixed.  However, it's possible
a9c310
(for example, if the user declined a fix) that we can reach this stage
a9c310
of processing with a corrupted directory entries.
a9c310
a9c310
So check for that case and don't try to process a corrupted directory
a9c310
block so we don't run into trouble in mutate_name() if there is a
a9c310
zero-length file name.
a9c310
a9c310
Addresses: TALOS-2019-0973
a9c310
Addresses: CVE-2019-5188
a9c310
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
a9c310
---
a9c310
 e2fsck/rehash.c | 9 +++++++++
a9c310
 1 file changed, 9 insertions(+)
a9c310
a9c310
diff --git a/e2fsck/rehash.c b/e2fsck/rehash.c
a9c310
index a5fc1be1..3dd1e941 100644
a9c310
--- a/e2fsck/rehash.c
a9c310
+++ b/e2fsck/rehash.c
a9c310
@@ -160,6 +160,10 @@ static int fill_dir_block(ext2_filsys fs,
a9c310
 		dir_offset += rec_len;
a9c310
 		if (dirent->inode == 0)
a9c310
 			continue;
a9c310
+		if ((name_len) == 0) {
a9c310
+			fd->err = EXT2_ET_DIR_CORRUPTED;
a9c310
+			return BLOCK_ABORT;
a9c310
+		}
a9c310
 		if (!fd->compress && (name_len == 1) &&
a9c310
 		    (dirent->name[0] == '.'))
a9c310
 			continue;
a9c310
@@ -401,6 +405,11 @@ static int duplicate_search_and_fix(e2fsck_t ctx, ext2_filsys fs,
a9c310
 			continue;
a9c310
 		}
a9c310
 		new_len = ext2fs_dirent_name_len(ent->dir);
a9c310
+		if (new_len == 0) {
a9c310
+			 /* should never happen */
a9c310
+			ext2fs_unmark_valid(fs);
a9c310
+			continue;
a9c310
+		}
a9c310
 		memcpy(new_name, ent->dir->name, new_len);
a9c310
 		mutate_name(new_name, &new_len);
a9c310
 		for (j=0; j < fd->num_array; j++) {
a9c310
-- 
a9c310
2.21.1
a9c310