ieee1275: prevent buffer over-read
PATCH 1/1 ieee1275: prevent buffer over-read
Prevent buffer over-read in grub_machine_mmap_iterate. This was causing phys_base from being calculated properly. This then caused the wrong value to be placed in ramdisk_image within struct linux_hdrs. Which prevented the ramdisk from loading on boot.
Newer SPARC systems contain more than 8 available memory entries.
For example on a T5-8 with 2TB of memory, the memory layout could look like this:
T5-8 Memory
reg 00000000 30000000 0000003f b0000000
00000800 00000000 00000040 00000000
00001000 00000000 00000040 00000000
00001800 00000000 00000040 00000000
00002000 00000000 00000040 00000000
00002800 00000000 00000040 00000000
00003000 00000000 00000040 00000000
00003800 00000000 00000040 00000000
available 00003800 00000000 0000003f ffcae000
00003000 00000000 00000040 00000000
00002800 00000000 00000040 00000000
00002000 00000000 00000040 00000000
00001800 00000000 00000040 00000000
00001000 00000000 00000040 00000000
00000800 00000000 00000040 00000000
00000000 70000000 0000003f 70000000
00000000 6eef8000 00000000 00002000
00000000 30400000 00000000 3eaf6000name memory
--- grub-core/kern/ieee1275/mmap.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
grub-core/kern/ieee1275/mmap.c +4 -1
@@ -25,7 +25,7 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) {grub_ieee1275_phandle_t root;grub_ieee1275_phandle_t memory; -grub_uint32_t available[32 ]; +grub_uint32_t available[64 ];grub_ssize_t available_size;grub_uint32_t address_cells =1 ;grub_uint32_t size_cells =1 ;
@@ -49,6 +49,9 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) sizeof available, &available_size))return grub_error (GRUB_ERR_UNKNOWN_DEVICE ,"couldn't examine /memory/available property" ); +if (available_size >sizeof available) +return grub_error (GRUB_ERR_UNKNOWN_DEVICE , +"/memory response buffer exceeded" );if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS )) {
Signature · 1 line
1.7.1
13.02.2016 03:50, Eric Snowberg пишет:
Quoted 42 lines
Prevent buffer over-read in
grub_machine_mmap_iterate. This was causingphys_basefrom being calculated properly. This then caused the wrong value to be placed inramdisk_imagewithin structlinux_hdrs. Which prevented the ramdisk from loading on boot.Newer SPARC systems contain more than 8 available memory entries.
For example on a T5-8 with 2TB of memory, the memory layout could look like this:
T5-8 Memory
reg 00000000 300000000000003fb000000000000800 00000000 00000040 00000000 00001000 00000000 00000040 00000000 00001800 00000000 00000040 00000000 00002000 00000000 00000040 00000000 00002800 00000000 00000040 00000000 00003000 00000000 00000040 00000000 00003800 00000000 00000040 00000000 available 00003800 00000000 0000003f ffcae000 00003000 00000000 00000040 00000000 00002800 00000000 00000040 00000000 00002000 00000000 00000040 00000000 00001800 00000000 00000040 00000000 00001000 00000000 00000040 00000000 00000800 00000000 00000040 00000000 00000000 70000000 0000003f 70000000 00000000 6eef8000 00000000 00002000 00000000 30400000 00000000 3eaf6000name memory
Signed-off-by Eric Snowberg <[email protected]>--- grub-core/kern/ieee1275/mmap.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)grub-core/kern/ieee1275/mmap.c +0
-0
grub-core/kern/ieee1275/mmap.c grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) · line 28
Quoted 5 lines
grub-core/kern/ieee1275/mmap.c +1
-1@@ -25,7 +25,7 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) {grub_ieee1275_phandle_t root;grub_ieee1275_phandle_t memory; -grub_uint32_t available[32 ]; +grub_uint32_t available[64 ];
Can we make it allocate dynamically according to available_size or is memory allocator not yet initialized at this point?
Quoted 14 lines
grub-core/kern/ieee1275/mmap.c +3
-0grub_ssize_t available_size;grub_uint32_t address_cells =1 ;grub_uint32_t size_cells =1 ;@@ -49,6 +49,9 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) sizeof available, &available_size))return grub_error (GRUB_ERR_UNKNOWN_DEVICE ,"couldn't examine /memory/available property" ); +if (available_size >sizeof available) +return grub_error (GRUB_ERR_UNKNOWN_DEVICE , +"/memory response buffer exceeded" );if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS )) {
On powerpc-ieee1275 we use mmap_iterate to claim heap, so we can't malloc here yet. But can we perhaps have at least 512 bytes fit more robustness?
Le sam. 13 févr. 2016 06:36, Andrei Borzenkov <[email protected]> a écrit :
Quoted 77 lines
13.02.2016 03:50, Eric Snowberg пишет:
Quoted 30 lines
Prevent buffer over-read in
grub_machine_mmap_iterate. This was causingphys_basefrom being calculated properly. This then caused the wrong value to be placed inramdisk_imagewithin structlinux_hdrs. Which prevented the ramdisk from loading on boot.Newer SPARC systems contain more than 8 available memory entries.
For example on a T5-8 with 2TB of memory, the memory layout could look like this:
T5-8 Memory
reg 00000000 300000000000003fb000000000000800 00000000 00000040 00000000 00001000 00000000 00000040 00000000 00001800 00000000 00000040 00000000 00002000 00000000 00000040 00000000 00002800 00000000 00000040 00000000 00003000 00000000 00000040 00000000 00003800 00000000 00000040 00000000 available 00003800 00000000 0000003f ffcae000 00003000 00000000 00000040 00000000 00002800 00000000 00000040 00000000 00002000 00000000 00000040 00000000 00001800 00000000 00000040 00000000 00001000 00000000 00000040 00000000 00000800 00000000 00000040 00000000 00000000 70000000 0000003f 70000000 00000000 6eef8000 00000000 00002000 00000000 30400000 00000000 3eaf6000Review
Quoted 8 lines
name memory
Signed-off-by Eric Snowberg <[email protected]>--- grub-core/kern/ieee1275/mmap.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)(quoted diff) +0
-0
b/grub-core/kern/ieee1275/mmap.cgrub-core/kern/ieee1275/mmap.c grub_machine_mmap_iterate (grub_memory_hook_t hook,
Quoted 4 lines
index 911bb00..8df4e9b 100644
grub-core/kern/ieee1275/mmap.c +0
-0@@ -25,7 +25,7 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook,void
*hook_data)grub-core/kern/ieee1275/mmap.c grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) · line 28
Quoted 5 lines
grub-core/kern/ieee1275/mmap.c +1
-1{grub_ieee1275_phandle_t root;grub_ieee1275_phandle_t memory; -grub_uint32_t available[32 ]; +grub_uint32_t available[64 ];Can we make it allocate dynamically according to
available_sizeor is memory allocator not yet initialized at this point?grub-core/kern/ieee1275/mmap.c grub_machine_mmap_iterate (grub_memory_hook_t hook,
Quoted 4 lines
grub-core/kern/ieee1275/mmap.c +0
-0grub_ssize_t available_size;grub_uint32_t address_cells =1 ;grub_uint32_t size_cells =1 ;@@ -49,6 +49,9 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook,void
*hook_data)grub-core/kern/ieee1275/mmap.c grub_machine_mmap_iterate (grub_memory_hook_t hook, · line 49
Quoted 1 line
grub-core/kern/ieee1275/mmap.c +0
-0sizeof available,
&available_size))grub-core/kern/ieee1275/mmap.c grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) · line 57
Quoted 9 lines
grub-core/kern/ieee1275/mmap.c +3
-0return grub_error (GRUB_ERR_UNKNOWN_DEVICE ,"couldn't examine /memory/available property" ); +if (available_size >sizeof available) +return grub_error (GRUB_ERR_UNKNOWN_DEVICE , +"/memory response buffer exceeded" );if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS )) {_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Le sam. 13 févr. 2016 01:51, Eric Snowberg <[email protected]> a écrit :
Quoted 43 lines
Prevent buffer over-read in
grub_machine_mmap_iterate. This was causingphys_basefrom being calculated properly. This then caused the wrong value to be placed inramdisk_imagewithin structlinux_hdrs. Which prevented the ramdisk from loading on boot.Newer SPARC systems contain more than 8 available memory entries.
For example on a T5-8 with 2TB of memory, the memory layout could look like this:
T5-8 Memory
reg 00000000 300000000000003fb000000000000800 00000000 00000040 00000000 00001000 00000000 00000040 00000000 00001800 00000000 00000040 00000000 00002000 00000000 00000040 00000000 00002800 00000000 00000040 00000000 00003000 00000000 00000040 00000000 00003800 00000000 00000040 00000000 available 00003800 00000000 0000003f ffcae000 00003000 00000000 00000040 00000000 00002800 00000000 00000040 00000000 00002000 00000000 00000040 00000000 00001800 00000000 00000040 00000000 00001000 00000000 00000040 00000000 00000800 00000000 00000040 00000000 00000000 70000000 0000003f 70000000 00000000 6eef8000 00000000 00002000 00000000 30400000 00000000 3eaf6000name memory
Signed-off-by Eric Snowberg <[email protected]>--- grub-core/kern/ieee1275/mmap.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)grub-core/kern/ieee1275/mmap.c +0
-0
grub-core/kern/ieee1275/mmap.c grub_machine_mmap_iterate (grub_memory_hook_t hook, void · line 30
Quoted 7 lines
grub-core/kern/ieee1275/mmap.c +1
-1@@ -25,7 +25,7 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) {grub_ieee1275_phandle_t root;grub_ieee1275_phandle_t memory; -grub_uint32_t available[32 ]; +grub_uint32_t available[64 ];
Please 512 at least so this can lands further down the road
grub-core/kern/ieee1275/mmap.c grub_machine_mmap_iterate (grub_memory_hook_t hook, void · line 55
Quoted 11 lines
grub-core/kern/ieee1275/mmap.c +0
-0grub_ssize_t available_size;grub_uint32_t address_cells = 1; grub_uint32_t size_cells = 1;grub-core/kern/ieee1275/mmap.c +1
-0@@ -49,6 +49,9 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) sizeof available, &available_size))return grub_error (GRUB_ERR_UNKNOWN_DEVICE ,"couldn't examine /memory/available property" ); +if (available_size >sizeof available)
Brackets around available
Quoted 14 lines
grub-core/kern/ieee1275/mmap.c +2
-0+return grub_error (GRUB_ERR_UNKNOWN_DEVICE , +"/memory response buffer exceeded" );if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS)) {--
1.7.1_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 53 lines · Vladimir 'phcoder' Serbinenko
Le sam. 13 févr. 2016 01:51, Eric Snowberg <[email protected]> a écrit :
Prevent buffer over-read ingrub_machine_mmap_iterate. This was causingphys_basefrom being calculated properly. This then
caused the wrong value to be placed inramdisk_imagewithin
structlinux_hdrs. Which prevented the ramdisk from loading on boot.Newer SPARC systems contain more than 8 available memory entries.
For example on a T5-8 with 2TB of memory, the memory layout could look like this:
T5-8 Memory
reg 00000000 300000000000003fb000000000000800 00000000 00000040 00000000 00001000 00000000 00000040 00000000 00001800 00000000 00000040 00000000 00002000 00000000 00000040 00000000 00002800 00000000 00000040 00000000 00003000 00000000 00000040 00000000 00003800 00000000 00000040 00000000 available 00003800 00000000 0000003f ffcae000 00003000 00000000 00000040 00000000 00002800 00000000 00000040 00000000 00002000 00000000 00000040 00000000 00001800 00000000 00000040 00000000 00001000 00000000 00000040 00000000 00000800 00000000 00000040 00000000 00000000 70000000 0000003f 70000000 00000000 6eef8000 00000000 00002000 00000000 30400000 00000000 3eaf6000name memory
Signed-off-by Eric Snowberg <[email protected]>--- grub-core/kern/ieee1275/mmap.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)grub-core/kern/ieee1275/mmap.c +1
-1@@ -25,7 +25,7 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) {grub_ieee1275_phandle_t root;grub_ieee1275_phandle_t memory; -grub_uint32_t available[32 ]; +grub_uint32_t available[64 ];
Quoted 1 line
Please 512 at least so this can lands further down the road
Ok, I’ll change the array to 512
grub-core/kern/ieee1275/mmap.c
Quoted 11 lines
grub_ssize_t available_size; grub_uint32_t address_cells = 1; grub_uint32_t size_cells = 1;grub-core/kern/ieee1275/mmap.c +1
-0@@ -49,6 +49,9 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) sizeof available, &available_size))return grub_error (GRUB_ERR_UNKNOWN_DEVICE ,"couldn't examine /memory/available property" ); +if (available_size >sizeof available)Brackets around available
grub-core/kern/ieee1275/mmap.c +2
-0+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, + "/memory response buffer exceeded”);
And I’ll add the brackets and resubmit
Quoted 11 lines
if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS)) {--
1.7.1_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 46 lines · Eric Snowberg
Quoted 44 lines · Vladimir 'phcoder' Serbinenko
Le sam. 13 févr. 2016 01:51, Eric Snowberg <[email protected]> a écrit :
Prevent buffer over-read ingrub_machine_mmap_iterate. This was causingphys_basefrom being calculated properly. This then
caused the wrong value to be placed inramdisk_imagewithin
structlinux_hdrs. Which prevented the ramdisk from loading on boot.Newer SPARC systems contain more than 8 available memory entries.
For example on a T5-8 with 2TB of memory, the memory layout could look like this:
T5-8 Memory
reg 00000000 300000000000003fb000000000000800 00000000 00000040 00000000 00001000 00000000 00000040 00000000 00001800 00000000 00000040 00000000 00002000 00000000 00000040 00000000 00002800 00000000 00000040 00000000 00003000 00000000 00000040 00000000 00003800 00000000 00000040 00000000 available 00003800 00000000 0000003f ffcae000 00003000 00000000 00000040 00000000 00002800 00000000 00000040 00000000 00002000 00000000 00000040 00000000 00001800 00000000 00000040 00000000 00001000 00000000 00000040 00000000 00000800 00000000 00000040 00000000 00000000 70000000 0000003f 70000000 00000000 6eef8000 00000000 00002000 00000000 30400000 00000000 3eaf6000name memory
Signed-off-by Eric Snowberg <[email protected]>---
grub-core/kern/ieee1275/mmap.c| 5 ++++-1 files changed, 4 insertions(+), 1 deletions(-)
Quoted 13 lines
Quoted 11 lines
grub-core/kern/ieee1275/mmap.c +1
-1@@ -25,7 +25,7 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) {grub_ieee1275_phandle_t root;grub_ieee1275_phandle_t memory; -grub_uint32_t available[32 ]; +grub_uint32_t available[64 ];Please 512 at least so this can lands further down the road
Ok, I’ll change the array to 512
I tested this new patch out with 512, it doesn’t work well with some older OBP versions. I get an error from OBP that I’ve never seen before. I changed it to 128 and this seems to work.
Would you accept 128 instead? If so, I need to test it on some more equipment before sending out the updated patch.
Quoted 32 lines
grub-core/kern/ieee1275/mmap.c
Quoted 12 lines
grub_ssize_t available_size; grub_uint32_t address_cells = 1; grub_uint32_t size_cells = 1;grub-core/kern/ieee1275/mmap.c +1
-0@@ -49,6 +49,9 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data) sizeof available, &available_size))return grub_error (GRUB_ERR_UNKNOWN_DEVICE ,"couldn't examine /memory/available property" ); +if (available_size >sizeof available)Brackets around available
grub-core/kern/ieee1275/mmap.c +2
-0+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, + "/memory response buffer exceeded”);And I’ll add the brackets and resubmit
Quoted 11 lines
if (
grub_ieee1275_test_flag(GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS)){--
1.7.1_______________________________________________
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
Sure, that works.
Le dim. 14 févr. 2016 03:45, Eric Snowberg <[email protected]> a écrit :
Quoted 108 lines
Quoted 2 lines
On Feb 13, 2016, at 9:08 AM, Eric Snowberg <[email protected]>
Quoted 3 lines · wrote:
Quoted 3 lines
On Feb 13, 2016, at 7:05 AM, Vladimir 'phcoder' Serbinenko <
Quoted 4 lines · [email protected]> wrote:
Quoted 4 lines
Le sam. 13 févr. 2016 01:51, Eric Snowberg <[email protected]>
Quoted 32 lines · a écrit :
Quoted 32 lines
Prevent buffer over-read in
grub_machine_mmap_iterate. This was causingphys_basefrom being calculated properly. This then caused the wrong value to be placed inramdisk_imagewithin structlinux_hdrs. Which prevented the ramdisk from loading on boot.Newer SPARC systems contain more than 8 available memory entries.
For example on a T5-8 with 2TB of memory, the memory layout could look like this:
T5-8 Memory
reg 00000000 300000000000003fb000000000000800 00000000 00000040 00000000 00001000 00000000 00000040 00000000 00001800 00000000 00000040 00000000 00002000 00000000 00000040 00000000 00002800 00000000 00000040 00000000 00003000 00000000 00000040 00000000 00003800 00000000 00000040 00000000 available 00003800 00000000 0000003f ffcae000 00003000 00000000 00000040 00000000 00002800 00000000 00000040 00000000 00002000 00000000 00000040 00000000 00001800 00000000 00000040 00000000 00001000 00000000 00000040 00000000 00000800 00000000 00000040 00000000 00000000 70000000 0000003f 70000000 00000000 6eef8000 00000000 00002000 00000000 30400000 00000000 3eaf6000name memory
Quoted 6 lines
Review
Quoted 6 lines
Signed-off-by Eric Snowberg <[email protected]>---
grub-core/kern/ieee1275/mmap.c| 5 ++++-1 files changed, 4 insertions(+), 1 deletions(-)(quoted diff) +0
-0
b/grub-core/kern/ieee1275/mmap.cQuoted 4 lines
grub-core/kern/ieee1275/mmap.c grub_machine_mmap_iterate (grub_memory_hook_t hook,
Quoted 4 lines
index 911bb00..8df4e9b 100644
grub-core/kern/ieee1275/mmap.c +0
-0@@ -25,7 +25,7 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook,void
*hook_data)Quoted 8 lines
Quoted 6 lines
grub-core/kern/ieee1275/mmap.c +1
-1{grub_ieee1275_phandle_t root;grub_ieee1275_phandle_t memory; -grub_uint32_t available[32 ]; +grub_uint32_t available[64 ];Please 512 at least so this can lands further down the road
Ok, I’ll change the array to 512
I tested this new patch out with 512, it doesn’t work well with some older OBP versions. I get an error from OBP that I’ve never seen before. I changed it to 128 and this seems to work.
Would you accept 128 instead? If so, I need to test it on some more equipment before sending out the updated patch.
Quoted 5 lines
grub-core/kern/ieee1275/mmap.c grub_machine_mmap_iterate (grub_memory_hook_t hook,
Quoted 5 lines
grub_ssize_t available_size; grub_uint32_t address_cells = 1; grub_uint32_t size_cells = 1;grub-core/kern/ieee1275/mmap.c +0
-0@@ -49,6 +49,9 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook,void
*hook_data)Quoted 1 line
grub-core/kern/ieee1275/mmap.c grub_machine_mmap_iterate (grub_memory_hook_t hook, · line 49
Quoted 1 line
grub-core/kern/ieee1275/mmap.c +0
-0sizeof available,
&available_size))Quoted 26 lines
grub-core/kern/ieee1275/mmap.c
Quoted 6 lines
grub-core/kern/ieee1275/mmap.c +1
-0return grub_error (GRUB_ERR_UNKNOWN_DEVICE ,"couldn't examine /memory/available property" ); +if (available_size >sizeof available)Brackets around available
grub-core/kern/ieee1275/mmap.c +2
-0+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, + "/memory response buffer exceeded”);And I’ll add the brackets and resubmit
Quoted 11 lines
if (
grub_ieee1275_test_flag(GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS)){--
1.7.1_______________________________________________
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