dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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