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

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