diff options
Diffstat (limited to 'meta/recipes-bsp/grub/files/0021-zfs-Fix-possible-negative-shift-operation.patch')
-rw-r--r-- | meta/recipes-bsp/grub/files/0021-zfs-Fix-possible-negative-shift-operation.patch | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/meta/recipes-bsp/grub/files/0021-zfs-Fix-possible-negative-shift-operation.patch b/meta/recipes-bsp/grub/files/0021-zfs-Fix-possible-negative-shift-operation.patch new file mode 100644 index 0000000000..12418858f9 --- /dev/null +++ b/meta/recipes-bsp/grub/files/0021-zfs-Fix-possible-negative-shift-operation.patch | |||
@@ -0,0 +1,42 @@ | |||
1 | From c757779e5d09719666c3b155afd2421978a107bd Mon Sep 17 00:00:00 2001 | ||
2 | From: Darren Kenny <darren.kenny@oracle.com> | ||
3 | Date: Tue, 24 Nov 2020 16:41:49 +0000 | ||
4 | Subject: [PATCH] zfs: Fix possible negative shift operation | ||
5 | |||
6 | While it is possible for the return value from zfs_log2() to be zero | ||
7 | (0), it is quite unlikely, given that the previous assignment to blksz | ||
8 | is shifted up by SPA_MINBLOCKSHIFT (9) before 9 is subtracted at the | ||
9 | assignment to epbs. | ||
10 | |||
11 | But, while unlikely during a normal operation, it may be that a carefully | ||
12 | crafted ZFS filesystem could result in a zero (0) value to the | ||
13 | dn_datalbkszsec field, which means that the shift left does nothing | ||
14 | and assigns zero (0) to blksz, resulting in a negative epbs value. | ||
15 | |||
16 | Fixes: CID 73608 | ||
17 | |||
18 | Signed-off-by: Darren Kenny <darren.kenny@oracle.com> | ||
19 | Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> | ||
20 | |||
21 | Upstream-Status: Backport [https://git.savannah.gnu.org/cgit/grub.git/commit/?id=a02091834d3e167320d8a262ff04b8e83c5e616d] | ||
22 | Signed-off-by: Marta Rybczynska <marta.rybczynska@huawei.com> | ||
23 | --- | ||
24 | grub-core/fs/zfs/zfs.c | 5 +++++ | ||
25 | 1 file changed, 5 insertions(+) | ||
26 | |||
27 | diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c | ||
28 | index 36d0373..0c42cba 100644 | ||
29 | --- a/grub-core/fs/zfs/zfs.c | ||
30 | +++ b/grub-core/fs/zfs/zfs.c | ||
31 | @@ -2667,6 +2667,11 @@ dnode_get (dnode_end_t * mdn, grub_uint64_t objnum, grub_uint8_t type, | ||
32 | blksz = grub_zfs_to_cpu16 (mdn->dn.dn_datablkszsec, | ||
33 | mdn->endian) << SPA_MINBLOCKSHIFT; | ||
34 | epbs = zfs_log2 (blksz) - DNODE_SHIFT; | ||
35 | + | ||
36 | + /* While this should never happen, we should check that epbs is not negative. */ | ||
37 | + if (epbs < 0) | ||
38 | + epbs = 0; | ||
39 | + | ||
40 | blkid = objnum >> epbs; | ||
41 | idx = objnum & ((1 << epbs) - 1); | ||
42 | |||