Skip to contentSkip to conversation

memblock: Fix return sizeless candidate on __memblock_find_range_top_down.

PATCH In review Levi Yun 2 participants 5 messages Jan 4, 2023

Subsystems (2)
lore
Share & tools
lore

Levi Yun

author
#0 lore raw

PATCH 1/1 memblock: Fix return sizeless candidate on __memblock_find_range_top_down.

__memblock_find_range_top_down can return start address of free region which sizeless then user speicified.
To prevent the above case, add size check on candidate free region.

---
 mm/memblock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memblock.c +1 -1
index 511d4783dcf1..710e2ef8d67d 100644
@@ -262,7 +262,7 @@ __memblock_find_range_top_down(phys_addr_t start, phys_addr_t end,
 			continue;
 
 		cand = round_down(this_end - size, align);
-		if (cand >= this_start)
+		if (cand >= this_start && this_end - cand >= size)
 			return cand;
 	}
 
Signature · 1 line
2.35.1
maintainer
#1 lore raw
Quoted 3 lines · Levi Yun

__memblock_find_range_top_down can return start address of free region which sizeless then user speicified.
To prevent the above case, add size check on candidate free region.

Did you see an actual issue or it's solely based on code inspection?

Quoted 21 lines
---
 mm/memblock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memblock.c +1 -1
index 511d4783dcf1..710e2ef8d67d 100644
@@ -262,7 +262,7 @@ __memblock_find_range_top_down(phys_addr_t start, phys_addr_t end,
 			continue;
 
 		cand = round_down(this_end - size, align);
-		if (cand >= this_start)
+		if (cand >= this_start && this_end - cand >= size)
 			return cand;
 	}
 
Signature · 1 line
2.35.1
Signature · 2 lines
Sincerely yours,
Mike.
author
#2 lore raw
Quoted 1 line

Did you see an actual issue or it's solely based on code inspection?

Based on code inspection. I haven't seen the actual issue yet :)

Thanks.

--
Sincerely,
Levi.

maintainer
#3 lore raw
Quoted 3 lines · Yun Levi
Quoted 1 line

Did you see an actual issue or it's solely based on code inspection?

Based on code inspection. I haven't seen the actual issue yet :)

I don't see a problem there. Do you have an example how this could happen?

Quoted 5 lines

Thanks.

--
Sincerely,
Levi.

Signature · 2 lines
Sincerely yours,
Mike.
author
#4 lore raw

I've got possessed by something... Sorry to make noise again :) Thanks!

Quoted 17 lines · Mike Rapoport
Quoted 3 lines · Yun Levi
Quoted 1 line

Did you see an actual issue or it's solely based on code inspection?

Based on code inspection. I haven't seen the actual issue yet :)

I don't see a problem there. Do you have an example how this could happen?

Quoted 5 lines

Thanks.

--
Sincerely,
Levi.

--
Sincerely yours,
Mike.