Re: [PATCH 2/4] selftests/sigaltstack: Fix the sas test on old kernels

2016-05-08 Thread Andy Lutomirski
On May 7, 2016 8:02 AM, "Stas Sergeev"  wrote:
>
> 03.05.2016 20:31, Andy Lutomirski пишет:
>
>> The handling for old kernels was wrong.  Fix it.
>>
>> Reported-by: Ingo Molnar 
>> Cc: Stas Sergeev 
>> Cc: Al Viro 
>> Cc: Andrew Morton 
>> Cc: Andy Lutomirski 
>> Cc: Borislav Petkov 
>> Cc: Brian Gerst 
>> Cc: Denys Vlasenko 
>> Cc: H. Peter Anvin 
>> Cc: Linus Torvalds 
>> Cc: Oleg Nesterov 
>> Cc: Pavel Emelyanov 
>> Cc: Peter Zijlstra 
>> Cc: Shuah Khan 
>> Cc: Thomas Gleixner 
>> Cc: linux-...@vger.kernel.org
>> Cc: linux-kernel@vger.kernel.org
>> Signed-off-by: Andy Lutomirski 
>> ---
>>   tools/testing/selftests/sigaltstack/sas.c | 21 ++---
>>   1 file changed, 14 insertions(+), 7 deletions(-)
>>
>> diff --git a/tools/testing/selftests/sigaltstack/sas.c 
>> b/tools/testing/selftests/sigaltstack/sas.c
>> index 57da8bfde60b..a98c3ef8141f 100644
>> --- a/tools/testing/selftests/sigaltstack/sas.c
>> +++ b/tools/testing/selftests/sigaltstack/sas.c
>> @@ -15,6 +15,7 @@
>>   #include 
>>   #include 
>>   #include 
>> +#include 
>> #ifndef SS_AUTODISARM
>>   #define SS_AUTODISARM  (1 << 4)
>> @@ -117,13 +118,19 @@ int main(void)
>> stk.ss_flags = SS_ONSTACK | SS_AUTODISARM;
>> err = sigaltstack(, NULL);
>> if (err) {
>> -   perror("[FAIL]\tsigaltstack(SS_ONSTACK | SS_AUTODISARM)");
>> -   stk.ss_flags = SS_ONSTACK;
>> -   }
>> -   err = sigaltstack(, NULL);
>> -   if (err) {
>> -   perror("[FAIL]\tsigaltstack(SS_ONSTACK)");
>> -   return EXIT_FAILURE;
>> +   if (errno == EINVAL) {
>> +   printf("[NOTE]\tThe running kernel doesn't support 
>> SS_AUTODISARM\n");
>> +   /*
>> +* If test cases for the !SS_AUTODISARM variant were
>> +* added, we could still run them.  We don't have any
>> +* test cases like that yet, so just exit and report
>> +* success.
>> +*/
>
> But that was the point, please see how it handles the
> old kernels:
>
> $ ./sas
> [FAIL]sigaltstack(SS_ONSTACK | SS_AUTODISARM): Invalid argument
> [RUN]signal USR1
> [FAIL]ss_flags=1, should be SS_DISABLE
> [RUN]switched to user ctx
> [RUN]signal USR2
> [FAIL]sigaltstack re-used
> [FAIL]Stack corrupted
> [RUN]Aborting

This is useful as a demonstration of why the feature is useful, but it
doesn't indicate that anything is wrong with old kernels per she.
That's why I changed it to simply report that the feature is missing.


Re: [PATCH 2/4] selftests/sigaltstack: Fix the sas test on old kernels

2016-05-08 Thread Andy Lutomirski
On May 7, 2016 8:02 AM, "Stas Sergeev"  wrote:
>
> 03.05.2016 20:31, Andy Lutomirski пишет:
>
>> The handling for old kernels was wrong.  Fix it.
>>
>> Reported-by: Ingo Molnar 
>> Cc: Stas Sergeev 
>> Cc: Al Viro 
>> Cc: Andrew Morton 
>> Cc: Andy Lutomirski 
>> Cc: Borislav Petkov 
>> Cc: Brian Gerst 
>> Cc: Denys Vlasenko 
>> Cc: H. Peter Anvin 
>> Cc: Linus Torvalds 
>> Cc: Oleg Nesterov 
>> Cc: Pavel Emelyanov 
>> Cc: Peter Zijlstra 
>> Cc: Shuah Khan 
>> Cc: Thomas Gleixner 
>> Cc: linux-...@vger.kernel.org
>> Cc: linux-kernel@vger.kernel.org
>> Signed-off-by: Andy Lutomirski 
>> ---
>>   tools/testing/selftests/sigaltstack/sas.c | 21 ++---
>>   1 file changed, 14 insertions(+), 7 deletions(-)
>>
>> diff --git a/tools/testing/selftests/sigaltstack/sas.c 
>> b/tools/testing/selftests/sigaltstack/sas.c
>> index 57da8bfde60b..a98c3ef8141f 100644
>> --- a/tools/testing/selftests/sigaltstack/sas.c
>> +++ b/tools/testing/selftests/sigaltstack/sas.c
>> @@ -15,6 +15,7 @@
>>   #include 
>>   #include 
>>   #include 
>> +#include 
>> #ifndef SS_AUTODISARM
>>   #define SS_AUTODISARM  (1 << 4)
>> @@ -117,13 +118,19 @@ int main(void)
>> stk.ss_flags = SS_ONSTACK | SS_AUTODISARM;
>> err = sigaltstack(, NULL);
>> if (err) {
>> -   perror("[FAIL]\tsigaltstack(SS_ONSTACK | SS_AUTODISARM)");
>> -   stk.ss_flags = SS_ONSTACK;
>> -   }
>> -   err = sigaltstack(, NULL);
>> -   if (err) {
>> -   perror("[FAIL]\tsigaltstack(SS_ONSTACK)");
>> -   return EXIT_FAILURE;
>> +   if (errno == EINVAL) {
>> +   printf("[NOTE]\tThe running kernel doesn't support 
>> SS_AUTODISARM\n");
>> +   /*
>> +* If test cases for the !SS_AUTODISARM variant were
>> +* added, we could still run them.  We don't have any
>> +* test cases like that yet, so just exit and report
>> +* success.
>> +*/
>
> But that was the point, please see how it handles the
> old kernels:
>
> $ ./sas
> [FAIL]sigaltstack(SS_ONSTACK | SS_AUTODISARM): Invalid argument
> [RUN]signal USR1
> [FAIL]ss_flags=1, should be SS_DISABLE
> [RUN]switched to user ctx
> [RUN]signal USR2
> [FAIL]sigaltstack re-used
> [FAIL]Stack corrupted
> [RUN]Aborting

This is useful as a demonstration of why the feature is useful, but it
doesn't indicate that anything is wrong with old kernels per she.
That's why I changed it to simply report that the feature is missing.


Re: [PATCH 2/4] selftests/sigaltstack: Fix the sas test on old kernels

2016-05-07 Thread Stas Sergeev

03.05.2016 20:31, Andy Lutomirski пишет:

The handling for old kernels was wrong.  Fix it.

Reported-by: Ingo Molnar 
Cc: Stas Sergeev 
Cc: Al Viro 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Pavel Emelyanov 
Cc: Peter Zijlstra 
Cc: Shuah Khan 
Cc: Thomas Gleixner 
Cc: linux-...@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Andy Lutomirski 
---
  tools/testing/selftests/sigaltstack/sas.c | 21 ++---
  1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/sigaltstack/sas.c 
b/tools/testing/selftests/sigaltstack/sas.c
index 57da8bfde60b..a98c3ef8141f 100644
--- a/tools/testing/selftests/sigaltstack/sas.c
+++ b/tools/testing/selftests/sigaltstack/sas.c
@@ -15,6 +15,7 @@
  #include 
  #include 
  #include 
+#include 
  
  #ifndef SS_AUTODISARM

  #define SS_AUTODISARM  (1 << 4)
@@ -117,13 +118,19 @@ int main(void)
stk.ss_flags = SS_ONSTACK | SS_AUTODISARM;
err = sigaltstack(, NULL);
if (err) {
-   perror("[FAIL]\tsigaltstack(SS_ONSTACK | SS_AUTODISARM)");
-   stk.ss_flags = SS_ONSTACK;
-   }
-   err = sigaltstack(, NULL);
-   if (err) {
-   perror("[FAIL]\tsigaltstack(SS_ONSTACK)");
-   return EXIT_FAILURE;
+   if (errno == EINVAL) {
+   printf("[NOTE]\tThe running kernel doesn't support 
SS_AUTODISARM\n");
+   /*
+* If test cases for the !SS_AUTODISARM variant were
+* added, we could still run them.  We don't have any
+* test cases like that yet, so just exit and report
+* success.
+*/

But that was the point, please see how it handles the
old kernels:

$ ./sas
[FAIL]sigaltstack(SS_ONSTACK | SS_AUTODISARM): Invalid argument
[RUN]signal USR1
[FAIL]ss_flags=1, should be SS_DISABLE
[RUN]switched to user ctx
[RUN]signal USR2
[FAIL]sigaltstack re-used
[FAIL]Stack corrupted
[RUN]Aborting

Unfortunalely, for Ingo it crashed...
I am not sure why, I can't reproduce. :(
So if you disable all the "old" tests, you can as well
remove them, or... find the bug and re-enable. :)


Re: [PATCH 2/4] selftests/sigaltstack: Fix the sas test on old kernels

2016-05-07 Thread Stas Sergeev

03.05.2016 20:31, Andy Lutomirski пишет:

The handling for old kernels was wrong.  Fix it.

Reported-by: Ingo Molnar 
Cc: Stas Sergeev 
Cc: Al Viro 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Pavel Emelyanov 
Cc: Peter Zijlstra 
Cc: Shuah Khan 
Cc: Thomas Gleixner 
Cc: linux-...@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Andy Lutomirski 
---
  tools/testing/selftests/sigaltstack/sas.c | 21 ++---
  1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/sigaltstack/sas.c 
b/tools/testing/selftests/sigaltstack/sas.c
index 57da8bfde60b..a98c3ef8141f 100644
--- a/tools/testing/selftests/sigaltstack/sas.c
+++ b/tools/testing/selftests/sigaltstack/sas.c
@@ -15,6 +15,7 @@
  #include 
  #include 
  #include 
+#include 
  
  #ifndef SS_AUTODISARM

  #define SS_AUTODISARM  (1 << 4)
@@ -117,13 +118,19 @@ int main(void)
stk.ss_flags = SS_ONSTACK | SS_AUTODISARM;
err = sigaltstack(, NULL);
if (err) {
-   perror("[FAIL]\tsigaltstack(SS_ONSTACK | SS_AUTODISARM)");
-   stk.ss_flags = SS_ONSTACK;
-   }
-   err = sigaltstack(, NULL);
-   if (err) {
-   perror("[FAIL]\tsigaltstack(SS_ONSTACK)");
-   return EXIT_FAILURE;
+   if (errno == EINVAL) {
+   printf("[NOTE]\tThe running kernel doesn't support 
SS_AUTODISARM\n");
+   /*
+* If test cases for the !SS_AUTODISARM variant were
+* added, we could still run them.  We don't have any
+* test cases like that yet, so just exit and report
+* success.
+*/

But that was the point, please see how it handles the
old kernels:

$ ./sas
[FAIL]sigaltstack(SS_ONSTACK | SS_AUTODISARM): Invalid argument
[RUN]signal USR1
[FAIL]ss_flags=1, should be SS_DISABLE
[RUN]switched to user ctx
[RUN]signal USR2
[FAIL]sigaltstack re-used
[FAIL]Stack corrupted
[RUN]Aborting

Unfortunalely, for Ingo it crashed...
I am not sure why, I can't reproduce. :(
So if you disable all the "old" tests, you can as well
remove them, or... find the bug and re-enable. :)