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

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