From: Jiwei Sun <sjiwei@163.com>
To: ltp@lists.linux.it, sunjw10@lenovo.com
Cc: ahuang12@lenovo.com
Subject: [LTP] [PATCH] genload: fix memory corruption in hogvm
Date: Mon, 10 Jun 2024 16:56:22 +0800 [thread overview]
Message-ID: <20240610085622.87076-1-sjiwei@163.com> (raw)
From: Jiwei Sun <sunjw10@lenovo.com>
With the following command for doing memory stress test,
./genload -v --vm 10 --vm-chunks 4 --vm-bytes 1073741824
Some memory corruption issue was triggered,
malloc(): corrupted top size
The root cause of the issue is that allocated memory for ptr is less
than what is actually needed.
Signed-off-by: Jiwei Sun <sunjw10@lenovo.com>
---
tools/genload/genload.c | 2 +-
tools/genload/stress.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/genload/genload.c b/tools/genload/genload.c
index 7f56d5272..9712e7828 100644
--- a/tools/genload/genload.c
+++ b/tools/genload/genload.c
@@ -642,7 +642,7 @@ int hogvm(long long forks, long long chunks, long long bytes)
usleep(backoff);
while (1) {
- ptr = (char **)malloc(chunks * 2);
+ ptr = (char **)malloc(chunks * 2 * sizeof(char *));
for (j = 0; chunks == 0 || j < chunks; j++) {
if ((ptr[j] =
(char *)malloc(bytes *
diff --git a/tools/genload/stress.c b/tools/genload/stress.c
index 7f56d5272..9712e7828 100644
--- a/tools/genload/stress.c
+++ b/tools/genload/stress.c
@@ -642,7 +642,7 @@ int hogvm(long long forks, long long chunks, long long bytes)
usleep(backoff);
while (1) {
- ptr = (char **)malloc(chunks * 2);
+ ptr = (char **)malloc(chunks * 2 * sizeof(char *));
for (j = 0; chunks == 0 || j < chunks; j++) {
if ((ptr[j] =
(char *)malloc(bytes *
--
2.27.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2024-06-10 11:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-10 8:56 Jiwei Sun [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-06-11 2:58 [LTP] [PATCH] genload: fix memory corruption in hogvm Jiwei Sun
2024-06-11 12:11 ` Cyril Hrubis
2024-06-11 12:34 ` Jiwei Sun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240610085622.87076-1-sjiwei@163.com \
--to=sjiwei@163.com \
--cc=ahuang12@lenovo.com \
--cc=ltp@lists.linux.it \
--cc=sunjw10@lenovo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.