Blame SOURCES/e2fsprogs-libext2fs-add-sanity-check-to-extent-manipulation.patch

91a00b
From ff6679208f45975a090b1260367f1fc5a17b3db7 Mon Sep 17 00:00:00 2001
91a00b
From: Lukas Czerner <lczerner@redhat.com>
91a00b
Date: Thu, 21 Apr 2022 19:31:48 +0200
91a00b
Subject: [PATCH] libext2fs: add sanity check to extent manipulation
91a00b
Content-Type: text/plain
91a00b
91a00b
It is possible to have a corrupted extent tree in such a way that a leaf
91a00b
node contains zero extents in it. Currently if that happens and we try
91a00b
to traverse the tree we can end up accessing wrong data, or possibly
91a00b
even uninitialized memory. Make sure we don't do that.
91a00b
91a00b
Additionally make sure that we have a sane number of bytes passed to
91a00b
memmove() in ext2fs_extent_delete().
91a00b
91a00b
Note that e2fsck is currently unable to spot and fix such corruption in
91a00b
pass1.
91a00b
91a00b
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
91a00b
Reported-by: Nils Bars <nils_bars@t-online.de>
91a00b
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2068113
91a00b
Addresses: CVE-2022-1304
91a00b
Addresses-Debian-Bug: #1010263
91a00b
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
91a00b
(cherry picked from commit ab51d587bb9b229b1fade1afd02e1574c1ba5c76)
91a00b
---
91a00b
 lib/ext2fs/extent.c | 8 ++++++++
91a00b
 1 file changed, 8 insertions(+)
91a00b
91a00b
diff --git a/lib/ext2fs/extent.c b/lib/ext2fs/extent.c
91a00b
index b324c7b0..1a206a16 100644
91a00b
--- a/lib/ext2fs/extent.c
91a00b
+++ b/lib/ext2fs/extent.c
91a00b
@@ -495,6 +495,10 @@ retry:
91a00b
 			ext2fs_le16_to_cpu(eh->eh_entries);
91a00b
 		newpath->max_entries = ext2fs_le16_to_cpu(eh->eh_max);
91a00b
 
91a00b
+		/* Make sure there is at least one extent present */
91a00b
+		if (newpath->left <= 0)
91a00b
+			return EXT2_ET_EXTENT_NO_DOWN;
91a00b
+
91a00b
 		if (path->left > 0) {
91a00b
 			ix++;
91a00b
 			newpath->end_blk = ext2fs_le32_to_cpu(ix->ei_block);
91a00b
@@ -1630,6 +1634,10 @@ errcode_t ext2fs_extent_delete(ext2_extent_handle_t handle, int flags)
91a00b
 
91a00b
 	cp = path->curr;
91a00b
 
91a00b
+	/* Sanity check before memmove() */
91a00b
+	if (path->left < 0)
91a00b
+		return EXT2_ET_EXTENT_LEAF_BAD;
91a00b
+
91a00b
 	if (path->left) {
91a00b
 		memmove(cp, cp + sizeof(struct ext3_extent_idx),
91a00b
 			path->left * sizeof(struct ext3_extent_idx));
91a00b
-- 
91a00b
2.35.3
91a00b