Skip to contentSkip to conversation

lib/relocator: Fix OOB write when initializing lo->freebytes[]

PATCH In review Daniel Kiper 2 participants 2 messages Jun 22, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/relocator: Fix OOB write when initializing lo->freebytes[]

Fixes CID 96636
---
 grub-core/lib/relocator.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
grub-core/lib/relocator.c +5 -3
index 568fc0b8f..e0478ae5b 100644
@@ -881,9 +881,11 @@ malloc_in_range (struct grub_relocator *rel,
 			offend = GRUB_RELOCATOR_FIRMWARE_REQUESTS_QUANT;
 		      lo->freebytes[offstart / 8]
 			&= ((1 << (8 - (start % 8))) - 1);
-		      grub_memset (lo->freebytes + (offstart + 7) / 8, 0,
-				   offend / 8 - (offstart + 7) / 8);
-		      lo->freebytes[offend / 8] &= ~((1 << (offend % 8)) - 1);
+		      if (offend / 8 > (offstart + 7) / 8)
+			grub_memset (lo->freebytes + (offstart + 7) / 8, 0,
+				     offend / 8 - (offstart + 7) / 8);
+		      if (offend < GRUB_RELOCATOR_FIRMWARE_REQUESTS_QUANT)
+			lo->freebytes[offend / 8] &= ~((1 << (offend % 8)) - 1);
 		    }
 		    break;
 #endif
Signature · 1 line
2.11.0
#1 lore raw

Reviewedby: Vladimir Serbinenko <[email protected]>

Le ven. 23 juin 2023, 00:09, Daniel Kiper <[email protected]> a écrit :

Quoted 32 lines
Fixes CID 96636
---
 grub-core/lib/relocator.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
grub-core/lib/relocator.c +5 -5
index 568fc0b8f..e0478ae5b 100644
@@ -881,9 +881,11 @@ malloc_in_range (struct grub_relocator *rel,
                        offend = GRUB_RELOCATOR_FIRMWARE_REQUESTS_QUANT;
                      lo->freebytes[offstart / 8]
                        &= ((1 << (8 - (start % 8))) - 1);
-                     grub_memset (lo->freebytes + (offstart + 7) / 8, 0,
-                                  offend / 8 - (offstart + 7) / 8);
-                     lo->freebytes[offend / 8] &= ~((1 << (offend % 8)) -
 1);
+                     if (offend / 8 > (offstart + 7) / 8)
+                       grub_memset (lo->freebytes + (offstart + 7) / 8, 0,
+                                    offend / 8 - (offstart + 7) / 8);
+                     if (offend < GRUB_RELOCATOR_FIRMWARE_REQUESTS_QUANT)
+                       lo->freebytes[offend / 8] &= ~((1 << (offend % 8))
- 1);
                    }
                    break;
 #endif
--

2.11.0