Skip to contentSkip to conversation

bring initial context to a known state

PATCH In review Robert Millan 2 participants 3 messages Oct 7, 2007 – Oct 15, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bring initial context to a known state

When GRUB starts initial_context is in an unknown state. This can lead to GRUB detecting bogus variables from it. Attached patch zeroes that struct during initialisation to avoid that.

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 /.)

2007-10-07 Robert Millan <[email protected]>

* kern/env.c (grub_env_init): New function. Set initial_context struct to zero.
* kern/main.c (grub_main): Call grub_env_init() after grub_machine_init().

kern/env.c +7 -0
diff -ur grub2/kern/env.c grub2.env_init/kern/env.c
@@ -47,6 +47,13 @@
 /* The current context.  */
 static struct grub_env_context *current_context = &initial_context;
 
+/* Bring initial context to a known state.  */
+void
+grub_env_init ()
+{
+  grub_memset (&initial_context, 0, sizeof(initial_context));
+}
+
 /* Return the hash representation of the string S.  */
 static unsigned int
 grub_env_hashval (const char *s)
kern/main.c +3 -0
diff -ur grub2/kern/main.c grub2.env_init/kern/main.c
@@ -112,6 +112,9 @@
   /* First of all, initialize the machine.  */
   grub_machine_init ();
 
+  /* Initialize context.  */
+  grub_env_init ();
+
   /* Hello.  */
   grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
   grub_printf ("Welcome to GRUB!\n\n");
#1 lore raw

Hell[o]

Quoted 3 lines

When GRUB starts initial_context is in an unknown state. This can lead to GRUB detecting bogus variables from it. Attached patch zeroes that struct during initialisation to avoid that.

This change broken command line argument handling for ieee1275. Arguments are read by grub_machine_init() in this case and zeroing is done just after that.

I guess it should be placed before grub_machine_init() to avoid this problem.

Signature · 1 line
--- Marcin 'Morgoth' Kurek ---
#2 lore raw
Quoted 11 lines · Marcin Kurek

Hell[o]

Quoted 3 lines

When GRUB starts initial_context is in an unknown state. This can lead to GRUB detecting bogus variables from it. Attached patch zeroes that struct during initialisation to avoid that.

This change broken command line argument handling for ieee1275. Arguments are read by grub_machine_init() in this case and zeroing is done just after that.

I guess it should be placed before grub_machine_init() to avoid this problem.

Uhm.. Marco pointed out that it's in the ELF standard that memory is zeroed before load. So there isn't really a problem, and my issue was just found in an inconsistent situation when playing with LB self-boot.

Let's kill this thread.

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 /.)