nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0405-zfs-Fix-possible-negative-shift-operation.patch

468bd4
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
468bd4
From: Darren Kenny <darren.kenny@oracle.com>
468bd4
Date: Tue, 24 Nov 2020 16:41:49 +0000
468bd4
Subject: [PATCH] zfs: Fix possible negative shift operation
468bd4
468bd4
While it is possible for the return value from zfs_log2() to be zero
468bd4
(0), it is quite unlikely, given that the previous assignment to blksz
468bd4
is shifted up by SPA_MINBLOCKSHIFT (9) before 9 is subtracted at the
468bd4
assignment to epbs.
468bd4
468bd4
But, while unlikely during a normal operation, it may be that a carefully
468bd4
crafted ZFS filesystem could result in a zero (0) value to the
468bd4
dn_datalbkszsec field, which means that the shift left does nothing
468bd4
and assigns zero (0) to blksz, resulting in a negative epbs value.
468bd4
468bd4
Fixes: CID 73608
468bd4
468bd4
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
468bd4
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
468bd4
---
468bd4
 grub-core/fs/zfs/zfs.c | 5 +++++
468bd4
 1 file changed, 5 insertions(+)
468bd4
468bd4
diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c
030dc3
index c6204367e78..3dfde080750 100644
468bd4
--- a/grub-core/fs/zfs/zfs.c
468bd4
+++ b/grub-core/fs/zfs/zfs.c
468bd4
@@ -2667,6 +2667,11 @@ dnode_get (dnode_end_t * mdn, grub_uint64_t objnum, grub_uint8_t type,
468bd4
   blksz = grub_zfs_to_cpu16 (mdn->dn.dn_datablkszsec, 
468bd4
 			     mdn->endian) << SPA_MINBLOCKSHIFT;
468bd4
   epbs = zfs_log2 (blksz) - DNODE_SHIFT;
468bd4
+
468bd4
+  /* While this should never happen, we should check that epbs is not negative. */
468bd4
+  if (epbs < 0)
468bd4
+    epbs = 0;
468bd4
+
468bd4
   blkid = objnum >> epbs;
468bd4
   idx = objnum & ((1 << epbs) - 1);
468bd4