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

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