Skip to contentSkip to conversation

kernel/syscalls/fallocate: fix array parameter degradation

PATCH Superseded Wei,Jiangang 6 participants 18 messages May 6, 2015 – May 19, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 kernel/syscalls/fallocate: fix array parameter degradation

Using 'sizeof' on array given as function argument returns size of a pointer, instead of the array's. So,
It needs to pass an additional parameter size_t size indicating the number of elements in the array.

This patch can fix it.

---
 testcases/kernel/syscalls/fallocate/fallocate04.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
testcases/kernel/syscalls/fallocate/fallocate04.c +1 -2
index 723c886..a6d1159 100644
@@ -98,9 +98,8 @@ static void setup(void)
 	get_blocksize();
 }
 
-static void check_file_data(const char exp_buf[])
+static void check_file_data(const char exp_buf[], size_t size)
 {
-	size_t size = sizeof(exp_buf);
 	char rbuf[size];
 
 	tst_resm(TINFO, "reading the file, compare with expected buffer");
Signature · 13 lines
1.9.3


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

PATCH 2/3 kernel/syscalls/fallocate: specify size needs check

Compare size_t size elements with file data and check if it's excpeted.
This patch depends on bff5968.

---
 testcases/kernel/syscalls/fallocate/fallocate04.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/fallocate/fallocate04.c +3 -3
index a6d1159..2da0bcd 100644
@@ -174,7 +174,7 @@ static void test02(void)
 	fill_tst_buf(exp_buf);
 	memset(exp_buf + block_size, 0, block_size);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, sizeof(exp_buf)/sizeof(exp_buf[0]));
 
 	tst_resm(TPASS, "test-case succeeded");
 }
@@ -214,7 +214,7 @@ static void test03(void)
 	fill_tst_buf(exp_buf);
 	memset(exp_buf + block_size - 1, 0, block_size + 2);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, sizeof(exp_buf)/sizeof(exp_buf[0]));
 
 	tst_resm(TPASS, "test-case succeeded");
 }
@@ -250,7 +250,7 @@ static void test04(void)
 	memcpy(exp_buf, tmp_buf, block_size);
 	memcpy(exp_buf + block_size, tmp_buf + size, block_size);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, sizeof(exp_buf)/sizeof(exp_buf[0]));
 
 	tst_resm(TPASS, "test-case succeeded");
 }
Signature · 13 lines
1.9.3


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#2 lore raw

Re: [LTP] [PATCH 2/3] kernel/syscalls/fallocate: specify size needs check

Hi,

Quoted 14 lines · Wei,Jiangang

Compare size_t size elements with file data and check if it's excpeted.
This patch depends on bff5968.

---
  testcases/kernel/syscalls/fallocate/fallocate04.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/fallocate/fallocate04.c +0 -0
index a6d1159..2da0bcd 100644

testcases/kernel/syscalls/fallocate/fallocate04.c static void test02(void) · line 177

Quoted 5 lines
testcases/kernel/syscalls/fallocate/fallocate04.c +1 -1
@@ -174,7 +174,7 @@ static void test02(void)
  	fill_tst_buf(exp_buf);
  	memset(exp_buf + block_size, 0, block_size);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, sizeof(exp_buf)/sizeof(exp_buf[0]));

Thank you for fixing it.

We could you use size variables already defined for 'exp_buf[buf_size]'.

testcases/kernel/syscalls/fallocate/fallocate04.c static void test03(void) · line 218

Quoted 10 lines
testcases/kernel/syscalls/fallocate/fallocate04.c +1 -1
  	tst_resm(TPASS, "test-case succeeded");
  }
@@ -214,7 +214,7 @@ static void test03(void)
  	fill_tst_buf(exp_buf);
  	memset(exp_buf + block_size - 1, 0, block_size + 2);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, sizeof(exp_buf)/sizeof(exp_buf[0]));
 

Also buf_size variable here.

testcases/kernel/syscalls/fallocate/fallocate04.c static void test04(void) · line 254

Quoted 9 lines
testcases/kernel/syscalls/fallocate/fallocate04.c +1 -1
  	tst_resm(TPASS, "test-case succeeded");
  }
@@ -250,7 +250,7 @@ static void test04(void)
  	memcpy(exp_buf, tmp_buf, block_size);
  	memcpy(exp_buf + block_size, tmp_buf + size, block_size);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, sizeof(exp_buf)/sizeof(exp_buf[0]));
 

'size' variable here.

testcases/kernel/syscalls/fallocate/fallocate04.c static void test04(void) · line 256

Quoted 2 lines
testcases/kernel/syscalls/fallocate/fallocate04.c +0 -0
  	tst_resm(TPASS, "test-case succeeded");
  }

Now test04 fails because I forgot to set adjacent two bytes in 'exp_buf' to zero in test04(), it could be fixed as follows:

@@ -250,8 +249,8 @@ static void test04(void)

         memcpy(exp_buf, tmp_buf, block_size);
         memcpy(exp_buf + block_size, tmp_buf + size, block_size);
-
-       check_file_data(exp_buf);
+       exp_buf[block_size - 1] = exp_buf[block_size] = '\0';
+       check_file_data(exp_buf, size);
         tst_resm(TPASS, "test-case succeeded");

}

I think it would be better to merge fallocate04 fixes in a single patch.

Thanks,
Alexey

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#3 lore raw

Re: [LTP] [PATCH 2/3] kernel/syscalls/fallocate: specify size needs check

Thanks for your comments.
I will update it.

Thanks,
wei

Quoted 70 lines · Alexey Kodanev

Hi,

Quoted 14 lines · Wei,Jiangang

Compare size_t size elements with file data and check if it's excpeted.
This patch depends on bff5968.

---
  testcases/kernel/syscalls/fallocate/fallocate04.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/fallocate/fallocate04.c +0 -0
index a6d1159..2da0bcd 100644

testcases/kernel/syscalls/fallocate/fallocate04.c static void test02(void) · line 177

Quoted 5 lines
testcases/kernel/syscalls/fallocate/fallocate04.c +1 -1
@@ -174,7 +174,7 @@ static void test02(void)
  	fill_tst_buf(exp_buf);
  	memset(exp_buf + block_size, 0, block_size);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, sizeof(exp_buf)/sizeof(exp_buf[0]));

Thank you for fixing it.

We could you use size variables already defined for 'exp_buf[buf_size]'.

testcases/kernel/syscalls/fallocate/fallocate04.c static void test03(void) · line 218

Quoted 10 lines
testcases/kernel/syscalls/fallocate/fallocate04.c +1 -1
  	tst_resm(TPASS, "test-case succeeded");
  }
@@ -214,7 +214,7 @@ static void test03(void)
  	fill_tst_buf(exp_buf);
  	memset(exp_buf + block_size - 1, 0, block_size + 2);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, sizeof(exp_buf)/sizeof(exp_buf[0]));
 

Also buf_size variable here.

testcases/kernel/syscalls/fallocate/fallocate04.c static void test04(void) · line 254

Quoted 9 lines
testcases/kernel/syscalls/fallocate/fallocate04.c +1 -1
  	tst_resm(TPASS, "test-case succeeded");
  }
@@ -250,7 +250,7 @@ static void test04(void)
  	memcpy(exp_buf, tmp_buf, block_size);
  	memcpy(exp_buf + block_size, tmp_buf + size, block_size);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, sizeof(exp_buf)/sizeof(exp_buf[0]));
 

'size' variable here.

testcases/kernel/syscalls/fallocate/fallocate04.c static void test04(void) · line 256

Quoted 2 lines
testcases/kernel/syscalls/fallocate/fallocate04.c +0 -0
  	tst_resm(TPASS, "test-case succeeded");
  }

Now test04 fails because I forgot to set adjacent two bytes in 'exp_buf' to zero in test04(), it could be fixed as follows:

testcases/kernel/syscalls/fallocate/fallocate04.c +2 -2
@@ -250,8 +249,8 @@ static void test04(void)
 
         memcpy(exp_buf, tmp_buf, block_size);
         memcpy(exp_buf + block_size, tmp_buf + size, block_size);
-
-       check_file_data(exp_buf);
+       exp_buf[block_size - 1] = exp_buf[block_size] = '\0';
+       check_file_data(exp_buf, size);
 
         tst_resm(TPASS, "test-case succeeded");
  }
Quoted 4 lines

I think it would be better to merge fallocate04 fixes in a single patch.

Thanks,
Alexey

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#4 lore raw

PATCH v2 1/1 kernel/syscalls/fallocate: fix array parameter degradation

In reply to Alexey Kodanev

Using 'sizeof' on array given as function argument returns size of a pointer, instead of the array's. So,
It needs to pass an additional parameter size_t size indicating the number of elements in the array.

Besides above,
Set adjacent two bytes in 'exp_buf' to zero in test04().

---
 testcases/kernel/syscalls/fallocate/fallocate04.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
testcases/kernel/syscalls/fallocate/fallocate04.c +5 -5
index 723c886..911bbe8 100644
@@ -98,9 +98,8 @@ static void setup(void)
 	get_blocksize();
 }
 
-static void check_file_data(const char exp_buf[])
+static void check_file_data(const char exp_buf[], size_t size)
 {
-	size_t size = sizeof(exp_buf);
 	char rbuf[size];
 
 	tst_resm(TINFO, "reading the file, compare with expected buffer");
@@ -175,7 +174,7 @@ static void test02(void)
 	fill_tst_buf(exp_buf);
 	memset(exp_buf + block_size, 0, block_size);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, buf_size);
 
 	tst_resm(TPASS, "test-case succeeded");
 }
@@ -215,7 +214,7 @@ static void test03(void)
 	fill_tst_buf(exp_buf);
 	memset(exp_buf + block_size - 1, 0, block_size + 2);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, buf_size);
 
 	tst_resm(TPASS, "test-case succeeded");
 }
@@ -251,7 +250,8 @@ static void test04(void)
 	memcpy(exp_buf, tmp_buf, block_size);
 	memcpy(exp_buf + block_size, tmp_buf + size, block_size);
 
-	check_file_data(exp_buf);
+	exp_buf[block_size - 1] = exp_buf[block_size] = '\0';
+	check_file_data(exp_buf, size);
 
 	tst_resm(TPASS, "test-case succeeded");
 }
Signature · 13 lines
1.9.3


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#5 lore raw

Hi,

Quoted 48 lines · Wei,Jiangang

Using 'sizeof' on array given as function argument returns size of a pointer, instead of the array's. So,
It needs to pass an additional parameter size_t size indicating the number of elements in the array.

Besides above,
Set adjacent two bytes in 'exp_buf' to zero in test04().

---
  testcases/kernel/syscalls/fallocate/fallocate04.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
testcases/kernel/syscalls/fallocate/fallocate04.c +3 -4
index 723c886..911bbe8 100644
@@ -98,9 +98,8 @@ static void setup(void)
  	get_blocksize();
  }
 
-static void check_file_data(const char exp_buf[])
+static void check_file_data(const char exp_buf[], size_t size)
  {
-	size_t size = sizeof(exp_buf);
  	char rbuf[size];
 
  	tst_resm(TINFO, "reading the file, compare with expected buffer");
@@ -175,7 +174,7 @@ static void test02(void)
  	fill_tst_buf(exp_buf);
  	memset(exp_buf + block_size, 0, block_size);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, buf_size);
 
  	tst_resm(TPASS, "test-case succeeded");
  }
@@ -215,7 +214,7 @@ static void test03(void)
  	fill_tst_buf(exp_buf);
  	memset(exp_buf + block_size - 1, 0, block_size + 2);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, buf_size);
 
  	tst_resm(TPASS, "test-case succeeded");
  }

testcases/kernel/syscalls/fallocate/fallocate04.c static void test04(void) · line 257

Quoted 9 lines
testcases/kernel/syscalls/fallocate/fallocate04.c +2 -1
@@ -251,7 +250,8 @@ static void test04(void)
  	memcpy(exp_buf, tmp_buf, block_size);
  	memcpy(exp_buf + block_size, tmp_buf + size, block_size);
 
-	check_file_data(exp_buf);
+	exp_buf[block_size - 1] = exp_buf[block_size] = '\0';
+	check_file_data(exp_buf, size);
 
  	tst_resm(TPASS, "test-case succeeded");
  }

Patch applied, thank you!

Best regards,
Alexey

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#6 lore raw
Quoted 53 lines · Alexey Kodanev

Hi,

Quoted 51 lines · Wei,Jiangang

Using 'sizeof' on array given as function argument returns size of a pointer, instead of the array's. So,
It needs to pass an additional parameter size_t size indicating the number of elements in the array.

Besides above,
Set adjacent two bytes in 'exp_buf' to zero in test04().

---
  testcases/kernel/syscalls/fallocate/fallocate04.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
testcases/kernel/syscalls/fallocate/fallocate04.c +3 -4
index 723c886..911bbe8 100644
@@ -98,9 +98,8 @@ static void setup(void)
  	get_blocksize();
  }
 
-static void check_file_data(const char exp_buf[])
+static void check_file_data(const char exp_buf[], size_t size)
  {
-	size_t size = sizeof(exp_buf);
  	char rbuf[size];
 
  	tst_resm(TINFO, "reading the file, compare with expected buffer");
@@ -175,7 +174,7 @@ static void test02(void)
  	fill_tst_buf(exp_buf);
  	memset(exp_buf + block_size, 0, block_size);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, buf_size);
 
  	tst_resm(TPASS, "test-case succeeded");
  }
@@ -215,7 +214,7 @@ static void test03(void)
  	fill_tst_buf(exp_buf);
  	memset(exp_buf + block_size - 1, 0, block_size + 2);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, buf_size);
 
  	tst_resm(TPASS, "test-case succeeded");
  }
@@ -251,7 +250,8 @@ static void test04(void)
  	memcpy(exp_buf, tmp_buf, block_size);
  	memcpy(exp_buf + block_size, tmp_buf + size, block_size);
 
Quoted 8 lines

testcases/kernel/syscalls/fallocate/fallocate04.c static void test04(void) · line 257

Quoted 6 lines
testcases/kernel/syscalls/fallocate/fallocate04.c +2 -1
-	check_file_data(exp_buf);
+	exp_buf[block_size - 1] = exp_buf[block_size] = '\0';
+	check_file_data(exp_buf, size);
 
  	tst_resm(TPASS, "test-case succeeded");
  }

Patch applied, thank you!

Thank you for your feedback so quickly.
Do you have noticed the other commit?
->[PATCH 3/3] kernel/mem/mmapstress: fix resource leak

I guess it might have been ignored...

Thanks again,
Wei

Quoted 5 lines

Best regards,
Alexey

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#7 lore raw
Quoted 63 lines · Jiangang
Quoted 53 lines · Alexey Kodanev

Hi,

Quoted 51 lines · Wei,Jiangang

Using 'sizeof' on array given as function argument returns size of a pointer, instead of the array's. So,
It needs to pass an additional parameter size_t size indicating the number of elements in the array.

Besides above,
Set adjacent two bytes in 'exp_buf' to zero in test04().

---
  testcases/kernel/syscalls/fallocate/fallocate04.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
testcases/kernel/syscalls/fallocate/fallocate04.c +3 -4
index 723c886..911bbe8 100644
@@ -98,9 +98,8 @@ static void setup(void)
  	get_blocksize();
  }
 
-static void check_file_data(const char exp_buf[])
+static void check_file_data(const char exp_buf[], size_t size)
  {
-	size_t size = sizeof(exp_buf);
  	char rbuf[size];
 
  	tst_resm(TINFO, "reading the file, compare with expected buffer");
@@ -175,7 +174,7 @@ static void test02(void)
  	fill_tst_buf(exp_buf);
  	memset(exp_buf + block_size, 0, block_size);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, buf_size);
 
  	tst_resm(TPASS, "test-case succeeded");
  }
@@ -215,7 +214,7 @@ static void test03(void)
  	fill_tst_buf(exp_buf);
  	memset(exp_buf + block_size - 1, 0, block_size + 2);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, buf_size);
 
  	tst_resm(TPASS, "test-case succeeded");
  }
@@ -251,7 +250,8 @@ static void test04(void)
  	memcpy(exp_buf, tmp_buf, block_size);
  	memcpy(exp_buf + block_size, tmp_buf + size, block_size);
 
Quoted 8 lines

testcases/kernel/syscalls/fallocate/fallocate04.c static void test04(void) · line 257

Quoted 6 lines
testcases/kernel/syscalls/fallocate/fallocate04.c +2 -1
-	check_file_data(exp_buf);
+	exp_buf[block_size - 1] = exp_buf[block_size] = '\0';
+	check_file_data(exp_buf, size);
 
  	tst_resm(TPASS, "test-case succeeded");
  }

Patch applied, thank you!

Quoted 5 lines

Thank you for your feedback so quickly.
Do you have noticed the other commit?
->[PATCH 3/3] kernel/mem/mmapstress: fix resource leak

I guess it might have been ignored...

It's a bit messy, would you repost your patches which were not applied to make things more clearly?

Thanks,
Wanlong Gao

Quoted 9 lines

Thanks again,
Wei

Quoted 5 lines

Best regards,
Alexey

Quoted 12 lines

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
.

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#8 lore raw
Quoted 64 lines · Wanlong Gao
Quoted 63 lines · Jiangang
Quoted 61 lines · Alexey Kodanev

Hi,

Quoted 48 lines · Wei,Jiangang

Using 'sizeof' on array given as function argument returns size of a pointer, instead of the array's. So,
It needs to pass an additional parameter size_t size indicating the number of elements in the array.

Besides above,
Set adjacent two bytes in 'exp_buf' to zero in test04().

---
  testcases/kernel/syscalls/fallocate/fallocate04.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
testcases/kernel/syscalls/fallocate/fallocate04.c +3 -4
index 723c886..911bbe8 100644
@@ -98,9 +98,8 @@ static void setup(void)
  	get_blocksize();
  }
 
-static void check_file_data(const char exp_buf[])
+static void check_file_data(const char exp_buf[], size_t size)
  {
-	size_t size = sizeof(exp_buf);
  	char rbuf[size];
 
  	tst_resm(TINFO, "reading the file, compare with expected buffer");
@@ -175,7 +174,7 @@ static void test02(void)
  	fill_tst_buf(exp_buf);
  	memset(exp_buf + block_size, 0, block_size);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, buf_size);
 
  	tst_resm(TPASS, "test-case succeeded");
  }
@@ -215,7 +214,7 @@ static void test03(void)
  	fill_tst_buf(exp_buf);
  	memset(exp_buf + block_size - 1, 0, block_size + 2);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, buf_size);
 
  	tst_resm(TPASS, "test-case succeeded");
  }

testcases/kernel/syscalls/fallocate/fallocate04.c static void test04(void) · line 257

Quoted 9 lines
testcases/kernel/syscalls/fallocate/fallocate04.c +2 -1
@@ -251,7 +250,8 @@ static void test04(void)
  	memcpy(exp_buf, tmp_buf, block_size);
  	memcpy(exp_buf + block_size, tmp_buf + size, block_size);
 
-	check_file_data(exp_buf);
+	exp_buf[block_size - 1] = exp_buf[block_size] = '\0';
+	check_file_data(exp_buf, size);
 
  	tst_resm(TPASS, "test-case succeeded");
  }

Patch applied, thank you!

Quoted 8 lines
Quoted 5 lines

Thank you for your feedback so quickly.
Do you have noticed the other commit?
->[PATCH 3/3] kernel/mem/mmapstress: fix resource leak

I guess it might have been ignored...

It's a bit messy, would you repost your patches which were not applied to make things more clearly?

And start a new mail thread.

Thanks,
Wanlong Gao

Quoted 26 lines

Thanks,
Wanlong Gao

Quoted 9 lines

Thanks again,
Wei

Quoted 5 lines

Best regards,
Alexey

Quoted 12 lines

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
.

Quoted 2 lines

.

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#9 lore raw
Quoted 69 lines · Wanlong Gao
Quoted 68 lines · Wanlong Gao
Quoted 67 lines · Jiangang
Quoted 53 lines · Alexey Kodanev

Hi,

Quoted 51 lines · Wei,Jiangang

Using 'sizeof' on array given as function argument returns size of a pointer, instead of the array's. So,
It needs to pass an additional parameter size_t size indicating the number of elements in the array.

Besides above,
Set adjacent two bytes in 'exp_buf' to zero in test04().

---
  testcases/kernel/syscalls/fallocate/fallocate04.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
testcases/kernel/syscalls/fallocate/fallocate04.c +3 -4
index 723c886..911bbe8 100644
@@ -98,9 +98,8 @@ static void setup(void)
  	get_blocksize();
  }
 
-static void check_file_data(const char exp_buf[])
+static void check_file_data(const char exp_buf[], size_t size)
  {
-	size_t size = sizeof(exp_buf);
  	char rbuf[size];
 
  	tst_resm(TINFO, "reading the file, compare with expected buffer");
@@ -175,7 +174,7 @@ static void test02(void)
  	fill_tst_buf(exp_buf);
  	memset(exp_buf + block_size, 0, block_size);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, buf_size);
 
  	tst_resm(TPASS, "test-case succeeded");
  }
@@ -215,7 +214,7 @@ static void test03(void)
  	fill_tst_buf(exp_buf);
  	memset(exp_buf + block_size - 1, 0, block_size + 2);
 
-	check_file_data(exp_buf);
+	check_file_data(exp_buf, buf_size);
 
  	tst_resm(TPASS, "test-case succeeded");
  }
@@ -251,7 +250,8 @@ static void test04(void)
  	memcpy(exp_buf, tmp_buf, block_size);
  	memcpy(exp_buf + block_size, tmp_buf + size, block_size);
 
Quoted 8 lines

testcases/kernel/syscalls/fallocate/fallocate04.c static void test04(void) · line 257

Quoted 6 lines
testcases/kernel/syscalls/fallocate/fallocate04.c +2 -1
-	check_file_data(exp_buf);
+	exp_buf[block_size - 1] = exp_buf[block_size] = '\0';
+	check_file_data(exp_buf, size);
 
  	tst_resm(TPASS, "test-case succeeded");
  }

Patch applied, thank you!

Thank you for your feedback so quickly.
Do you have noticed the other commit?
->[PATCH 3/3] kernel/mem/mmapstress: fix resource leak

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I guess it might have been ignored...

It's a bit messy, would you repost your patches which were not applied to make things more clearly?

And start a new mail thread.

OK, I got it.

Regards,
Wei

Quoted 33 lines

Thanks,
Wanlong Gao

Quoted 28 lines

Thanks,
Wanlong Gao

Quoted 9 lines

Thanks again,
Wei

Quoted 5 lines

Best regards,
Alexey

Quoted 12 lines

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
.

.

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#10 lore raw

PATCH 3/3 kernel/mem/mmapstress: fix resource leak

In reply to Wei,Jiangang

Including memory and fd leak.

---
 testcases/kernel/mem/mmapstress/mmapstress01.c | 7 +++++++
 1 file changed, 7 insertions(+)
testcases/kernel/mem/mmapstress/mmapstress01.c +7 -0
index 0baf0e2..1db8147 100644
@@ -657,6 +657,8 @@ int fileokay(char *file, uchar_t * expbuf)
 			perror("read error");
 			/***** LTP Port *****/
 			local_flag = FAILED;
+			free(readbuf);
+			close(fd);
 			anyfail();
 			/*****	**	*****/
 			return 0;
@@ -668,6 +670,8 @@ int fileokay(char *file, uchar_t * expbuf)
 				(void)fprintf(stderr, "read %d of %ld bytes\n",
 					      (i * pagesize) + cnt,
 					      (long)mapsize);
+				free(readbuf);
+				close(fd);
 				return 0;
 			}
 		}
@@ -688,10 +692,13 @@ int fileokay(char *file, uchar_t * expbuf)
 					      "(fsize %ld)\n", i, j,
 					      statbuf.st_size);
 #endif /* LARGE_FILE */
+				free(readbuf);
+				close(fd);
 				return 0;
 			}
 		}
 	}
+	free(readbuf);
 	close(fd);
 
 	return 1;
Signature · 13 lines
1.9.3


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#11 lore raw

Re: [LTP] [PATCH 3/3] kernel/mem/mmapstress: fix resource leak

Quoted 12 lines · Wei,Jiangang

Including memory and fd leak.

---
  testcases/kernel/mem/mmapstress/mmapstress01.c | 7 +++++++
  1 file changed, 7 insertions(+)
testcases/kernel/mem/mmapstress/mmapstress01.c +0 -0
index 0baf0e2..1db8147 100644

testcases/kernel/mem/mmapstress/mmapstress01.c int fileokay(char *file, uchar_t * expbuf) · line 660

Quoted 4 lines
testcases/kernel/mem/mmapstress/mmapstress01.c +1 -0
@@ -657,6 +657,8 @@ int fileokay(char *file, uchar_t * expbuf)
  			perror("read error");
  			/***** LTP Port *****/
  			local_flag = FAILED;
+			free(readbuf);

We could allocate readbuf on the stack... readbuf[pagesize] so free() not needed.

testcases/kernel/mem/mmapstress/mmapstress01.c int fileokay(char *file, uchar_t * expbuf) · line 662

Quoted 2 lines
testcases/kernel/mem/mmapstress/mmapstress01.c +1 -0
+			close(fd);
  			anyfail();

anyfail() calls tst_brkm() - the program terminates and closes fd.

Quoted 12 lines
testcases/kernel/mem/mmapstress/mmapstress01.c +2 -0
  			/*****	**	*****/
  			return 0;
@@ -668,6 +670,8 @@ int fileokay(char *file, uchar_t * expbuf)
  				(void)fprintf(stderr, "read %d of %ld bytes\n",
  					      (i * pagesize) + cnt,
  					      (long)mapsize);
+				free(readbuf);
+				close(fd);
  				return 0;
  			}
  		}

testcases/kernel/mem/mmapstress/mmapstress01.c int fileokay(char *file, uchar_t * expbuf) · line 697

Quoted 6 lines
testcases/kernel/mem/mmapstress/mmapstress01.c +2 -0
@@ -688,10 +692,13 @@ int fileokay(char *file, uchar_t * expbuf)
  					      "(fsize %ld)\n", i, j,
  					      statbuf.st_size);
  #endif /* LARGE_FILE */
+				free(readbuf);
+				close(fd);
  				return 0;

In both above cases it'll call anyfail() after checking fileokay()'s return value.
If it seems not obvious we can close 'fd' here and it'd be better to use SAFE_CLOSE() macro from safe_macros.h.

testcases/kernel/mem/mmapstress/mmapstress01.c int fileokay(char *file, uchar_t * expbuf) · line 704

Quoted 7 lines
testcases/kernel/mem/mmapstress/mmapstress01.c +1 -0
  			}
  		}
  	}
+	free(readbuf);
  	close(fd);
 
  	return 1;

Thanks,
Alexey

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#12 lore raw

Re: [LTP] [PATCH 3/3] kernel/mem/mmapstress: fix resource leak

Quoted 8 lines · Alexey Kodanev
Quoted 7 lines · Wei,Jiangang

Including memory and fd leak.

---
  testcases/kernel/mem/mmapstress/mmapstress01.c | 7 +++++++
  1 file changed, 7 insertions(+)
Quoted 12 lines

testcases/kernel/mem/mmapstress/mmapstress01.c int fileokay(char *file, uchar_t * expbuf) · line 660

Quoted 9 lines
testcases/kernel/mem/mmapstress/mmapstress01.c +1 -0
index 0baf0e2..1db8147 100644
@@ -657,6 +657,8 @@ int fileokay(char *file, uchar_t * expbuf)
  			perror("read error");
  			/***** LTP Port *****/
  			local_flag = FAILED;
+			free(readbuf);

We could allocate readbuf on the stack... readbuf[pagesize] so free() not needed.

Thanks for your comments.
Yes, That's right.
I accept it.

Quoted 21 lines

testcases/kernel/mem/mmapstress/mmapstress01.c int fileokay(char *file, uchar_t * expbuf) · line 662

Quoted 3 lines
testcases/kernel/mem/mmapstress/mmapstress01.c +1 -0
+			close(fd);
  			anyfail();

anyfail() calls tst_brkm() - the program terminates and closes fd.

Quoted 15 lines
testcases/kernel/mem/mmapstress/mmapstress01.c +2 -0
  			/*****	**	*****/
  			return 0;
@@ -668,6 +670,8 @@ int fileokay(char *file, uchar_t * expbuf)
  				(void)fprintf(stderr, "read %d of %ld bytes\n",
  					      (i * pagesize) + cnt,
  					      (long)mapsize);
+				free(readbuf);
+				close(fd);
  				return 0;
  			}
  		}
@@ -688,10 +692,13 @@ int fileokay(char *file, uchar_t * expbuf)
  					      "(fsize %ld)\n", i, j,
  					      statbuf.st_size);
  #endif /* LARGE_FILE */
Quoted 8 lines

testcases/kernel/mem/mmapstress/mmapstress01.c int fileokay(char *file, uchar_t * expbuf) · line 664

Quoted 3 lines
testcases/kernel/mem/mmapstress/mmapstress01.c +2 -0
+				free(readbuf);
+				close(fd);
  				return 0;

In both above cases it'll call anyfail() after checking fileokay()'s return value.
If it seems not obvious we can close 'fd' here and it'd be better to use SAFE_CLOSE() macro from safe_macros.h.

There's no cleanup function for SAFE_CLOSE().
so,
close() is the same as SAFE_CLOSE(NULL, fd).

And close(fd) had been used at mmapstress01.c.
if i adopt SAFE_CLOSE(NULL, fd),
It looks a bit odd...

Thanks,
Wei

Quoted 11 lines

testcases/kernel/mem/mmapstress/mmapstress01.c int fileokay(char *file, uchar_t * expbuf) · line 704

Quoted 8 lines
testcases/kernel/mem/mmapstress/mmapstress01.c +1 -0
  			}
  		}
  	}
+	free(readbuf);
  	close(fd);
 
  	return 1;

Thanks,
Alexey

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#13 lore raw

Re: [LTP] [PATCH 3/3] kernel/mem/mmapstress: fix resource leak

Hi!

Quoted 2 lines

There's no cleanup function for SAFE_CLOSE(). so,
close() is the same as SAFE_CLOSE(NULL, fd).

FYI, there is a difference between plain close() and SAFE_CLOSE(NULL, fd). The latter checks the return value from close(). Have a look at lib/safe_macros.c.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#14 lore raw

Re: [LTP] [PATCH 3/3] kernel/mem/mmapstress: fix resource leak

In reply to Wei, Jiangang

Hi,

Quoted 9 lines · Jiangang
Quoted 4 lines · Alexey Kodanev

In both above cases it'll call anyfail() after checking fileokay()'s return value.
If it seems not obvious we can close 'fd' here and it'd be better to use SAFE_CLOSE() macro from safe_macros.h.

There's no cleanup function for SAFE_CLOSE().
so,
close() is the same as SAFE_CLOSE(NULL, fd).

tst_brkm() is using tst_rmdir() as a cleanup function.

Best regards,
Alexey

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#15 lore raw

PATCH v2 1/1 kernel/mem/mmapstress: fix resource leak

In reply to Alexey Kodanev

* Avoid memory leak by allocate readbuf on the stack, not by malloc.

* close file descriptor explicitly before return.

---
 testcases/kernel/mem/mmapstress/mmapstress01.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
testcases/kernel/mem/mmapstress/mmapstress01.c +3 -2
index 0baf0e2..ed1466a 100644
@@ -602,9 +602,9 @@ int fileokay(char *file, uchar_t * expbuf)
 	struct stat statbuf;
 #endif /* LARGE_FILE */
 	size_t mapsize;
-	uchar_t *readbuf;
 	unsigned mappages;
 	unsigned pagesize = sysconf(_SC_PAGE_SIZE);
+	char readbuf[pagesize];
 	int fd;
 	int cnt;
 	unsigned i, j;
@@ -641,7 +641,6 @@ int fileokay(char *file, uchar_t * expbuf)
 		perror("lseek");
 		anyfail();
 	}
-	readbuf = malloc(pagesize);
 
 	if (statbuf.st_size - sparseoffset > SIZE_MAX) {
 		fprintf(stderr, "size_t overflow when setting up map\n");
@@ -668,6 +667,7 @@ int fileokay(char *file, uchar_t * expbuf)
 				(void)fprintf(stderr, "read %d of %ld bytes\n",
 					      (i * pagesize) + cnt,
 					      (long)mapsize);
+				close(fd);
 				return 0;
 			}
 		}
@@ -688,6 +688,7 @@ int fileokay(char *file, uchar_t * expbuf)
 					      "(fsize %ld)\n", i, j,
 					      statbuf.st_size);
 #endif /* LARGE_FILE */
+				close(fd);
 				return 0;
 			}
 		}
Signature · 13 lines
1.9.3


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#16 lore raw

PATCH 1/1 mmapstress01: Modify readbuf's type and define it to uchar_t

In reply to Wei,Jiangang

readbuf is defined to char. That is different with the previous defined. If readbuf's value is more than 127, that would be regarded as negative number. And expbuf is uchar_t, the value is always nonegative. That will make the test fail because the different data type.

---
 testcases/kernel/mem/mmapstress/mmapstress01.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/mem/mmapstress/mmapstress01.c +1 -1
index ed1466a..81566f2 100644
@@ -604,7 +604,7 @@ int fileokay(char *file, uchar_t * expbuf)
 	size_t mapsize;
 	unsigned mappages;
 	unsigned pagesize = sysconf(_SC_PAGE_SIZE);
-	char readbuf[pagesize];
+	uchar_t readbuf[pagesize];
 	int fd;
 	int cnt;
 	unsigned i, j;
Signature · 15 lines
1.9.3




------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Applied
#17 lore raw

Re: [LTP] [PATCH] mmapstress01: Modify readbuf's type and define it to uchar_t

----- Original Message -----

Quoted 6 lines

From: "Zeng Linggang" <[email protected]>
To: "Jiangang Wei" <[email protected]>
Cc: [email protected]
Sent: Tuesday, 19 May, 2015 5:34:01 AM
Subject: [LTP] [PATCH] mmapstress01: Modify readbuf's type and define it to uchar_t

Quoted 7 lines

readbuf is defined to char. That is different with the previous defined. If readbuf's value is more than 127, that would be regarded as negative number. And expbuf is uchar_t, the value is always nonegative. That will make the test fail because the different data type.

Applied.

Regards,
Jan

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list