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

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