nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0370-zfs-Fix-possible-integer-overflows.patch

b1bcb2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
b1bcb2
From: Darren Kenny <darren.kenny@oracle.com>
b1bcb2
Date: Tue, 8 Dec 2020 22:17:04 +0000
b1bcb2
Subject: [PATCH] zfs: Fix possible integer overflows
b1bcb2
b1bcb2
In all cases the problem is that the value being acted upon by
b1bcb2
a left-shift is a 32-bit number which is then being used in the
b1bcb2
context of a 64-bit number.
b1bcb2
b1bcb2
To avoid overflow we ensure that the number being shifted is 64-bit
b1bcb2
before the shift is done.
b1bcb2
b1bcb2
Fixes: CID 73684, CID 73695, CID 73764
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 | 8 ++++----
b1bcb2
 1 file changed, 4 insertions(+), 4 deletions(-)
b1bcb2
b1bcb2
diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c
b1bcb2
index 467fa7ee9ea..4fe09b4c10c 100644
b1bcb2
--- a/grub-core/fs/zfs/zfs.c
b1bcb2
+++ b/grub-core/fs/zfs/zfs.c
b1bcb2
@@ -560,7 +560,7 @@ find_bestub (uberblock_phys_t * ub_array,
b1bcb2
       ubptr = (uberblock_phys_t *) ((grub_properly_aligned_t *) ub_array
b1bcb2
 				    + ((i << ub_shift)
b1bcb2
 				       / sizeof (grub_properly_aligned_t)));
b1bcb2
-      err = uberblock_verify (ubptr, offset, 1 << ub_shift);
b1bcb2
+      err = uberblock_verify (ubptr, offset, (grub_size_t) 1 << ub_shift);
b1bcb2
       if (err)
b1bcb2
 	{
b1bcb2
 	  grub_errno = GRUB_ERR_NONE;
b1bcb2
@@ -1535,7 +1535,7 @@ read_device (grub_uint64_t offset, struct grub_zfs_device_desc *desc,
b1bcb2
 
b1bcb2
 	    high = grub_divmod64 ((offset >> desc->ashift) + c,
b1bcb2
 				  desc->n_children, &devn);
b1bcb2
-	    csize = bsize << desc->ashift;
b1bcb2
+	    csize = (grub_size_t) bsize << desc->ashift;
b1bcb2
 	    if (csize > len)
b1bcb2
 	      csize = len;
b1bcb2
 
b1bcb2
@@ -1627,8 +1627,8 @@ read_device (grub_uint64_t offset, struct grub_zfs_device_desc *desc,
b1bcb2
 
b1bcb2
 	    while (len > 0)
b1bcb2
 	      {
b1bcb2
-		grub_size_t csize;
b1bcb2
-		csize = ((s / (desc->n_children - desc->nparity))
b1bcb2
+		grub_size_t csize = s;
b1bcb2
+		csize = ((csize / (desc->n_children - desc->nparity))
b1bcb2
 			 << desc->ashift);
b1bcb2
 		if (csize > len)
b1bcb2
 		  csize = len;