Skip to contentSkip to conversation

Dell Dimension 8300 reboots when grub2 cbfs module is loaded

PATCH Andrei Borzenkov 5 participants 11 messages Nov 1, 2015 – Nov 4, 2015

lore
Share & tools
lore
#0 lore raw

I was debugging problem reported by user on Dell Dimension 8300 - it rebooted when doing "ls -l". It turned out, the problem was triggered by loading cbfs which probed for header. System has 2GB memory, and attempt to read from address 0xffffffff caused instant reboot. 0xffffffff was returned by read from non-existing address 0xfffffffc.

The proof of concept patch below avoids it, but I wonder what the proper fix is.

grub-core/fs/cbfs.c +2 -1
index a34eb88..a5a2fde 100644
@@ -344,8 +344,9 @@ init_cbfsdisk (void)
 
   ptr = *(grub_uint32_t *) 0xfffffffc;
   head = (struct cbfs_header *) (grub_addr_t) ptr;
+  grub_dprintf ("cbfs", "head=%p\n", head);
 
-  if (!validate_head (head))
+  if (0xffffffff - ptr < sizeof (*head) || !validate_head (head))
     return;
 
   cbfsdisk_size = ALIGN_UP (grub_be_to_cpu32 (head->romsize),
#1 lore raw

The code itself looks good but I'd like more details. Reading 0xffffffff shouldn't cause reboot. Why does it?

Quoted 31 lines · Andrei Borzenkov

I was debugging problem reported by user on Dell Dimension 8300 - it rebooted when doing "ls -l". It turned out, the problem was triggered by loading cbfs which probed for header. System has 2GB memory, and attempt to read from address 0xffffffff caused instant reboot. 0xffffffff was returned by read from non-existing address 0xfffffffc.

The proof of concept patch below avoids it, but I wonder what the proper fix is.

grub-core/fs/cbfs.c +2 -1
index a34eb88..a5a2fde 100644
@@ -344,8 +344,9 @@ init_cbfsdisk (void)
 
   ptr = *(grub_uint32_t *) 0xfffffffc;
   head = (struct cbfs_header *) (grub_addr_t) ptr;
+  grub_dprintf ("cbfs", "head=%p\n", head);
 
-  if (!validate_head (head))
+  if (0xffffffff - ptr < sizeof (*head) || !validate_head (head))
     return;
 
   cbfsdisk_size = ALIGN_UP (grub_be_to_cpu32 (head->romsize),

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw

03.11.2015 19:28, Vladimir 'phcoder' Serbinenko пишет:

Quoted 2 lines

The code itself looks good but I'd like more details. Reading 0xffffffff shouldn't cause reboot. Why does it?

That I do not know nor do I have access to system in question myself. I sent user patch that modified validate_header to do each comparison as individual statement and did line by line debug print (fortunately it was possible to connect serial port and capture output) and the last line printed was immediately before the very first

head->magic == grub_cpu_to_be32_compile_time (CBFS_HEADER_MAGIC

I suppose reading *one* byte from 0xffffffff should not cause issues but here we are reading 4 bytes which are beyond 0xffffffff. Who knows what memory controller in this system does in this case.

Quoted 41 lines · Andrei Borzenkov
Quoted 27 lines

I was debugging problem reported by user on Dell Dimension 8300 - it rebooted when doing "ls -l". It turned out, the problem was triggered by loading cbfs which probed for header. System has 2GB memory, and attempt to read from address 0xffffffff caused instant reboot. 0xffffffff was returned by read from non-existing address 0xfffffffc.

The proof of concept patch below avoids it, but I wonder what the proper fix is.

grub-core/fs/cbfs.c +2 -1
index a34eb88..a5a2fde 100644
@@ -344,8 +344,9 @@ init_cbfsdisk (void)
 
    ptr = *(grub_uint32_t *) 0xfffffffc;
    head = (struct cbfs_header *) (grub_addr_t) ptr;
+  grub_dprintf ("cbfs", "head=%p\n", head);
 
-  if (!validate_head (head))
+  if (0xffffffff - ptr < sizeof (*head) || !validate_head (head))
      return;
 
    cbfsdisk_size = ALIGN_UP (grub_be_to_cpu32 (head->romsize),
Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#3 lore raw

Which platform is it? i386-pc, i386-efi or x86_64-efi? The behavior is actually will defined, just different between cpu modes

Quoted 68 lines · Andrei Borzenkov

03.11.2015 19:28, Vladimir 'phcoder' Serbinenko пишет:

Quoted 3 lines

The code itself looks good but I'd like more details. Reading 0xffffffff shouldn't cause reboot. Why does it?

That I do not know nor do I have access to system in question myself. I sent user patch that modified validate_header to do each comparison as individual statement and did line by line debug print (fortunately it was possible to connect serial port and capture output) and the last line printed was immediately before the very first

head->magic == grub_cpu_to_be32_compile_time (CBFS_HEADER_MAGIC

I suppose reading *one* byte from 0xffffffff should not cause issues but here we are reading 4 bytes which are beyond 0xffffffff. Who knows what memory controller in this system does in this case.

Quoted 29 lines · Andrei Borzenkov

I was debugging problem reported by user on Dell Dimension 8300 - it

Quoted 27 lines

rebooted when doing "ls -l". It turned out, the problem was triggered by loading cbfs which probed for header. System has 2GB memory, and attempt to
read from address 0xffffffff caused instant reboot. 0xffffffff was returned
by read from non-existing address 0xfffffffc.

The proof of concept patch below avoids it, but I wonder what the proper fix is.

grub-core/fs/cbfs.c +2 -1
index a34eb88..a5a2fde 100644
@@ -344,8 +344,9 @@ init_cbfsdisk (void)
 
    ptr = *(grub_uint32_t *) 0xfffffffc;
    head = (struct cbfs_header *) (grub_addr_t) ptr;
+  grub_dprintf ("cbfs", "head=%p\n", head);
 
-  if (!validate_head (head))
+  if (0xffffffff - ptr < sizeof (*head) || !validate_head (head))
      return;
 
    cbfsdisk_size = ALIGN_UP (grub_be_to_cpu32 (head->romsize),
Quoted 14 lines
Quoted 6 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#4 lore raw

03.11.2015 20:10, Vladimir 'phcoder' Serbinenko пишет:

Quoted 2 lines

Which platform is it? i386-pc, i386-efi or x86_64-efi? The behavior is actually will defined, just different between cpu modes

i386-pc

Quoted 78 lines · Andrei Borzenkov
Quoted 64 lines

03.11.2015 19:28, Vladimir 'phcoder' Serbinenko пишет:

Quoted 3 lines

The code itself looks good but I'd like more details. Reading 0xffffffff shouldn't cause reboot. Why does it?

That I do not know nor do I have access to system in question myself. I sent user patch that modified validate_header to do each comparison as individual statement and did line by line debug print (fortunately it was possible to connect serial port and capture output) and the last line printed was immediately before the very first

head->magic == grub_cpu_to_be32_compile_time (CBFS_HEADER_MAGIC

I suppose reading *one* byte from 0xffffffff should not cause issues but here we are reading 4 bytes which are beyond 0xffffffff. Who knows what memory controller in this system does in this case.

Quoted 29 lines · Andrei Borzenkov

I was debugging problem reported by user on Dell Dimension 8300 - it

Quoted 27 lines

rebooted when doing "ls -l". It turned out, the problem was triggered by loading cbfs which probed for header. System has 2GB memory, and attempt to
read from address 0xffffffff caused instant reboot. 0xffffffff was returned
by read from non-existing address 0xfffffffc.

The proof of concept patch below avoids it, but I wonder what the proper fix is.

grub-core/fs/cbfs.c +2 -1
index a34eb88..a5a2fde 100644
@@ -344,8 +344,9 @@ init_cbfsdisk (void)
 
     ptr = *(grub_uint32_t *) 0xfffffffc;
     head = (struct cbfs_header *) (grub_addr_t) ptr;
+  grub_dprintf ("cbfs", "head=%p\n", head);
 
-  if (!validate_head (head))
+  if (0xffffffff - ptr < sizeof (*head) || !validate_head (head))
       return;
 
     cbfsdisk_size = ALIGN_UP (grub_be_to_cpu32 (head->romsize),
Quoted 14 lines
Quoted 6 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#5 lore raw

03.11.2015 20:14, Andrei Borzenkov пишет:

Quoted 6 lines

03.11.2015 20:10, Vladimir 'phcoder' Serbinenko пишет:

Quoted 2 lines

Which platform is it? i386-pc, i386-efi or x86_64-efi? The behavior is actually will defined, just different between cpu modes

i386-pc

BTW here are specs from Dell site

Intel® Pentium® 4 microprocessor (2.4, 2.6, 2.8, 3.0, 3.2, and 3.4 for 800 FSB, and 2.4, 2.66, 2.8, and 3.06 for 533 FSB)

4GB max memory

Intel 875P chipset

Quoted 86 lines
Quoted 85 lines

Le 3 nov. 2015 6:08 PM, "Andrei Borzenkov" <[email protected]> a écrit :

Quoted 69 lines

03.11.2015 19:28, Vladimir 'phcoder' Serbinenko пишет:

Quoted 4 lines

The code itself looks good but I'd like more details. Reading 0xffffffff
shouldn't cause reboot. Why does it?

That I do not know nor do I have access to system in question myself. I sent user patch that modified validate_header to do each comparison as individual statement and did line by line debug print (fortunately it was
possible to connect serial port and capture output) and the last line printed was immediately before the very first

head->magic == grub_cpu_to_be32_compile_time (CBFS_HEADER_MAGIC

I suppose reading *one* byte from 0xffffffff should not cause issues but here we are reading 4 bytes which are beyond 0xffffffff. Who knows what memory controller in this system does in this case.

Le 1 nov. 2015 3:53 PM, "Andrei Borzenkov" <[email protected]> a écrit :

Quoted 32 lines

I was debugging problem reported by user on Dell Dimension 8300 - it

Quoted 30 lines

rebooted when doing "ls -l". It turned out, the problem was triggered by
loading cbfs which probed for header. System has 2GB memory, and attempt
to
read from address 0xffffffff caused instant reboot. 0xffffffff was returned
by read from non-existing address 0xfffffffc.

The proof of concept patch below avoids it, but I wonder what the proper
fix is.

grub-core/fs/cbfs.c +2 -1
index a34eb88..a5a2fde 100644
@@ -344,8 +344,9 @@ init_cbfsdisk (void)
 
     ptr = *(grub_uint32_t *) 0xfffffffc;
     head = (struct cbfs_header *) (grub_addr_t) ptr;
+  grub_dprintf ("cbfs", "head=%p\n", head);
 
-  if (!validate_head (head))
+  if (0xffffffff - ptr < sizeof (*head) || !validate_head (head))
       return;
 
     cbfsdisk_size = ALIGN_UP (grub_be_to_cpu32 (head->romsize),
Quoted 14 lines
Quoted 6 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#8 lore raw
In reply to Andrei Borzenkov

Thanks Andrei,

Vladimir, what do you think?

Martin

Quoted 29 lines · Andrei Borzenkov

I was debugging problem reported by user on Dell Dimension 8300 - it rebooted when doing "ls -l". It turned out, the problem was triggered by loading cbfs which probed for header. System has 2GB memory, and attempt to read from address 0xffffffff caused instant reboot. 0xffffffff was returned by read from non-existing address 0xfffffffc.

The proof of concept patch below avoids it, but I wonder what the proper fix is.

grub-core/fs/cbfs.c +2 -2
index a34eb88..a5a2fde 100644
@@ -344,8 +344,9 @@ init_cbfsdisk (void)
 
   ptr = *(grub_uint32_t *) 0xfffffffc;
   head = (struct cbfs_header *) (grub_addr_t) ptr;
+  grub_dprintf ("cbfs", "head=%p\n", head);
 
-  if (!validate_head (head))
+  if (0xffffffff - ptr < sizeof (*head) || !validate_head (head))
     return;
 
   cbfsdisk_size = ALIGN_UP (grub_be_to_cpu32 (head->romsize),
 
 
--

coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

#7 lore raw
In reply to Aaron Durbin
Quoted 10 lines · Aaron Durbin
Quoted 2 lines · Vladimir 'phcoder' Serbinenko

The code itself looks good but I'd like more details. Reading 0xffffffff shouldn't cause reboot. Why does it?

It's probably implementation defined reading a multi-byte object from 4GiB-1. Does it wrap? Blow up the machine? Machine check? Transaction never gets terminated?

It would be interesting to find out. Since it's P4, it may be related to PAE but paging is disabled when GRUB is active However it shouldn't hold this patch. Andrei: go ahead, just please add reference to machine and cpu in the comment and the fact that we have little idea what's going on.

Quoted 2 lines
Quoted 2 lines

Le 1 nov. 2015 3:53 PM, "Andrei Borzenkov" <[email protected]> a

écrit :

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I was debugging problem reported by user on Dell Dimension 8300 - it rebooted when doing "ls -l". It turned out, the problem was triggered

by

Quoted 1 line
Quoted 1 line
Quoted 1 line

loading cbfs which probed for header. System has 2GB memory, and

attempt to

Quoted 1 line
Quoted 1 line
Quoted 1 line

read from address 0xffffffff caused instant reboot. 0xffffffff was

returned

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

by read from non-existing address 0xfffffffc.

The proof of concept patch below avoids it, but I wonder what the

proper

Quoted 28 lines
Quoted 28 lines
Quoted 19 lines

fix is.

grub-core/fs/cbfs.c +2 -1
index a34eb88..a5a2fde 100644
@@ -344,8 +344,9 @@ init_cbfsdisk (void)
 
   ptr = *(grub_uint32_t *) 0xfffffffc;
   head = (struct cbfs_header *) (grub_addr_t) ptr;
+  grub_dprintf ("cbfs", "head=%p\n", head);
 
-  if (!validate_head (head))
+  if (0xffffffff - ptr < sizeof (*head) || !validate_head (head))
     return;
 
   cbfsdisk_size = ALIGN_UP (grub_be_to_cpu32 (head->romsize),
Quoted 4 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

--
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

#6 lore raw
In reply to Vladimir 'phcoder' Serbinenko
Quoted 2 lines · Vladimir 'phcoder' Serbinenko

The code itself looks good but I'd like more details. Reading 0xffffffff shouldn't cause reboot. Why does it?

It's probably implementation defined reading a multi-byte object from 4GiB-1. Does it wrap? Blow up the machine? Machine check? Transaction never gets terminated?

Quoted 38 lines · Andrei Borzenkov
Quoted 27 lines

I was debugging problem reported by user on Dell Dimension 8300 - it rebooted when doing "ls -l". It turned out, the problem was triggered by loading cbfs which probed for header. System has 2GB memory, and attempt to read from address 0xffffffff caused instant reboot. 0xffffffff was returned by read from non-existing address 0xfffffffc.

The proof of concept patch below avoids it, but I wonder what the proper fix is.

grub-core/fs/cbfs.c +2 -1
index a34eb88..a5a2fde 100644
@@ -344,8 +344,9 @@ init_cbfsdisk (void)
 
   ptr = *(grub_uint32_t *) 0xfffffffc;
   head = (struct cbfs_header *) (grub_addr_t) ptr;
+  grub_dprintf ("cbfs", "head=%p\n", head);
 
-  if (!validate_head (head))
+  if (0xffffffff - ptr < sizeof (*head) || !validate_head (head))
     return;
 
   cbfsdisk_size = ALIGN_UP (grub_be_to_cpu32 (head->romsize),
Quoted 4 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

--
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

#9 lore raw
In reply to Andrei Borzenkov

Hi Andrei,

your patch looks good generally, but the check is off by one. It's obvious, we want to have sane checking there. Reading from a random address can cause trouble and 0xffffffff is not the only offending address.

On x86, the cbfs is mapped right below the 4GiB line. Current machines don't have more than 16MiB space for cbfs, FWIW. So maybe it's best to check if the ptr points somewhere between 0xff000000 and (0x100000000 - sizeof(*head)).

Nico

Quoted 26 lines · Andrei Borzenkov

I was debugging problem reported by user on Dell Dimension 8300 - it rebooted when doing "ls -l". It turned out, the problem was triggered by loading cbfs which probed for header. System has 2GB memory, and attempt to read from address 0xffffffff caused instant reboot. 0xffffffff was returned by read from non-existing address 0xfffffffc.

The proof of concept patch below avoids it, but I wonder what the proper fix is.

grub-core/fs/cbfs.c +2 -1
index a34eb88..a5a2fde 100644
@@ -344,8 +344,9 @@ init_cbfsdisk (void)
 
   ptr = *(grub_uint32_t *) 0xfffffffc;
   head = (struct cbfs_header *) (grub_addr_t) ptr;
+  grub_dprintf ("cbfs", "head=%p\n", head);
 
-  if (!validate_head (head))
+  if (0xffffffff - ptr < sizeof (*head) || !validate_head (head))
     return;
 
   cbfsdisk_size = ALIGN_UP (grub_be_to_cpu32 (head->romsize),
#10 lore raw

04.11.2015 00:41, Nico Huber пишет:

Quoted 3 lines

Hi Andrei,

your patch looks good generally, but the check is off by one. It's

Yes, but it should not matter in real life. Last 4 bytes are pointer, so header cannot start after 0xffffffdc anyway. I'll change it.

Quoted 9 lines

obvious, we want to have sane checking there. Reading from a random address can cause trouble and 0xffffffff is not the only offending address.

On x86, the cbfs is mapped right below the 4GiB line. Current machines don't have more than 16MiB space for cbfs, FWIW. So maybe it's best to check if the ptr points somewhere between 0xff000000 and (0x100000000 - sizeof(*head)).

That's far exceeds my intention and knowledge, sorry.

Quoted 29 lines

Nico

Quoted 26 lines · Andrei Borzenkov

I was debugging problem reported by user on Dell Dimension 8300 - it rebooted when doing "ls -l". It turned out, the problem was triggered by loading cbfs which probed for header. System has 2GB memory, and attempt to read from address 0xffffffff caused instant reboot. 0xffffffff was returned by read from non-existing address 0xfffffffc.

The proof of concept patch below avoids it, but I wonder what the proper fix is.

grub-core/fs/cbfs.c +2 -1
index a34eb88..a5a2fde 100644
@@ -344,8 +344,9 @@ init_cbfsdisk (void)
 
    ptr = *(grub_uint32_t *) 0xfffffffc;
    head = (struct cbfs_header *) (grub_addr_t) ptr;
+  grub_dprintf ("cbfs", "head=%p\n", head);
 
-  if (!validate_head (head))
+  if (0xffffffff - ptr < sizeof (*head) || !validate_head (head))
      return;
 
    cbfsdisk_size = ALIGN_UP (grub_be_to_cpu32 (head->romsize),