2
0

004-CVE-2022-1304-libext2fs-add-sanity-check-to-extent-manipulation.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. From ab51d587bb9b229b1fade1afd02e1574c1ba5c76 Mon Sep 17 00:00:00 2001
  2. From: Lukas Czerner <[email protected]>
  3. Date: Thu, 21 Apr 2022 19:31:48 +0200
  4. Subject: libext2fs: add sanity check to extent manipulation
  5. It is possible to have a corrupted extent tree in such a way that a leaf
  6. node contains zero extents in it. Currently if that happens and we try
  7. to traverse the tree we can end up accessing wrong data, or possibly
  8. even uninitialized memory. Make sure we don't do that.
  9. Additionally make sure that we have a sane number of bytes passed to
  10. memmove() in ext2fs_extent_delete().
  11. Note that e2fsck is currently unable to spot and fix such corruption in
  12. pass1.
  13. Signed-off-by: Lukas Czerner <[email protected]>
  14. Reported-by: Nils Bars <[email protected]>
  15. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2068113
  16. Addresses: CVE-2022-1304
  17. Addresses-Debian-Bug: #1010263
  18. Signed-off-by: Theodore Ts'o <[email protected]>
  19. ---
  20. lib/ext2fs/extent.c | 8 ++++++++
  21. 1 file changed, 8 insertions(+)
  22. --- a/lib/ext2fs/extent.c
  23. +++ b/lib/ext2fs/extent.c
  24. @@ -495,6 +495,10 @@ retry:
  25. ext2fs_le16_to_cpu(eh->eh_entries);
  26. newpath->max_entries = ext2fs_le16_to_cpu(eh->eh_max);
  27. + /* Make sure there is at least one extent present */
  28. + if (newpath->left <= 0)
  29. + return EXT2_ET_EXTENT_NO_DOWN;
  30. +
  31. if (path->left > 0) {
  32. ix++;
  33. newpath->end_blk = ext2fs_le32_to_cpu(ix->ei_block);
  34. @@ -1630,6 +1634,10 @@ errcode_t ext2fs_extent_delete(ext2_exte
  35. cp = path->curr;
  36. + /* Sanity check before memmove() */
  37. + if (path->left < 0)
  38. + return EXT2_ET_EXTENT_LEAF_BAD;
  39. +
  40. if (path->left) {
  41. memmove(cp, cp + sizeof(struct ext3_extent_idx),
  42. path->left * sizeof(struct ext3_extent_idx));