Skip to contentSkip to conversation

safety check in claim_heap()

PATCH In review Robert Millan 2 participants 5 messages Jan 20, 2008 – Jan 22, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 safety check in claim_heap()

Hi!

What do you think of adding this kind of checks? I know it's not a perfect safegard, but it can save your day in some situations (it helped me during i386/ieee1275 port, when link address was 0x100000).

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
powerpc/ieee1275/init.c renamed from ../grub2/kern/powerpc/ieee1275/init.c +11 -0
@@ -143,6 +143,17 @@
         (total + (HEAP_MAX_ADDR - addr) > HEAP_MIN_SIZE))	/* only limit ourselves when we can afford to */
        len = HEAP_MAX_ADDR - addr;
 
+    /* In theory, firmware should already prevent this from happening by not
+       listing our own image in /memory/available.  The check below is intended
+       as a safegard in case that doesn't happen.  It does, however, not protect
+       us from corrupting our module area, which extends up to a
+       yet-undetermined region above _end.  */
+    if ((addr < _end) && ((addr + len) > _start))
+      {
+        grub_printf ("Warning: attempt to claim over our own code!\n");
+        len = 0;
+      }
+
     if (len)
       {
 	/* Claim and use it.  */
#1 lore raw

Robert Millan <[email protected]> writes:

Hi,

Quoted 3 lines

What do you think of adding this kind of checks? I know it's not a perfect safegard, but it can save your day in some situations (it helped me during i386/ieee1275 port, when link address was 0x100000).

If this fixes the i386-ieee1275 port, this is fine to me.

--
Marco

#2 lore raw
Quoted 9 lines · Marco Gerards

Robert Millan <[email protected]> writes:

Hi,

Quoted 3 lines

What do you think of adding this kind of checks? I know it's not a perfect safegard, but it can save your day in some situations (it helped me during i386/ieee1275 port, when link address was 0x100000).

If this fixes the i386-ieee1275 port, this is fine to me.

It isn't currently needed by either of the i386-ieee1275 targets (qemu and xo).

However, it was during an earlier stage of the port in which link address was 0x100000 rather than 0x10000.

My question is whether it makes sense as a general safety check.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#3 lore raw
Quoted 11 lines · Robert Millan
Quoted 9 lines · Marco Gerards

Robert Millan <[email protected]> writes:

Hi,

Quoted 3 lines

What do you think of adding this kind of checks? I know it's not a perfect safegard, but it can save your day in some situations (it helped me during i386/ieee1275 port, when link address was 0x100000).

If this fixes the i386-ieee1275 port, this is fine to me.

Quoted 7 lines

It isn't currently needed by either of the i386-ieee1275 targets (qemu and xo).

However, it was during an earlier stage of the port in which link address was 0x100000 rather than 0x10000.

My question is whether it makes sense as a general safety check.

Well, if it isn't going to occur with the current firmware implementations, I do not see the use. But it will not hurt either. Simply, I do not care either way... I leave this up to you ;-)

--
Marco

#4 lore raw
Quoted 5 lines · Marco Gerards
Quoted 1 line

My question is whether it makes sense as a general safety check.

Well, if it isn't going to occur with the current firmware implementations, I do not see the use. But it will not hurt either. Simply, I do not care either way... I leave this up to you ;-)

Ok, I checked that in.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)