Skip to contentSkip to conversation

x86/compressed: remove unnecessary check

PATCH In review Alexander Kuleshov 2 participants 3 messages Feb 20, 2015 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/compressed: remove unnecessary check

region.start is entry->addr, but we already did check for case when entry->addr + entry->size < minimum, so no need to check that region.start is less than minimum.

---
 arch/x86/boot/compressed/aslr.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
arch/x86/boot/compressed/aslr.c +1 -5
index bb13763..13424a9 100644
@@ -249,11 +249,7 @@ static void process_e820_entry(struct e820entry *entry,
 
 	region.start = entry->addr;
 	region.size = entry->size;
-
-	/* Potentially raise address to minimum location. */
-	if (region.start < minimum)
-		region.start = minimum;
-
+ 
 	/* Potentially raise address to meet alignment requirements. */
 	region.start = ALIGN(region.start, CONFIG_PHYSICAL_ALIGN);
 
Signature · 1 line
2.3.0.80.g18d0fec
#1 lore raw
Quoted 3 lines · Alexander Kuleshov

region.start is entry->addr, but we already did check for case when entry->addr + entry->size < minimum, so no need to check that region.start is less than minimum.

Nope, that's not correct. Those are separate checks. For example, a region 20..130 would be seen as:

start = 20
size = 110

With minimum = 50, the first check eliminates anything with size <= 30 (since the region would be entirely (20...50) below the minimum).

The second check (the one you're suggesting to remove) raises the bottom of the region up to the minimum:

start = 50

And later on ("Reduce size by any delta from the original address."), the size is also adjusted to notice any changes:

size = 80

Now the region is 50...130: the bottom is cut off to adapt to the minimum location.

Is there some situation you found where this logic isn't working?

-Kees

Quoted 26 lines
---
 arch/x86/boot/compressed/aslr.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
arch/x86/boot/compressed/aslr.c +1 -6
index bb13763..13424a9 100644
@@ -249,11 +249,7 @@ static void process_e820_entry(struct e820entry *entry,
 
        region.start = entry->addr;
        region.size = entry->size;
-
-       /* Potentially raise address to minimum location. */
-       if (region.start < minimum)
-               region.start = minimum;
-
+
        /* Potentially raise address to meet alignment requirements. */
        region.start = ALIGN(region.start, CONFIG_PHYSICAL_ALIGN);
 
--

2.3.0.80.g18d0fec

Signature · 2 lines
Kees Cook
Chrome OS Security
#2 lore raw

Hello Kees,

yes you're fully right.

sorry for noise.

2015-02-21 0:38 GMT+06:00 Kees Cook <[email protected]>:

Quoted 64 lines
Quoted 3 lines · Alexander Kuleshov

region.start is entry->addr, but we already did check for case when entry->addr + entry->size < minimum, so no need to check that region.start is less than minimum.

Nope, that's not correct. Those are separate checks. For example, a region 20..130 would be seen as:

start = 20
size = 110

With minimum = 50, the first check eliminates anything with size <= 30 (since the region would be entirely (20...50) below the minimum).

The second check (the one you're suggesting to remove) raises the bottom of the region up to the minimum:

start = 50

And later on ("Reduce size by any delta from the original address."), the size is also adjusted to notice any changes:

size = 80

Now the region is 50...130: the bottom is cut off to adapt to the minimum location.

Is there some situation you found where this logic isn't working?

-Kees

Quoted 24 lines
---
 arch/x86/boot/compressed/aslr.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
arch/x86/boot/compressed/aslr.c +1 -6
index bb13763..13424a9 100644
@@ -249,11 +249,7 @@ static void process_e820_entry(struct e820entry *entry,
 
        region.start = entry->addr;
        region.size = entry->size;
-
-       /* Potentially raise address to minimum location. */
-       if (region.start < minimum)
-               region.start = minimum;
-
+
        /* Potentially raise address to meet alignment requirements. */
        region.start = ALIGN(region.start, CONFIG_PHYSICAL_ALIGN);
 
--
Quoted 2 lines

2.3.0.80.g18d0fec

--
Kees Cook
Chrome OS Security

Signature · 2 lines
_________________________
0xAX