mbox series

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

Message ID 20230717213545.142598-1-deller@gmx.de (mailing list archive)
Headers show
Series linux-user: brk() syscall fixes and armhf static binary fix | expand

Message

Helge Deller July 17, 2023, 9:35 p.m. UTC
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

Comments

Philippe Mathieu-Daudé July 17, 2023, 9:43 p.m. UTC | #1
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.
gaosong July 18, 2023, 3:03 a.m. UTC | #2
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
>
Helge Deller July 18, 2023, 5:42 a.m. UTC | #3
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
>>
>
gaosong July 18, 2023, 7:25 a.m. UTC | #4
在 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
>>>
>>
Michael Tokarev July 18, 2023, 8:30 a.m. UTC | #5
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
Michael Tokarev July 19, 2023, 11:39 a.m. UTC | #6
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