0125-fs-btrfs-Validate-the-number-of-stripes-parities-in-.patch 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. From b88a82e78cdd0ab8e0339c1c3f9564c4d8c0c969 Mon Sep 17 00:00:00 2001
  2. From: Daniel Axtens <dja@axtens.net>
  3. Date: Mon, 18 Jan 2021 17:17:16 +1100
  4. Subject: [PATCH] fs/btrfs: Validate the number of stripes/parities in RAID5/6
  5. This prevents a divide by zero if nstripes == nparities, and
  6. also prevents propagation of invalid values if nstripes ends up
  7. less than nparities.
  8. Signed-off-by: Daniel Axtens <dja@axtens.net>
  9. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  10. Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
  11. ---
  12. grub-core/fs/btrfs.c | 3 +++
  13. 1 file changed, 3 insertions(+)
  14. diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
  15. index 2b65bd5..e4e87ba 100644
  16. --- a/grub-core/fs/btrfs.c
  17. +++ b/grub-core/fs/btrfs.c
  18. @@ -1076,6 +1076,9 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr,
  19. * stripen is computed without the parities
  20. * (0 for A0, A1, A2, 1 for B0, B1, B2, etc.).
  21. */
  22. + if (nparities >= nstripes)
  23. + return grub_error (GRUB_ERR_BAD_FS,
  24. + "invalid RAID5/6: nparities >= nstripes");
  25. high = grub_divmod64 (stripe_nr, nstripes - nparities, &stripen);
  26. /*
  27. --
  28. 2.14.2