[OpenBIOS] [PATCH] ofmem: restrict ofmem_claim() allocations to RAM size

Mark Cave-Ayland mark.cave-ayland at ilande.co.uk
Tue Feb 13 23:41:23 CET 2018


As OFMEM memory ranges don't provide an explicit upper limit, we must manually
check that CIF claim calls lie within a valid maxmimum range if attempting to
allocate a specific address. Since the claim method provides a 1:1 mapping between
physical and virtual addresses, the valid maximum address is therefore equivalent
to the machine RAM size.

This fixes booting yaboot 1.3.17 which implements a top-down search using claim to
find the next free memory region to locate its heap. Without this fix we blindly
accept a claim for physical addresses far above the available RAM which fails
silently when we try to use the mapping later.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
---
 libopenbios/ofmem_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libopenbios/ofmem_common.c b/libopenbios/ofmem_common.c
index 217bd9b..fc19d27 100644
--- a/libopenbios/ofmem_common.c
+++ b/libopenbios/ofmem_common.c
@@ -623,7 +623,7 @@ ucell ofmem_claim( ucell addr, ucell size, ucell align )
 	virt = phys = 0;
 	if( !align ) {
 		if( is_free(addr, size, ofmem->virt_range) &&
-		    is_free(addr, size, ofmem->phys_range) ) {
+		    is_free(addr, size, ofmem->phys_range) && addr < get_ram_size() ) {
 			ofmem_claim_phys_( addr, size, 0, 0, 0, 0 );
 			ofmem_claim_virt_( addr, size, 0, 0, 0, 0 );
 			virt = phys = addr;
-- 
2.11.0




More information about the OpenBIOS mailing list