All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] genload: fix memory corruption in hogvm
@ 2024-06-10  8:56 Jiwei Sun
  0 siblings, 0 replies; 4+ messages in thread
From: Jiwei Sun @ 2024-06-10  8:56 UTC (permalink / raw)
  To: ltp, sunjw10; +Cc: ahuang12

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [LTP] [PATCH] genload: fix memory corruption in hogvm
@ 2024-06-11  2:58 Jiwei Sun
  2024-06-11 12:11 ` Cyril Hrubis
  0 siblings, 1 reply; 4+ messages in thread
From: Jiwei Sun @ 2024-06-11  2:58 UTC (permalink / raw)
  To: ltp; +Cc: ahuang12

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH] genload: fix memory corruption in hogvm
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Cyril Hrubis @ 2024-06-11 12:11 UTC (permalink / raw)
  To: Jiwei Sun; +Cc: ahuang12, ltp

Hi!
> 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 *));

Good catch, however shouldn't this be just chunks * 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 *));

Here as well.

>  				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

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH] genload: fix memory corruption in hogvm
  2024-06-11 12:11 ` Cyril Hrubis
@ 2024-06-11 12:34   ` Jiwei Sun
  0 siblings, 0 replies; 4+ messages in thread
From: Jiwei Sun @ 2024-06-11 12:34 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ahuang12, ltp

Hi Cyril,

On 6/11/24 20:11, Cyril Hrubis wrote:
> Hi!
>> 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 *));
> 
> Good catch, however shouldn't this be just chunks * sizeof(char*) ?

Yes indeed, totally agree with you, "* 2" is redundant, 
thanks for your review and reply. And also, if the chunks is 0, 
the memory will be corrupted too. I will modify it in the v2 patch.

Thanks,
Regards,
Jiwei

> 
>>  				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 *));
> 
> Here as well.
> 
>>  				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
> 

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-06-11 12:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
  -- strict thread matches above, loose matches on Subject: below --
2024-06-10  8:56 Jiwei Sun

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.