0001-libext2fs-fix-potential-buffer-overflow-in-closefs.patch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. From 49d0fe2a14f2a23da2fe299643379b8c1d37df73 Mon Sep 17 00:00:00 2001
  2. From: Theodore Ts'o <tytso@mit.edu>
  3. Date: Fri, 6 Feb 2015 12:46:39 -0500
  4. Subject: [PATCH] libext2fs: fix potential buffer overflow in closefs()
  5. Upstream commit 49d0fe2a14f2.
  6. The bug fix in f66e6ce4446: "libext2fs: avoid buffer overflow if
  7. s_first_meta_bg is too big" had a typo in the fix for
  8. ext2fs_closefs(). In practice most of the security exposure was from
  9. the openfs path, since this meant if there was a carefully crafted
  10. file system, buffer overrun would be triggered when the file system was
  11. opened.
  12. However, if corrupted file system didn't trip over some corruption
  13. check, and then the file system was modified via tune2fs or debugfs,
  14. such that the superblock was marked dirty and then written out via the
  15. closefs() path, it's possible that the buffer overrun could be
  16. triggered when the file system is closed.
  17. Also clear up a signed vs unsigned warning while we're at it.
  18. Thanks to Nick Kralevich <nnk@google.com> for asking me to look at
  19. compiler warning in the code in question, which led me to notice the
  20. bug in f66e6ce4446.
  21. Addresses: CVE-2015-1572
  22. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
  23. Signed-off-by: Baruch Siach <baruch@tkos.co.il>
  24. ---
  25. lib/ext2fs/closefs.c | 4 ++--
  26. 1 file changed, 2 insertions(+), 2 deletions(-)
  27. diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c
  28. index 1f9911311a1a..ab5b2fb2365e 100644
  29. --- a/lib/ext2fs/closefs.c
  30. +++ b/lib/ext2fs/closefs.c
  31. @@ -287,7 +287,7 @@ errcode_t ext2fs_flush2(ext2_filsys fs, int flags)
  32. dgrp_t j;
  33. #endif
  34. char *group_ptr;
  35. - int old_desc_blocks;
  36. + blk64_t old_desc_blocks;
  37. struct ext2fs_numeric_progress_struct progress;
  38. EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
  39. @@ -346,7 +346,7 @@ errcode_t ext2fs_flush2(ext2_filsys fs, int flags)
  40. group_ptr = (char *) group_shadow;
  41. if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) {
  42. old_desc_blocks = fs->super->s_first_meta_bg;
  43. - if (old_desc_blocks > fs->super->s_first_meta_bg)
  44. + if (old_desc_blocks > fs->desc_blocks)
  45. old_desc_blocks = fs->desc_blocks;
  46. } else
  47. old_desc_blocks = fs->desc_blocks;
  48. --
  49. 2.1.4