tests/tcg: fix buffer overflow in multiarch/linux/linux-sigrtminmax
PATCH 1/1 tests/tcg: fix buffer overflow in multiarch/linux/linux-sigrtminmax
Fix new_argv allocation size to be (argc + 2) * sizeof(char *) bytes, which matches the way it's used to store argc + 2 pointers.
This fixes the test for me, which otherwise fails on xtensa with the following message
linux-sigrtminmax.c: 59: main: Assertion `execve(new_argv[0], new_argv, environ) == 0' failed.'.
--- tests/tcg/multiarch/linux/linux-sigrtminmax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/tcg/multiarch/linux/linux-sigrtminmax.c +1 -1
@@ -39,7 +39,7 @@ int main(int argc, char **argv)assert (qemu);if (!getenv ("QEMU_RTSIG_MAP" )) { -char **new_argv =malloc ((argc +2 ) +sizeof (char *)); +char **new_argv =malloc ((argc +2 ) *sizeof (char *));int tsig1, hsig1, count1, tsig2, hsig2, count2;char rt_sigmap[64 ];
Signature · 1 line
2.47.3
Quoted 9 lines · Max Filippov
Fix
new_argvallocation size to be(argc + 2) * sizeof(char *)bytes, which matches the way it's used to storeargc + 2pointers.This fixes the test for me, which otherwise fails on xtensa with the following message
linux-sigrtminmax.c: 59: main: Assertion `execve(new_argv[0],new_argv, environ) == 0' failed.'.Signed-off-by Max Filippov <[email protected]>
Quoted 16 lines
--- tests/tcg/multiarch/linux/linux-sigrtminmax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/tcg/multiarch/linux/linux-sigrtminmax.c +1
-1@@ -39,7 +39,7 @@ int main(int argc, char **argv)assert (qemu);if (!getenv ("QEMU_RTSIG_MAP" )) { -char **new_argv =malloc ((argc +2 ) +sizeof (char *)); +char **new_argv =malloc ((argc +2 ) *sizeof (char *));int tsig1, hsig1, count1, tsig2, hsig2, count2;char rt_sigmap[64 ];
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Quoted 6 lines · Max Filippov
Fix
new_argvallocation size to be(argc + 2) * sizeof(char *)bytes, which matches the way it's used to storeargc + 2pointers.This fixes the test for me, which otherwise fails on xtensa with the following message
Quoted 6 lines
linux-sigrtminmax.c: 59: main: Assertion `execve(new_argv[0], new_argv, environ) == 0' failed.'.Signed-off-by Max Filippov <[email protected]>--- tests/tcg/multiarch/linux/linux-sigrtminmax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
Quoted 14 lines
tests/tcg/multiarch/linux/linux-sigrtminmax.c +1
-1@@ -39,7 +39,7 @@ int main(int argc, char **argv)assert (qemu);if (!getenv ("QEMU_RTSIG_MAP" )) { -char **new_argv =malloc ((argc +2 ) +sizeof (char *)); +char **new_argv =malloc ((argc +2 ) *sizeof (char *));int tsig1, hsig1, count1, tsig2, hsig2, count2;char rt_sigmap[64 ];
Quoted 6 lines · Max Filippov
Fix
new_argvallocation size to be(argc + 2) * sizeof(char *)bytes, which matches the way it's used to storeargc + 2pointers.This fixes the test for me, which otherwise fails on xtensa with the following message
Quoted 6 lines
linux-sigrtminmax.c: 59: main: Assertion `execve(new_argv[0], new_argv, environ) == 0' failed.'.Signed-off-by Max Filippov <[email protected]>--- tests/tcg/multiarch/linux/linux-sigrtminmax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 18 lines · Max Filippov
Fix
new_argvallocation size to be(argc + 2) * sizeof(char *)bytes, which matches the way it's used to storeargc + 2pointers.This fixes the test for me, which otherwise fails on xtensa with the following message
linux-sigrtminmax.c: 59: main: Assertion `execve(new_argv[0], new_argv, environ) == 0' failed.'.Signed-off-by Max Filippov <[email protected]>--- tests/tcg/multiarch/linux/linux-sigrtminmax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/tcg/multiarch/linux/linux-sigrtminmax.c +0
-0
tests/tcg/multiarch/linux/linux-sigrtminmax.c int main(int argc, char **argv) · line 45
Quoted 8 lines
tests/tcg/multiarch/linux/linux-sigrtminmax.c +1
-1@@ -39,7 +39,7 @@ int main(int argc, char **argv)assert (qemu);if (!getenv ("QEMU_RTSIG_MAP" )) { -char **new_argv =malloc ((argc +2 ) +sizeof (char *)); +char **new_argv =malloc ((argc +2 ) *sizeof (char *));int tsig1, hsig1, count1, tsig2, hsig2, count2;char rt_sigmap[64 ];
Whoops, a silly typo on my part.
Thanks for taking the time to fix it!
Quoted 18 lines · Max Filippov
Fix
new_argvallocation size to be(argc + 2) * sizeof(char *)bytes, which matches the way it's used to storeargc + 2pointers.This fixes the test for me, which otherwise fails on xtensa with the following message
linux-sigrtminmax.c: 59: main: Assertion `execve(new_argv[0],new_argv, environ) == 0' failed.'.Signed-off-by Max Filippov <[email protected]>--- tests/tcg/multiarch/linux/linux-sigrtminmax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/tcg/multiarch/linux/linux-sigrtminmax.c +0
-0
tests/tcg/multiarch/linux/linux-sigrtminmax.c int main(int argc, char **argv) · line 42
Quoted 5 lines
tests/tcg/multiarch/linux/linux-sigrtminmax.c +1
-1@@ -39,7 +39,7 @@ int main(int argc, char **argv)assert (qemu);if (!getenv ("QEMU_RTSIG_MAP" )) { -char **new_argv =malloc ((argc +2 ) +sizeof (char *)); +char **new_argv =malloc ((argc +2 ) *sizeof (char *));
If you can switch to glib's malloc, then g_new(argc + 2, sizeof(char *)) is better. Yes, @argc can't become big enough for the multiplication to overflow, but g_new() removes the need for reasoning.
Quoted 2 lines
tests/tcg/multiarch/linux/linux-sigrtminmax.c +0
-0int tsig1, hsig1, count1, tsig2, hsig2, count2;char rt_sigmap[64 ];
Quoted 22 lines · Markus Armbruster
Quoted 20 lines · Max Filippov
Fix
new_argvallocation size to be(argc + 2) * sizeof(char *)bytes, which matches the way it's used to storeargc + 2pointers.This fixes the test for me, which otherwise fails on xtensa with the following message
linux-sigrtminmax.c: 59: main: Assertion `execve(new_argv[0],new_argv, environ) == 0' failed.'.Signed-off-by Max Filippov <[email protected]>--- tests/tcg/multiarch/linux/linux-sigrtminmax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/tcg/multiarch/linux/linux-sigrtminmax.c +0
-0@@ -39,7 +39,7 @@ int main(int argc, char **argv)assert (qemu);
Quoted 7 lines
tests/tcg/multiarch/linux/linux-sigrtminmax.c int main(int argc, char **argv) · line 42
Quoted 3 lines
tests/tcg/multiarch/linux/linux-sigrtminmax.c +1
-1if (!getenv ("QEMU_RTSIG_MAP" )) { -char **new_argv =malloc ((argc +2 ) +sizeof (char *)); +char **new_argv =malloc ((argc +2 ) *sizeof (char *));If you can switch to glib's malloc, then
g_new(argc + 2, sizeof(char *))is better. Yes, @argc can't become big enough for the multiplication to overflow, butg_new()removes the need for reasoning.
The TCG unit tests don't link to GLib, only basic libc.
Fortunately unit tests have a trusted caller (the QEMU meson build system), so we don't have to worry about malicious usage with overflow in this context.
Quoted 5 lines
tests/tcg/multiarch/linux/linux-sigrtminmax.c int main(int argc, char **argv) · line 44
Quoted 3 lines
tests/tcg/multiarch/linux/linux-sigrtminmax.c +0
-0int tsig1, hsig1, count1, tsig2, hsig2, count2;char rt_sigmap[64 ];
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
Quoted 22 lines · Markus Armbruster
Quoted 20 lines · Max Filippov
Fix
new_argvallocation size to be(argc + 2) * sizeof(char *)bytes, which matches the way it's used to storeargc + 2pointers.This fixes the test for me, which otherwise fails on xtensa with the following message
linux-sigrtminmax.c: 59: main: Assertion `execve(new_argv[0],new_argv, environ) == 0' failed.'.Signed-off-by Max Filippov <[email protected]>--- tests/tcg/multiarch/linux/linux-sigrtminmax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/tcg/multiarch/linux/linux-sigrtminmax.c +0
-0@@ -39,7 +39,7 @@ int main(int argc, char **argv)assert (qemu);
Quoted 7 lines
tests/tcg/multiarch/linux/linux-sigrtminmax.c int main(int argc, char **argv) · line 42
Quoted 3 lines
tests/tcg/multiarch/linux/linux-sigrtminmax.c +1
-1if (!getenv ("QEMU_RTSIG_MAP" )) { -char **new_argv =malloc ((argc +2 ) +sizeof (char *)); +char **new_argv =malloc ((argc +2 ) *sizeof (char *));If you can switch to glib's malloc, then
g_new(argc + 2, sizeof(char *))is better. Yes, @argc can't become big enough for the multiplication to overflow, butg_new()removes the need for reasoning.
Not for TCG test cases - we are limited to plain old glibc.
Quoted 3 lines
Quoted 3 lines
tests/tcg/multiarch/linux/linux-sigrtminmax.c +0
-0int tsig1, hsig1, count1, tsig2, hsig2, count2;char rt_sigmap[64 ];
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Quoted 9 lines · Max Filippov
Fix
new_argvallocation size to be(argc + 2) * sizeof(char *)bytes, which matches the way it's used to storeargc + 2pointers.This fixes the test for me, which otherwise fails on xtensa with the following message
linux-sigrtminmax.c: 59: main: Assertion `execve(new_argv[0],new_argv, environ) == 0' failed.'.Signed-off-by Max Filippov <[email protected]>
Queued to testing/next, thanks.
<snip>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro