mtest01.c: Increase max_pids and check for array overflow.
PATCH 1/1 mtest01.c: Increase max_pids and check for array overflow.
This test was writing past the end of the pid_list array which corrupted other data such as the stdout file structure and that resulted in incorrect output including non-ascii text. This patch increases the size of pid_list and adds checks so we don't overflow the array.
Signed-off-by Steve Ellcey <[email protected]>
--- testcases/kernel/mem/mtest01/mtest01.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
testcases/kernel/mem/mtest01/mtest01.c +7 -1
@@ -152,7 +152,7 @@ int main(int argc, char *argv[]) total_free = sstats.freeram + sstats.freeswap;/* Total Free Pre-Test RAM */ pre_mem = sstats.mem_unit * total_free; - max_pids = total_ram / (unsigned long )FIVE_HUNDRED_MB +1 ; + max_pids = total_ram / (unsigned long )FIVE_HUNDRED_MB +10 ;if ((pid_list =malloc (max_pids *sizeof (pid_t))) ==NULL )tst_brkm (TBROK |TERRNO ,NULL ,"malloc failed." );
@@ -200,6 +200,8 @@ int main(int argc, char *argv[])#if defined (_s390_)/* s390's 31bit addressing requires smaller chunks */ while (pid !=0 && maxbytes >FIVE_HUNDRED_MB ) { i++; +if (i >= max_pids) +tst_brkm (TBROK , cleanup,"max_pids needs to be increased" ); maxbytes -=FIVE_HUNDRED_MB ; pid =fork ();if (pid <0 )
@@ -217,6 +219,8 @@ int main(int argc, char *argv[])#elif __WORDSIZE ==32 while (pid !=0 && maxbytes >ONE_GB ) { i++; +if (i >= max_pids) +tst_brkm (TBROK , cleanup,"max_pids needs to be increased" ); maxbytes -=ONE_GB ; pid =fork ();if (pid <0 )
@@ -234,6 +238,8 @@ int main(int argc, char *argv[])#elif __WORDSIZE ==64 while (pid !=0 && maxbytes >THREE_GB ) { i++; +if (i >= max_pids) +tst_brkm (TBROK , cleanup,"max_pids needs to be increased" ); maxbytes -=THREE_GB ; pid =fork ();if (pid <0 )
Signature · 1 line
2.7.4
PATCH 1/1 mtest01.c: Increase max_pids and check for array overflow.
Hi!
Applied, thanks.
While we could have fixed this more elegantly (this patch is band-aid like fix) it's good enough to fix the memory corruption expecially since we want to produce another release soon enough...
Signature · 2 lines
Cyril Hrubis [email protected]