From: Darren Kenny Date: Tue, 24 Nov 2020 16:41:49 +0000 (+0000) Subject: zfs: Fix possible negative shift operation X-Git-Tag: grub-2.06-rc1~107 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a02091834d3e167320d8a262ff04b8e83c5e616d;p=thirdparty%2Fgrub.git zfs: Fix possible negative shift operation While it is possible for the return value from zfs_log2() to be zero (0), it is quite unlikely, given that the previous assignment to blksz is shifted up by SPA_MINBLOCKSHIFT (9) before 9 is subtracted at the assignment to epbs. But, while unlikely during a normal operation, it may be that a carefully crafted ZFS filesystem could result in a zero (0) value to the dn_datalbkszsec field, which means that the shift left does nothing and assigns zero (0) to blksz, resulting in a negative epbs value. Fixes: CID 73608 Signed-off-by: Darren Kenny Reviewed-by: Daniel Kiper --- diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c index b6e1e178d..695e6ea30 100644 --- a/grub-core/fs/zfs/zfs.c +++ b/grub-core/fs/zfs/zfs.c @@ -2670,6 +2670,11 @@ dnode_get (dnode_end_t * mdn, grub_uint64_t objnum, grub_uint8_t type, blksz = grub_zfs_to_cpu16 (mdn->dn.dn_datablkszsec, mdn->endian) << SPA_MINBLOCKSHIFT; epbs = zfs_log2 (blksz) - DNODE_SHIFT; + + /* While this should never happen, we should check that epbs is not negative. */ + if (epbs < 0) + epbs = 0; + blkid = objnum >> epbs; idx = objnum & ((1 << epbs) - 1);