[PATCH 0/6] linux-user: brk() syscall fixes and armhf static binary fix

Helge Deller posted 6 patches 9 months, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20230717213545.142598-1-deller@gmx.de
Maintainers: Laurent Vivier <laurent@vivier.eu>
There is a newer version of this series
linux-user/elfload.c |  7 +++++++
linux-user/strace.c  | 49 ++++++++++++++++++++++++++++++++++++++++----
linux-user/syscall.c | 25 +++++++++++++---------
3 files changed, 67 insertions(+), 14 deletions(-)
[PATCH 0/6] linux-user: brk() syscall fixes and armhf static binary fix
Posted by Helge Deller 9 months, 2 weeks ago
Commit 86f04735ac ("linux-user: Fix brk() to release pages") introduced the
possibility for userspace applications to reduce memory footprint by calling
brk() with a lower address and free up memory.
This change introduced some failures for applications with errors like
- accesing bytes above the brk heap address on the same page,
- freeing memory below the initial brk address,
and introduced a behaviour which isn't done by the kernel (e.g. zeroing
memory above brk).

This patch set fixes those issues and have been tested with existing
programs (e.g. upx).

Additionally it includes one patch to allow running static armhf executables
(e.g. fstype) which was broken since qemu-8.0.

Helge

Helge Deller (6):
  Revert "linux-user: Make sure initial brk(0) is page-aligned"
  linux-user: Fix qemu brk() to not zero bytes on current page
  linux-user: Prohibit brk() to to shrink below initial heap address
  linux-user: Fix signed math overflow in brk() syscall
  linux-user: Fix strace output for old_mmap
  linux-user: Fix qemu-arm to run static armhf binaries

 linux-user/elfload.c |  7 +++++++
 linux-user/strace.c  | 49 ++++++++++++++++++++++++++++++++++++++++----
 linux-user/syscall.c | 25 +++++++++++++---------
 3 files changed, 67 insertions(+), 14 deletions(-)

--
2.41.0
Re: [PATCH 0/6] linux-user: brk() syscall fixes and armhf static binary fix
Posted by Song Gao 9 months, 2 weeks ago
Hi,  Helge

Could you see the following bugs:
https://gitlab.com/qemu-project/qemu/-/issues/1707

This issue is also caused by  the commit  86f04735ac.

Thanks.
Song Gao


在 2023/7/18 上午5:35, Helge Deller 写道:
> Commit 86f04735ac ("linux-user: Fix brk() to release pages") introduced the
> possibility for userspace applications to reduce memory footprint by calling
> brk() with a lower address and free up memory.
> This change introduced some failures for applications with errors like
> - accesing bytes above the brk heap address on the same page,
> - freeing memory below the initial brk address,
> and introduced a behaviour which isn't done by the kernel (e.g. zeroing
> memory above brk).
>
> This patch set fixes those issues and have been tested with existing
> programs (e.g. upx).
>
> Additionally it includes one patch to allow running static armhf executables
> (e.g. fstype) which was broken since qemu-8.0.
>
> Helge
>
> Helge Deller (6):
>    Revert "linux-user: Make sure initial brk(0) is page-aligned"
>    linux-user: Fix qemu brk() to not zero bytes on current page
>    linux-user: Prohibit brk() to to shrink below initial heap address
>    linux-user: Fix signed math overflow in brk() syscall
>    linux-user: Fix strace output for old_mmap
>    linux-user: Fix qemu-arm to run static armhf binaries
>
>   linux-user/elfload.c |  7 +++++++
>   linux-user/strace.c  | 49 ++++++++++++++++++++++++++++++++++++++++----
>   linux-user/syscall.c | 25 +++++++++++++---------
>   3 files changed, 67 insertions(+), 14 deletions(-)
>
> --
> 2.41.0
>


Re: [PATCH 0/6] linux-user: brk() syscall fixes and armhf static binary fix
Posted by Michael Tokarev 9 months, 2 weeks ago
18.07.2023 06:03, Song Gao пишет:
> Hi,  Helge
> 
> Could you see the following bugs:
> https://gitlab.com/qemu-project/qemu/-/issues/1707
> 
> This issue is also caused by  the commit  86f04735ac.

This issue has been fixed in master already and even in 8.0.3 stable release
(I haven't checked which commit did that, though).

/mjt

Re: [PATCH 0/6] linux-user: brk() syscall fixes and armhf static binary fix
Posted by Michael Tokarev 9 months, 2 weeks ago
18.07.2023 11:30, Michael Tokarev wrote:
> 18.07.2023 06:03, Song Gao пишет:
>> Hi,  Helge
>>
>> Could you see the following bugs:
>> https://gitlab.com/qemu-project/qemu/-/issues/1707
>>
>> This issue is also caused by  the commit  86f04735ac.
> 
> This issue has been fixed in master already and even in 8.0.3 stable release
> (I haven't checked which commit did that, though).

This claim turned out to be false: the prob is fixed in *debian* build of
qemu v8.0.3, which includes an additional change on top of qemu v8.0.3,
"linux-user: Make sure initial brk(0) is page-aligned" - the one which is being
reverted in this patchset, apparenly incorrectly.

So, in short, https://gitlab.com/qemu-project/qemu/-/issues/1707 is fixed
in qemu master but not in qemu v8.0.3 stable. Hopefully the fix will be in v8.0.4
(together with other fixes from this thread).

Thanks,  and sorry for my mistake.

/mjt

Re: [PATCH 0/6] linux-user: brk() syscall fixes and armhf static binary fix
Posted by Helge Deller 9 months, 2 weeks ago
On 7/18/23 05:03, Song Gao wrote:
> Hi,  Helge
>
> Could you see the following bugs:
> https://gitlab.com/qemu-project/qemu/-/issues/1707
>
> This issue is also caused by  the commit  86f04735ac.

I don't have access to such a box (and on an arm64 debian porterbox
I get unmet build dependencies, e.g. for gcc-powerpc64-linux-gnu).

If you can provide me with access to a machine I can test,
otherwise you may simply check out:
   git pull https://github.com/hdeller/qemu-hppa.git linux-user-brk-fixes
and test yourself.

Helge


>
> Thanks.
> Song Gao
>
>
> 在 2023/7/18 上午5:35, Helge Deller 写道:
>> Commit 86f04735ac ("linux-user: Fix brk() to release pages") introduced the
>> possibility for userspace applications to reduce memory footprint by calling
>> brk() with a lower address and free up memory.
>> This change introduced some failures for applications with errors like
>> - accesing bytes above the brk heap address on the same page,
>> - freeing memory below the initial brk address,
>> and introduced a behaviour which isn't done by the kernel (e.g. zeroing
>> memory above brk).
>>
>> This patch set fixes those issues and have been tested with existing
>> programs (e.g. upx).
>>
>> Additionally it includes one patch to allow running static armhf executables
>> (e.g. fstype) which was broken since qemu-8.0.
>>
>> Helge
>>
>> Helge Deller (6):
>>    Revert "linux-user: Make sure initial brk(0) is page-aligned"
>>    linux-user: Fix qemu brk() to not zero bytes on current page
>>    linux-user: Prohibit brk() to to shrink below initial heap address
>>    linux-user: Fix signed math overflow in brk() syscall
>>    linux-user: Fix strace output for old_mmap
>>    linux-user: Fix qemu-arm to run static armhf binaries
>>
>>   linux-user/elfload.c |  7 +++++++
>>   linux-user/strace.c  | 49 ++++++++++++++++++++++++++++++++++++++++----
>>   linux-user/syscall.c | 25 +++++++++++++---------
>>   3 files changed, 67 insertions(+), 14 deletions(-)
>>
>> --
>> 2.41.0
>>
>
Re: [PATCH 0/6] linux-user: brk() syscall fixes and armhf static binary fix
Posted by Song Gao 9 months, 2 weeks ago

在 2023/7/18 下午1:42, Helge Deller 写道:
> On 7/18/23 05:03, Song Gao wrote:
>> Hi,  Helge
>>
>> Could you see the following bugs:
>> https://gitlab.com/qemu-project/qemu/-/issues/1707
>>
>> This issue is also caused by  the commit  86f04735ac.
>
> I don't have access to such a box (and on an arm64 debian porterbox
> I get unmet build dependencies, e.g. for gcc-powerpc64-linux-gnu).
>
> If you can provide me with access to a machine I can test,
> otherwise you may simply check out:
>   git pull https://github.com/hdeller/qemu-hppa.git linux-user-brk-fixes
> and test yourself.
>
Thank you.
I update code to the lastet,   it's no problem.

Thanks.
Song Gao
> Helge
>>
>> Thanks.
>> Song Gao
>>
>>
>> 在 2023/7/18 上午5:35, Helge Deller 写道:
>>> Commit 86f04735ac ("linux-user: Fix brk() to release pages") 
>>> introduced the
>>> possibility for userspace applications to reduce memory footprint by 
>>> calling
>>> brk() with a lower address and free up memory.
>>> This change introduced some failures for applications with errors like
>>> - accesing bytes above the brk heap address on the same page,
>>> - freeing memory below the initial brk address,
>>> and introduced a behaviour which isn't done by the kernel (e.g. zeroing
>>> memory above brk).
>>>
>>> This patch set fixes those issues and have been tested with existing
>>> programs (e.g. upx).
>>>
>>> Additionally it includes one patch to allow running static armhf 
>>> executables
>>> (e.g. fstype) which was broken since qemu-8.0.
>>>
>>> Helge
>>>
>>> Helge Deller (6):
>>>    Revert "linux-user: Make sure initial brk(0) is page-aligned"
>>>    linux-user: Fix qemu brk() to not zero bytes on current page
>>>    linux-user: Prohibit brk() to to shrink below initial heap address
>>>    linux-user: Fix signed math overflow in brk() syscall
>>>    linux-user: Fix strace output for old_mmap
>>>    linux-user: Fix qemu-arm to run static armhf binaries
>>>
>>>   linux-user/elfload.c |  7 +++++++
>>>   linux-user/strace.c  | 49 
>>> ++++++++++++++++++++++++++++++++++++++++----
>>>   linux-user/syscall.c | 25 +++++++++++++---------
>>>   3 files changed, 67 insertions(+), 14 deletions(-)
>>>
>>> -- 
>>> 2.41.0
>>>
>>


Re: [PATCH 0/6] linux-user: brk() syscall fixes and armhf static binary fix
Posted by Philippe Mathieu-Daudé 9 months, 2 weeks ago
On 17/7/23 23:35, Helge Deller wrote:
> Commit 86f04735ac ("linux-user: Fix brk() to release pages") introduced the
> possibility for userspace applications to reduce memory footprint by calling
> brk() with a lower address and free up memory.
> This change introduced some failures for applications with errors like
> - accesing bytes above the brk heap address on the same page,
> - freeing memory below the initial brk address,
> and introduced a behaviour which isn't done by the kernel (e.g. zeroing
> memory above brk).
> 
> This patch set fixes those issues and have been tested with existing
> programs (e.g. upx).
> 
> Additionally it includes one patch to allow running static armhf executables
> (e.g. fstype) which was broken since qemu-8.0.
> 
> Helge
> 
> Helge Deller (6):
>    Revert "linux-user: Make sure initial brk(0) is page-aligned"
>    linux-user: Fix qemu brk() to not zero bytes on current page
>    linux-user: Prohibit brk() to to shrink below initial heap address
>    linux-user: Fix signed math overflow in brk() syscall
>    linux-user: Fix strace output for old_mmap
>    linux-user: Fix qemu-arm to run static armhf binaries

I'm not sure this series will reach Markus at
Markus F.X.J. Oberhumer <notifications@github.com> =)
Cc'ing his "minilzo.h" address.