linux-user/mmap.c: fix integer underflow in target_mremap
PATCH 1/1 linux-user/mmap.c: fix integer underflow in target_mremap
This code path in mmap occurs when a page size is decreased with mremap. When a section of pages is shrunk, qemu calls mmap_reserve on the pages that were released. However, it has the diff operation reversed, subtracting the larger old_size from the smaller new_size. Instead, it should be subtracting the smaller new_size from the larger old_size. You can also see in the previous line of the change that this mmap_reserve call only occurs when old_size > new_size.
--- linux-user/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/mmap.c +1 -1
@@ -708,7 +708,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,if (prot ==0 ) { host_addr =mremap (g2h (old_addr), old_size, new_size, flags);if (host_addr !=MAP_FAILED && reserved_va && old_size > new_size) { -mmap_reserve (old_addr + old_size, new_size - old_size); +mmap_reserve (old_addr + old_size, old_size - new_size); } }else { errno =ENOMEM ;
Signature · 1 line
2.23.1
FYI, I applied this patch to the qemu build that zig uses to run non-native tests (
https://github.com/ziglang/qemu-static/blob/master/patch/mremap-underflow.diff
)
After applying it, my new code that calls mremap now passes, whereas before the fix I was getting a segfault.
Quoted 34 lines · Jonathan Marler
This code path in mmap occurs when a page size is decreased with mremap. When a section of pages is shrunk, qemu calls
mmap_reserveon the pages that were released. However, it has the diff operation reversed, subtracting the largerold_sizefrom the smallernew_size. Instead, it should be subtracting the smallernew_sizefrom the largerold_size. You can also see in the previous line of the change that thismmap_reservecall only occurs whenold_size>new_size.Signed-off-by Jonathan Marler <[email protected]>--- linux-user/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linux-user/mmap.c +1
-1@@ -708,7 +708,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, if (prot == 0) { host_addr =mremap (g2h (old_addr), old_size, new_size, flags);if (host_addr !=MAP_FAILED && reserved_va && old_size > new_size) { -mmap_reserve (old_addr + old_size, new_size - old_size); +mmap_reserve (old_addr + old_size, old_size - new_size); }} else { errno = ENOMEM;--
2.23.1
Been a couple weeks, checking to see if anyone has looked at this.
Quoted 45 lines · Jonathan Marler
FYI, I applied this patch to the qemu build that zig uses to run non-native tests (
https://github.com/ziglang/qemu-static/blob/master/patch/mremap-underflow.diff
)After applying it, my new code that calls mremap now passes, whereas before the fix I was getting a segfault.
Quoted 34 lines · Jonathan Marler
This code path in mmap occurs when a page size is decreased with mremap. When a section of pages is shrunk, qemu calls
mmap_reserveon the pages that were released. However, it has the diff operation reversed, subtracting the largerold_sizefrom the smallernew_size. Instead, it should be subtracting the smallernew_sizefrom the largerold_size. You can also see in the previous line of the change that thismmap_reservecall only occurs whenold_size>new_size.Signed-off-by Jonathan Marler <[email protected]>--- linux-user/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linux-user/mmap.c +1
-1@@ -708,7 +708,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, if (prot == 0) { host_addr =mremap (g2h (old_addr), old_size, new_size, flags);if (host_addr !=MAP_FAILED && reserved_va && old_size > new_size) { -mmap_reserve (old_addr + old_size, new_size - old_size); +mmap_reserve (old_addr + old_size, old_size - new_size); }} else { errno = ENOMEM;--
2.23.1
Been a few more days. Not sure how often I should be pinging. If this is too much to ping every few days let me know.
Quoted 51 lines · Jonathan Marler
Been a couple weeks, checking to see if anyone has looked at this.
Quoted 46 lines · Jonathan Marler
FYI, I applied this patch to the qemu build that zig uses to run non-native tests (
https://github.com/ziglang/qemu-static/blob/master/patch/mremap-underflow.diff
)After applying it, my new code that calls mremap now passes, whereas before the fix I was getting a segfault.
Quoted 35 lines · Jonathan Marler
This code path in mmap occurs when a page size is decreased with mremap. When a section of pages is shrunk, qemu calls
mmap_reserveon the pages that were released. However, it has the diff operation reversed, subtracting the largerold_sizefrom the smallernew_size. Instead, it should be subtracting the smallernew_sizefrom the largerold_size. You can also see in the previous line of the change that thismmap_reservecall only occurs whenold_size>new_size.Signed-off-by Jonathan Marler <[email protected]>--- linux-user/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linux-user/mmap.c +1
-1@@ -708,7 +708,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, if (prot == 0) { host_addr =mremap (g2h (old_addr), old_size, new_size, flags);if (host_addr !=MAP_FAILED && reserved_va && old_size > new_size) { -mmap_reserve (old_addr + old_size, new_size - old_size); +mmap_reserve (old_addr + old_size, old_size - new_size);} } else { errno = ENOMEM;--
2.23.1
Hi Jonathan,
thanks for the patch!
CCing Riku and Laurent.
Quoted 2 lines · Jonathan Marler
Been a few more days. Not sure how often I should be pinging. If this is too much to ping every few days let me know.
Is not too much, but next time is better to CC the maintainers. You can use 'scripts/get_maintainer.pl' to get the list of maintainers and reviewers.
Please take a look at https://wiki.qemu.org/Contribute/SubmitAPatch
Quoted 14 lines
Quoted 10 lines · Jonathan Marler
Been a couple weeks, checking to see if anyone has looked at this.
Quoted 5 lines · Jonathan Marler
FYI, I applied this patch to the qemu build that zig uses to run non-native tests (
https://github.com/ziglang/qemu-static/blob/master/patch/mremap-underflow.diff
)
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
After applying it, my new code that calls mremap now passes, whereas before the fix I was getting a segfault.
Quoted 1 line · Jonathan Marler
should be "Buglink: https://bugs.launchpad.net/bugs/1876373"
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
This code path in mmap occurs when a page size is decreased with mremap. When a section of pages is shrunk, qemu calls
mmap_reserveon the pages that were released. However, it has the diff operation reversed, subtracting the largerold_sizefrom the smallernew_size. Instead, it should be subtracting the smallernew_sizefrom the largerold_size. You can also see in the previous line of the change that thismmap_reservecall only occurs whenold_size>new_size.
Please break the lines of the commit message (max 76 charactes per line):
https://wiki.qemu.org/Contribute/SubmitAPatch#Write_a_meaningful_commit_message
Thanks,
Stefano
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Signed-off-by Jonathan Marler <[email protected]>--- linux-user/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linux-user/mmap.c +1
-1@@ -708,7 +708,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, if (prot == 0) { host_addr =mremap (g2h (old_addr), old_size, new_size, flags);if (host_addr !=MAP_FAILED && reserved_va && old_size > new_size) { -mmap_reserve (old_addr + old_size, new_size - old_size); +mmap_reserve (old_addr + old_size, old_size - new_size);} } else { errno = ENOMEM;--
2.23.1
Hi Jonathan.
Quoted 8 lines · Stefano Garzarella
Hi Jonathan,
thanks for the patch!CCing Riku and Laurent.
Quoted 2 lines · Jonathan Marler
Been a few more days. Not sure how often I should be pinging. If this is too much to ping every few days let me know.
Pinging every week is fine. The problem here, as noticed by Stefano, is you forgot to Cc the maintainers, so they surely missed your patch.
Last time Riku sent an email to qemu-devel was more than 2 years ago, letling Laurent second him, then went MIA:
https://www.mail-archive.com/[email protected]/msg507843.html
I'd say count 1 week starting today.
Regards,
Phil.
Quoted 74 lines
Is not too much, but next time is better to CC the maintainers. You can use '
scripts/get_maintainer.pl' to get the list of maintainers and reviewers.Please take a look at https://wiki.qemu.org/Contribute/SubmitAPatch
Quoted 14 lines
Quoted 10 lines · Jonathan Marler
Been a couple weeks, checking to see if anyone has looked at this.
Quoted 5 lines · Jonathan Marler
FYI, I applied this patch to the qemu build that zig uses to run non-native tests (
https://github.com/ziglang/qemu-static/blob/master/patch/mremap-underflow.diff
)Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
After applying it, my new code that calls mremap now passes, whereas before the fix I was getting a segfault.
Quoted 1 line · Jonathan Marler
should be "Buglink: https://bugs.launchpad.net/bugs/1876373"
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
This code path in mmap occurs when a page size is decreased with mremap. When a section of pages is shrunk, qemu calls
mmap_reserveon the pages that were released. However, it has the diff operation reversed, subtracting the largerold_sizefrom the smallernew_size. Instead, it should be subtracting the smallernew_sizefrom the largerold_size. You can also see in the previous line of the change that thismmap_reservecall only occurs whenold_size>new_size.Please break the lines of the commit message (max 76 charactes per line):
https://wiki.qemu.org/Contribute/SubmitAPatch#Write_a_meaningful_commit_messageThanks,
StefanoQuoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Signed-off-by Jonathan Marler <[email protected]>--- linux-user/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linux-user/mmap.c +1
-1@@ -708,7 +708,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, if (prot == 0) { host_addr =mremap (g2h (old_addr), old_size, new_size, flags);if (host_addr !=MAP_FAILED && reserved_va && old_size > new_size) { -mmap_reserve (old_addr + old_size, new_size - old_size); +mmap_reserve (old_addr + old_size, old_size - new_size);} } else { errno = ENOMEM;--
2.23.1
Le 02/05/2020 à 18:12, Jonathan Marler a écrit :
Quoted 15 lines
This code path in mmap occurs when a page size is decreased with mremap. When a section of pages is shrunk, qemu calls
mmap_reserveon the pages that were released. However, it has the diff operation reversed, subtracting the largerold_sizefrom the smallernew_size. Instead, it should be subtracting the smallernew_sizefrom the largerold_size. You can also see in the previous line of the change that thismmap_reservecall only occurs whenold_size>new_size.Signed-off-by Jonathan Marler <[email protected]>--- linux-user/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linux-user/mmap.c +0
-0
linux-user/mmap.c abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, · line 714
Quoted 8 lines
linux-user/mmap.c +1
-1@@ -708,7 +708,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,if (prot ==0 ) { host_addr =mremap (g2h (old_addr), old_size, new_size, flags);if (host_addr !=MAP_FAILED && reserved_va && old_size > new_size) { -mmap_reserve (old_addr + old_size, new_size - old_size); +mmap_reserve (old_addr + old_size, old_size - new_size); } }else { errno =ENOMEM ;
Laurent Vivier
AppliedLe 02/05/2020 à 18:12, Jonathan Marler a écrit :
Quoted 15 lines
This code path in mmap occurs when a page size is decreased with mremap. When a section of pages is shrunk, qemu calls
mmap_reserveon the pages that were released. However, it has the diff operation reversed, subtracting the largerold_sizefrom the smallernew_size. Instead, it should be subtracting the smallernew_sizefrom the largerold_size. You can also see in the previous line of the change that thismmap_reservecall only occurs whenold_size>new_size.Signed-off-by Jonathan Marler <[email protected]>--- linux-user/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linux-user/mmap.c +0
-0
linux-user/mmap.c abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, · line 714
Quoted 8 lines
linux-user/mmap.c +1
-1@@ -708,7 +708,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,if (prot ==0 ) { host_addr =mremap (g2h (old_addr), old_size, new_size, flags);if (host_addr !=MAP_FAILED && reserved_va && old_size > new_size) { -mmap_reserve (old_addr + old_size, new_size - old_size); +mmap_reserve (old_addr + old_size, old_size - new_size); } }else { errno =ENOMEM ;
Applied to my linux-user branch.
Thanks,
Laurent