* [PATCH] selftests/nolibc: avoid buffer underrun in space printing
@ 2023-07-26 6:08 Thomas Weißschuh
2023-07-29 7:29 ` Willy Tarreau
0 siblings, 1 reply; 2+ messages in thread
From: Thomas Weißschuh @ 2023-07-26 6:08 UTC (permalink / raw)
To: Willy Tarreau, Shuah Khan, Zhangjin Wu
Cc: linux-kselftest, linux-kernel, Thomas Weißschuh
If the test description is longer than the status alignment the
parameter 'n' to putcharn() would lead to a signed underflow that then
gets converted to a very large unsigned value.
This in turn leads out-of-bound writes in memset() crashing the
application.
The failure case of EXPECT_PTRER() used in "mmap_bad" exhibits this
exact behavior.
Fixes: 8a27526f49f9 ("selftests/nolibc: add EXPECT_PTREQ, EXPECT_PTRNE and EXPECT_PTRER")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
tools/testing/selftests/nolibc/nolibc-test.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 03b1d30f5507..9b76603e4ce3 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -151,7 +151,8 @@ static void result(int llen, enum RESULT r)
else
msg = "[FAIL]";
- putcharn(' ', 64 - llen);
+ if (llen < 64)
+ putcharn(' ', 64 - llen);
puts(msg);
}
---
base-commit: dfef4fc45d5713eb23d87f0863aff9c33bd4bfaf
change-id: 20230726-nolibc-result-width-1f4b0b4f3ca0
Best regards,
--
Thomas Weißschuh <linux@weissschuh.net>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] selftests/nolibc: avoid buffer underrun in space printing
2023-07-26 6:08 [PATCH] selftests/nolibc: avoid buffer underrun in space printing Thomas Weißschuh
@ 2023-07-29 7:29 ` Willy Tarreau
0 siblings, 0 replies; 2+ messages in thread
From: Willy Tarreau @ 2023-07-29 7:29 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Shuah Khan, Zhangjin Wu, linux-kselftest, linux-kernel
On Wed, Jul 26, 2023 at 08:08:13AM +0200, Thomas Weißschuh wrote:
> If the test description is longer than the status alignment the
> parameter 'n' to putcharn() would lead to a signed underflow that then
> gets converted to a very large unsigned value.
> This in turn leads out-of-bound writes in memset() crashing the
> application.
>
> The failure case of EXPECT_PTRER() used in "mmap_bad" exhibits this
> exact behavior.
>
> Fixes: 8a27526f49f9 ("selftests/nolibc: add EXPECT_PTREQ, EXPECT_PTRNE and EXPECT_PTRER")
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Applied, thank you Thomas!
Willy
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-07-29 7:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-26 6:08 [PATCH] selftests/nolibc: avoid buffer underrun in space printing Thomas Weißschuh
2023-07-29 7:29 ` Willy Tarreau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox