Skip to contentSkip to conversation

genload: fix memory corruption in hogvm

PATCH New Jiwei Sun 1 participant 1 message Jun 10, 2024

lore
Share & tools
lore

Jiwei Sun

author
#0 lore raw

PATCH 1/1 genload: fix memory corruption in hogvm

From: Jiwei Sun <[email protected]>

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.

---
 tools/genload/genload.c | 2 +-
 tools/genload/stress.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tools/genload/genload.c +1 -1
index 7f56d5272..9712e7828 100644
@@ -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 *
tools/genload/stress.c +1 -1
index 7f56d5272..9712e7828 100644
@@ -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 *
Signature · 5 lines
2.27.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp