Skip to contentSkip to conversation

linux-user: make sure brk(0) returns a page-aligned value

PATCH In review Andreas Schwab 3 participants 5 messages Jul 6, 2023 – Jul 12, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: make sure brk(0) returns a page-aligned value

Fixes 86f04735ac ("linux-user: Fix brk() to release pages")
---
 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +1 -1
index 08162cc966..e8a17377f5 100644
@@ -805,7 +805,7 @@ static abi_ulong brk_page;
 
 void target_set_brk(abi_ulong new_brk)
 {
-    target_brk = new_brk;
+    target_brk = TARGET_PAGE_ALIGN(new_brk);
     brk_page = HOST_PAGE_ALIGN(target_brk);
 }
 
Signature · 7 lines
2.41.0


-- 
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
#1 lore raw
Quoted 11 lines · Andreas Schwab
Fixes 86f04735ac ("linux-user: Fix brk() to release pages")
---
  linux-user/syscall.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +0 -0
index 08162cc966..e8a17377f5 100644

linux-user/syscall.c static abi_ulong brk_page; · line 811

Quoted 8 lines
linux-user/syscall.c +1 -1
@@ -805,7 +805,7 @@ static abi_ulong brk_page;
 
  void target_set_brk(abi_ulong new_brk)
  {
-    target_brk = new_brk;
+    target_brk = TARGET_PAGE_ALIGN(new_brk);
      brk_page = HOST_PAGE_ALIGN(target_brk);
  }
 

It make sense, since that's how do_brk aligns things.
I'm curious why this error might have produced host memory clobbering, but I'm not going to debug that.

Queuing for tcg/linux-user.

r~

#2 lore raw
Quoted 7 lines · Richard Henderson
Quoted 6 lines · Andreas Schwab
Fixes 86f04735ac ("linux-user: Fix brk() to release pages")

---
  linux-user/syscall.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

linux-user/syscall.c static abi_ulong brk_page; · line 809

Quoted 11 lines
linux-user/syscall.c +1 -1
index 08162cc966..e8a17377f5 100644
@@ -805,7 +805,7 @@ static abi_ulong brk_page;
   void target_set_brk(abi_ulong new_brk)
   {
-    target_brk = new_brk;
+    target_brk = TARGET_PAGE_ALIGN(new_brk);
       brk_page = HOST_PAGE_ALIGN(target_brk);
   }

It make sense, since that's how do_brk aligns things.

Yes, patch looks good.
I haven't tested, but it seems it adjusts the initial brk(0) value only to make sure that it's target page aligned.
Maybe the title should be: ?
linux-user: make sure the initial brk(0) is page-aligned

Quoted 1 line

I'm curious why this error might have produced host memory clobbering, but I'm not going to debug that.

I don't believe that this un-alignment triggers host memory clobbering either.

Helge

#3 lore raw
Quoted 19 lines · Helge Deller
Quoted 18 lines · Richard Henderson
Quoted 17 lines · Andreas Schwab
Fixes 86f04735ac ("linux-user: Fix brk() to release pages")

---
  linux-user/syscall.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +1 -1
index 08162cc966..e8a17377f5 100644
@@ -805,7 +805,7 @@ static abi_ulong brk_page;
   void target_set_brk(abi_ulong new_brk)
   {
-    target_brk = new_brk;
+    target_brk = TARGET_PAGE_ALIGN(new_brk);
       brk_page = HOST_PAGE_ALIGN(target_brk);
   }

...

Quoted 2 lines
Quoted 1 line

I'm curious why this error might have produced host memory clobbering, but I'm not going to debug that.

I don't believe that this un-alignment triggers host memory clobbering either.

See my follow-up in the other mail threadd:
"Re: [RISC-V] ERROR:../accel/tcg/cpu-exec.c:1028:cpu_exec_setjmp: assertion failed: (cpu == current_cpu)"

Helge

#4 lore raw
In reply to Helge Deller
Quoted 22 lines · Helge Deller
Quoted 7 lines · Richard Henderson
Quoted 6 lines · Andreas Schwab
Fixes 86f04735ac ("linux-user: Fix brk() to release pages")

---
  linux-user/syscall.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

linux-user/syscall.c static abi_ulong brk_page; · line 809

Quoted 11 lines
linux-user/syscall.c +1 -1
index 08162cc966..e8a17377f5 100644
@@ -805,7 +805,7 @@ static abi_ulong brk_page;
   void target_set_brk(abi_ulong new_brk)
   {
-    target_brk = new_brk;
+    target_brk = TARGET_PAGE_ALIGN(new_brk);
       brk_page = HOST_PAGE_ALIGN(target_brk);
   }

It make sense, since that's how do_brk aligns things.

Quoted 5 lines

Yes, patch looks good.
I haven't tested, but it seems it adjusts the initial brk(0) value only to make sure that it's target page aligned.
Maybe the title should be: ?
linux-user: make sure the initial brk(0) is page-aligned

Another bug report regarding the non-aligned brk()...

See:
https://github.com/upx/upx/issues/683
https://gitlab.com/qemu-project/qemu/-/issues/1756

Helge