0068-zfs-Fix-possible-negative-shift-operation.patch 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. From a02091834d3e167320d8a262ff04b8e83c5e616d Mon Sep 17 00:00:00 2001
  2. From: Darren Kenny <darren.kenny@oracle.com>
  3. Date: Tue, 24 Nov 2020 16:41:49 +0000
  4. Subject: [PATCH] zfs: Fix possible negative shift operation
  5. While it is possible for the return value from zfs_log2() to be zero
  6. (0), it is quite unlikely, given that the previous assignment to blksz
  7. is shifted up by SPA_MINBLOCKSHIFT (9) before 9 is subtracted at the
  8. assignment to epbs.
  9. But, while unlikely during a normal operation, it may be that a carefully
  10. crafted ZFS filesystem could result in a zero (0) value to the
  11. dn_datalbkszsec field, which means that the shift left does nothing
  12. and assigns zero (0) to blksz, resulting in a negative epbs value.
  13. Fixes: CID 73608
  14. Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
  15. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  16. Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
  17. ---
  18. grub-core/fs/zfs/zfs.c | 5 +++++
  19. 1 file changed, 5 insertions(+)
  20. diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c
  21. index 36d0373..0c42cba 100644
  22. --- a/grub-core/fs/zfs/zfs.c
  23. +++ b/grub-core/fs/zfs/zfs.c
  24. @@ -2667,6 +2667,11 @@ dnode_get (dnode_end_t * mdn, grub_uint64_t objnum, grub_uint8_t type,
  25. blksz = grub_zfs_to_cpu16 (mdn->dn.dn_datablkszsec,
  26. mdn->endian) << SPA_MINBLOCKSHIFT;
  27. epbs = zfs_log2 (blksz) - DNODE_SHIFT;
  28. +
  29. + /* While this should never happen, we should check that epbs is not negative. */
  30. + if (epbs < 0)
  31. + epbs = 0;
  32. +
  33. blkid = objnum >> epbs;
  34. idx = objnum & ((1 << epbs) - 1);
  35. --
  36. 2.14.2