syscalls/setrlimit02.c: Add a test for EFAULT
PATCH 1/2 syscalls/setrlimit02.c: Add a test for EFAULT
--- testcases/kernel/syscalls/setrlimit/setrlimit02.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/setrlimit/setrlimit02.c +6 -1
@@ -18,7 +18,11 @@* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* -* Testcase to test the different errnos set by setrlimit(2) system call. +* DESCRIPTION +* 1) Test for EINVAL when resource is invalid. +* 2) Test for EFAULT when rlim points outside the accessible address space. +* 3) Test for EPERM when an unprivileged process tried to use setrlimit() to +* increase a soft or hard limit. */ #include <pwd.h> #include <errno.h>
@@ -33,6 +37,7 @@ static struct tcase {int exp_errno; } tcases[] = { {-1, &rlim, EINVAL}, + {RLIMIT_NOFILE, (void *) -1, EFAULT}, {RLIMIT_NOFILE, &rlim, EPERM} };
Signature · 1 line
1.8.3.1
PATCH 2/2 syscalls/setrlimit03.c: Cleanup && Convert to new API
1) take use of safe macros
2) add a test for EINVAL
--- testcases/kernel/syscalls/setrlimit/setrlimit03.c | 143 ++++++++-------------- 1 file changed, 53 insertions(+), 90 deletions(-)
testcases/kernel/syscalls/setrlimit/setrlimit03.c +53 -90
@@ -1,116 +1,79 @@/* +* Copyright (c) International Business Machines Corp., 2001 +* Copyright (c) 2017 Xiao Yang <[email protected]> * -* Copyright (c) International Business Machines Corp., 2001 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. * -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* -* NAME -* setrlimit03.c -* * DESCRIPTION -* Test for EPERM when the super-user tries to increase RLIMIT_NOFILE -* beyond the system limit. -* -* USAGE: <for command-line> -* setrlimit03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS -* Must run test as root. +* 1) Test for EPERM when the super-user tries to increase RLIMIT_NOFILE +* beyond the system limit. +* 2) Test for EINVAL when rlim->rlim_cur was greater than rlim->rlim_max. */ + +#include <errno.h> #include <sys/time.h> #include <sys/resource.h> -#include <unistd.h> -#include <errno.h> -#include "test.h" #include <linux/fs.h> - -char *TCID ="setrlimit03" ; -int TST_TOTAL =1 ; +#include "tst_test.h" #if !defined(NR_OPEN ) -//Taken from definition in /usr/include/linux/fs.h -#define NR_OPEN (1024*1024) +// Taken from definition in /usr/include/linux/fs.h +# define NR_OPEN (1024*1024)#endif -void setup (); -void cleanup (); - -int main (int ac,char **av) -{ -int lc; -struct rlimit rlim; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { +static struct rlimit rlim1, rlim2; - tst_count =0 ; +static struct tcase { +struct rlimit *rlimt; +int exp_err; +} tcases[] = { + {&rlim1,EPERM }, + {&rlim2,EINVAL } +}; -if (getrlimit (RLIMIT_NOFILE , &rlim) !=0 ) -tst_brkm (TFAIL , cleanup,"getrlimit failed, " -"errno = %d" , errno); - rlim.rlim_max =NR_OPEN +1 ; - -TEST (setrlimit (RLIMIT_NOFILE , &rlim)); - -if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"call succeeded unexpectedly" ); -continue ; - } +static void verify_setrlimit (unsigned int n) +{ +struct tcase *tc = &tcases[n]; -if (TEST_ERRNO !=EPERM ) { -tst_resm (TFAIL ,"Expected EPERM, got %d" ,TEST_ERRNO ); - }else { -tst_resm (TPASS ,"got expected EPERM error" ); - } +TEST (setrlimit (RLIMIT_NOFILE , tc->rlimt)); +if (TEST_RETURN !=-1 ) { +tst_res (TFAIL ,"call succeeded unexpectedly" ); +return ; } -cleanup (); -tst_exit (); +if (TEST_ERRNO != tc->exp_err) { +tst_res (TFAIL |TTERRNO ,"setrlimit() should fail with %s, got" , +tst_strerrno (tc->exp_err)); + }else { +tst_res (TPASS |TTERRNO ,"setrlimit() failed as expected" ); + } } -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) +static void setup (void ) { -tst_require_root (); - -tst_sig (FORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; +SAFE_GETRLIMIT (RLIMIT_NOFILE , &rlim1); + rlim2.rlim_max = rlim1.rlim_cur; + rlim2.rlim_cur = rlim1.rlim_max +1 ; + rlim1.rlim_max =NR_OPEN +1 ; } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -} +static struct tst_test test = { + .setup = setup, + .tcnt =ARRAY_SIZE (tcases), + .test = verify_setrlimit, + .needs_root =1 +};
Signature · 1 line
1.8.3.1
PATCH 1/2 syscalls/setrlimit02.c: Add a test for EFAULT
In reply to Xiao YangHi!
Quoted 5 lines
+ * DESCRIPTION
+ * 1) Test for EINVAL when resource is invalid. + * 2) Test for EFAULT when rlim points outside the accessible address space. + * 3) Test for EPERM when an unprivileged process tried to use setrlimit() to+ * increase a soft or hard limit.
We increase only the hard limit here hence this description is misleading, we should say here that unprivileged process is trying to increase the hard limit.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/2 syscalls/setrlimit02.c: Add a test for EFAULT
--- testcases/kernel/syscalls/setrlimit/setrlimit02.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/setrlimit/setrlimit02.c +6 -1
@@ -18,7 +18,11 @@* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* -* Testcase to test the different errnos set by setrlimit(2) system call. +* DESCRIPTION +* 1) Test for EINVAL when resource is invalid. +* 2) Test for EFAULT when rlim points outside the accessible address space. +* 3) Test for EPERM when an unprivileged process tries to increase the +* hard limit. */ #include <pwd.h> #include <errno.h>
@@ -33,6 +37,7 @@ static struct tcase {int exp_errno; } tcases[] = { {-1, &rlim, EINVAL}, + {RLIMIT_NOFILE, (void *) -1, EFAULT}, {RLIMIT_NOFILE, &rlim, EPERM} };
Signature · 1 line
1.8.3.1
PATCH v2 2/2 syscalls/setrlimit03.c: Cleanup && Convert to new API
1) take use of safe macros
2) add a test for EINVAL
--- testcases/kernel/syscalls/setrlimit/setrlimit03.c | 143 ++++++++-------------- 1 file changed, 53 insertions(+), 90 deletions(-)
testcases/kernel/syscalls/setrlimit/setrlimit03.c +53 -90
@@ -1,116 +1,79 @@/* +* Copyright (c) International Business Machines Corp., 2001 +* Copyright (c) 2017 Xiao Yang <[email protected]> * -* Copyright (c) International Business Machines Corp., 2001 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. * -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* -* NAME -* setrlimit03.c -* * DESCRIPTION -* Test for EPERM when the super-user tries to increase RLIMIT_NOFILE -* beyond the system limit. -* -* USAGE: <for command-line> -* setrlimit03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS -* Must run test as root. +* 1) Test for EPERM when the super-user tries to increase RLIMIT_NOFILE +* beyond the system limit. +* 2) Test for EINVAL when rlim->rlim_cur is greater than rlim->rlim_max. */ + +#include <errno.h> #include <sys/time.h> #include <sys/resource.h> -#include <unistd.h> -#include <errno.h> -#include "test.h" #include <linux/fs.h> - -char *TCID ="setrlimit03" ; -int TST_TOTAL =1 ; +#include "tst_test.h" #if !defined(NR_OPEN ) -//Taken from definition in /usr/include/linux/fs.h -#define NR_OPEN (1024*1024) +// Taken from definition in /usr/include/linux/fs.h +# define NR_OPEN (1024*1024)#endif -void setup (); -void cleanup (); - -int main (int ac,char **av) -{ -int lc; -struct rlimit rlim; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { +static struct rlimit rlim1, rlim2; - tst_count =0 ; +static struct tcase { +struct rlimit *rlimt; +int exp_err; +} tcases[] = { + {&rlim1,EPERM }, + {&rlim2,EINVAL } +}; -if (getrlimit (RLIMIT_NOFILE , &rlim) !=0 ) -tst_brkm (TFAIL , cleanup,"getrlimit failed, " -"errno = %d" , errno); - rlim.rlim_max =NR_OPEN +1 ; - -TEST (setrlimit (RLIMIT_NOFILE , &rlim)); - -if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"call succeeded unexpectedly" ); -continue ; - } +static void verify_setrlimit (unsigned int n) +{ +struct tcase *tc = &tcases[n]; -if (TEST_ERRNO !=EPERM ) { -tst_resm (TFAIL ,"Expected EPERM, got %d" ,TEST_ERRNO ); - }else { -tst_resm (TPASS ,"got expected EPERM error" ); - } +TEST (setrlimit (RLIMIT_NOFILE , tc->rlimt)); +if (TEST_RETURN !=-1 ) { +tst_res (TFAIL ,"call succeeded unexpectedly" ); +return ; } -cleanup (); -tst_exit (); +if (TEST_ERRNO != tc->exp_err) { +tst_res (TFAIL |TTERRNO ,"setrlimit() should fail with %s, got" , +tst_strerrno (tc->exp_err)); + }else { +tst_res (TPASS |TTERRNO ,"setrlimit() failed as expected" ); + } } -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) +static void setup (void ) { -tst_require_root (); - -tst_sig (FORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; +SAFE_GETRLIMIT (RLIMIT_NOFILE , &rlim1); + rlim2.rlim_max = rlim1.rlim_cur; + rlim2.rlim_cur = rlim1.rlim_max +1 ; + rlim1.rlim_max =NR_OPEN +1 ; } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -} +static struct tst_test test = { + .setup = setup, + .tcnt =ARRAY_SIZE (tcases), + .test = verify_setrlimit, + .needs_root =1 +};
Signature · 1 line
1.8.3.1
PATCH v2 2/2 syscalls/setrlimit03.c: Cleanup && Convert to new API
Hi Cyril,
Could you help me review this patch? Thanks a lot.
Thanks,
Xiao Yang
Quoted 182 lines · Xiao Yang
1) take use of safe macros
2) add a test for EINVALSigned-off-by Xiao Yang <[email protected]>--- testcases/kernel/syscalls/setrlimit/setrlimit03.c | 143 ++++++++-------------- 1 file changed, 53 insertions(+), 90 deletions(-)testcases/kernel/syscalls/setrlimit/setrlimit03.c +53
-90@@ -1,116 +1,79 @@/* +* Copyright (c) International Business Machines Corp., 2001 +* Copyright (c) 2017 Xiao Yang <[email protected]> * -* Copyright (c) International Business Machines Corp., 2001 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. * -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* -* NAME -* setrlimit03.c -* * DESCRIPTION -* Test for EPERM when the super-user tries to increase RLIMIT_NOFILE -* beyond the system limit. -* -* USAGE: <for command-line> -* setrlimit03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS -* Must run test as root. +* 1) Test for EPERM when the super-user tries to increase RLIMIT_NOFILE +* beyond the system limit. +* 2) Test for EINVAL when rlim->rlim_cur is greater than rlim->rlim_max. */ + +#include <errno.h> #include <sys/time.h> #include <sys/resource.h> -#include <unistd.h> -#include <errno.h> -#include "test.h" #include <linux/fs.h> - -char *TCID ="setrlimit03" ; -int TST_TOTAL =1 ; +#include "tst_test.h" #if !defined(NR_OPEN ) -//Taken from definition in /usr/include/linux/fs.h -#define NR_OPEN (1024*1024) +// Taken from definition in /usr/include/linux/fs.h +# define NR_OPEN (1024*1024)#endif -void setup (); -void cleanup (); - -int main (int ac,char **av) -{ -int lc; -struct rlimit rlim; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { +static struct rlimit rlim1, rlim2; - tst_count =0 ; +static struct tcase { +struct rlimit *rlimt; +int exp_err; +} tcases[] = { + {&rlim1,EPERM }, + {&rlim2,EINVAL } +}; -if (getrlimit (RLIMIT_NOFILE , &rlim) !=0 ) -tst_brkm (TFAIL , cleanup,"getrlimit failed, " -"errno = %d" , errno); - rlim.rlim_max =NR_OPEN +1 ; - -TEST (setrlimit (RLIMIT_NOFILE , &rlim)); - -if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"call succeeded unexpectedly" ); -continue ; - } +static void verify_setrlimit (unsigned int n) +{ +struct tcase *tc = &tcases[n]; -if (TEST_ERRNO !=EPERM ) { -tst_resm (TFAIL ,"Expected EPERM, got %d" ,TEST_ERRNO ); - }else { -tst_resm (TPASS ,"got expected EPERM error" ); - } +TEST (setrlimit (RLIMIT_NOFILE , tc->rlimt)); +if (TEST_RETURN !=-1 ) { +tst_res (TFAIL ,"call succeeded unexpectedly" ); +return ; } -cleanup (); -tst_exit (); +if (TEST_ERRNO != tc->exp_err) { +tst_res (TFAIL |TTERRNO ,"setrlimit() should fail with %s, got" , +tst_strerrno (tc->exp_err)); + }else { +tst_res (TPASS |TTERRNO ,"setrlimit() failed as expected" ); + } } -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) +static void setup (void ) { -tst_require_root (); - -tst_sig (FORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; +SAFE_GETRLIMIT (RLIMIT_NOFILE , &rlim1); + rlim2.rlim_max = rlim1.rlim_cur; + rlim2.rlim_cur = rlim1.rlim_max +1 ; + rlim1.rlim_max =NR_OPEN +1 ; } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -} +static struct tst_test test = { + .setup = setup, + .tcnt =ARRAY_SIZE (tcases), + .test = verify_setrlimit, + .needs_root =1 +};
PATCH v2 2/2 syscalls/setrlimit03.c: Cleanup && Convert to new API
In reply to Xiao YangHi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/2 syscalls/setrlimit02.c: Add a test for EFAULT
In reply to Xiao YangHi!
Quoted 9 lines
+ * DESCRIPTION
+ * 1) Test for EINVAL when resource is invalid. + * 2) Test for EFAULT when rlim points outside the accessible address space. + * 3) Test for EPERM when an unprivileged process tries to increase the+ * hard limit.
*/
#include <pwd.h>
#include <errno.h>
testcases/kernel/syscalls/setrlimit/setrlimit02.c static struct tcase { · line 42
Quoted 6 lines
testcases/kernel/syscalls/setrlimit/setrlimit02.c +1
-0@@ -33,6 +37,7 @@ static struct tcase {int exp_errno; } tcases[] = { {-1, &rlim, EINVAL}, + {RLIMIT_NOFILE, (void *) -1, EFAULT}, {RLIMIT_NOFILE, &rlim, EPERM} };
I've rembered why there is no EFAULT test for the setrlimit:
commit 259db6fed55f88ab32a0875e66803eee44d298be
Author: Cyril Hrubis <[email protected]> Date: Thu Aug 17 13:42:20 2017 +0200
syscalls/setrlimit02: Remove the EFAULT test
...
https://github.com/linux-test-project/ltp/issues/193
So if we really want to add this one, we have to either run the test in the child and produce PASS on SegFault or call the raw syscall for the EFAULT test. Either way I think that we should put it in a seprate testcase if the test is really needed.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/2 syscalls/setrlimit05.c: Add a test for EFAULT
1) Usually, setrlimit() returns EFAULT when rlim points outside the accessible address space.
2) In some cases, setrlimit() could return SIGSEGV as expected when rlim points outside the accessible address space. Please see the following url for reasons:
https://github.com/linux-test-project/ltp/issues/193
--- runtest/syscalls | 1 + testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/setrlimit/setrlimit05.c | 66 +++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 testcases/kernel/syscalls/setrlimit/setrlimit05.c
runtest/syscalls +1 -0
@@ -1142,6 +1142,7 @@ setrlimit01 setrlimit01 setrlimit02 setrlimit02 setrlimit03 setrlimit03 setrlimit04 setrlimit04 +setrlimit05 setrlimit05 set_robust_list01 set_robust_list01 set_thread_area01 set_thread_area01
testcases/kernel/syscalls/.gitignore +1 -0
@@ -930,6 +930,7 @@ /setrlimit/setrlimit02 /setrlimit/setrlimit03 /setrlimit/setrlimit04 +/setrlimit/setrlimit05 /setsid/setsid01 /setsockopt/setsockopt01 /settimeofday/settimeofday01
testcases/kernel/syscalls/setrlimit/setrlimit05.c new file +66 -0
66 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 1/2 syscalls/setrlimit05.c: Add a test for EFAULT
Hi!
Quoted 11 lines
testcases/kernel/syscalls/setrlimit/setrlimit05.c new file +11
-0+#define _GNU_SOURCE +#include <errno.h> +#include <sys/resource.h> +#include <sys/time.h> +#include <sys/wait.h> +#include <stdlib.h> + +#include "tst_test.h" + +static void verify_setrlimit (void ) +{
testcases/kernel/syscalls/setrlimit/setrlimit05.c line 40
Quoted 10 lines
testcases/kernel/syscalls/setrlimit/setrlimit05.c new file +10
-0+int status; +pid_t pid; + + pid =SAFE_FORK (); +if (!pid) { +TEST (setrlimit (RLIMIT_NOFILE , (void *)-1 )); +if (TEST_RETURN ==-1 &&TEST_ERRNO ==EFAULT ) +exit (0 ); + +exit (1 );
Can we do the PASS/FAIL for the expected errno here?
Then we need to handle just the TPASS in the parent in case of SegFault.
Quoted 15 lines
testcases/kernel/syscalls/setrlimit/setrlimit05.c new file +15
-0+ } + +SAFE_WAITPID (pid, &status,0 ); + +/* Usually, setrlimit() should return EFAULT */ +if (WIFEXITED (status) &&WEXITSTATUS (status) ==0 ) { +tst_res (TPASS ,"setrlimit() returned EFAULT as expected" ); +return ; + } + +/* If glibc has to convert between 32bit and 64bit struct rlimit +* in some cases, it is possible to get SegFault. +*/ +if (!WIFEXITED (status) &&WIFSIGNALED (status) ==SIGSEGV ) { +tst_res (TPASS ,"setrlimit() returned SIGSEGV as expected" );
testcases/kernel/syscalls/setrlimit/setrlimit05.c line 65
Quoted 10 lines
testcases/kernel/syscalls/setrlimit/setrlimit05.c new file +10
-0+return ; + } + +tst_res (TFAIL ,"setrlimit() did not return EFAULT or SIGSEGV" ); +} + +static struct tst_test test = { + .test_all = verify_setrlimit, + .forks_child =1 , + .needs_root =1 ,
Do we really need root?
Quoted 6 lines
+};
Signature · 1 line
1.8.3.1
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 1/2 syscalls/setrlimit05.c: Add a test for EFAULT
1) Usually, setrlimit() returns EFAULT when rlim points outside the accessible address space.
2) In some cases, setrlimit() could return SIGSEGV as expected when rlim points outside the accessible address space. Please see the following url for reasons:
https://github.com/linux-test-project/ltp/issues/193
--- runtest/syscalls | 1 + testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/setrlimit/setrlimit05.c | 73 +++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 testcases/kernel/syscalls/setrlimit/setrlimit05.c
runtest/syscalls +1 -0
@@ -1142,6 +1142,7 @@ setrlimit01 setrlimit01 setrlimit02 setrlimit02 setrlimit03 setrlimit03 setrlimit04 setrlimit04 +setrlimit05 setrlimit05 set_robust_list01 set_robust_list01 set_thread_area01 set_thread_area01
testcases/kernel/syscalls/.gitignore +1 -0
@@ -930,6 +930,7 @@ /setrlimit/setrlimit02 /setrlimit/setrlimit03 /setrlimit/setrlimit04 +/setrlimit/setrlimit05 /setsid/setsid01 /setsockopt/setsockopt01 /settimeofday/settimeofday01
testcases/kernel/syscalls/setrlimit/setrlimit05.c new file +73 -0
73 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v4 1/2 syscalls/setrlimit05.c: Add a test for EFAULT
Hi!
Quoted 14 lines
testcases/kernel/syscalls/setrlimit/setrlimit05.c new file +14
-0+/* +* Test for EFAULT when rlim points outside the accessible address space. +*/ + +#define _GNU_SOURCE +#include <errno.h> +#include <sys/resource.h> +#include <sys/time.h> +#include <sys/wait.h> +#include <stdlib.h> + +#include "tst_test.h" + +static void verify_setrlimit (void )
testcases/kernel/syscalls/setrlimit/setrlimit05.c line 39
Quoted 10 lines
testcases/kernel/syscalls/setrlimit/setrlimit05.c new file +10
-0+{ +int status; +pid_t pid; + + pid =SAFE_FORK (); +if (!pid) { +TEST (setrlimit (RLIMIT_NOFILE , (void *)-1 )); +if (TEST_RETURN !=-1 ) { +tst_res (TFAIL ,"setrlimit() succeeded unexpectedly" ); + goto end;
^
Why not just exit(0) here?
Quoted 11 lines
testcases/kernel/syscalls/setrlimit/setrlimit05.c new file +11
-0+ } + +/* Usually, setrlimit() should return EFAULT */ +if (TEST_ERRNO ==EFAULT ) { +tst_res (TPASS |TTERRNO , +"setrlimit() failed as expected" ); + }else { +tst_res (TFAIL |TTERRNO , +"setrlimit() should fail with EFAULT, got" ); + } +end:
testcases/kernel/syscalls/setrlimit/setrlimit05.c line 60
Quoted 10 lines
testcases/kernel/syscalls/setrlimit/setrlimit05.c new file +10
-0+exit (0 ); + } + +SAFE_WAITPID (pid, &status,0 ); + +/* If glibc has to convert between 32bit and 64bit struct rlimit +* in some cases, it is possible to get SegFault. +*/ +if (!WIFEXITED (status)) { +if (WIFSIGNALED (status) ==SIGSEGV ) {
^ This is wrong, we have to use WTERMSIG(status) == SIGSEGV
testcases/kernel/syscalls/setrlimit/setrlimit05.c line 66
Quoted 6 lines
testcases/kernel/syscalls/setrlimit/setrlimit05.c new file +6
-0+tst_res (TPASS , +"setrlimit() returned SIGSEGV as expected" ); + }else { +tst_res (TFAIL ,"setrlimit() did not return SIGSEGV" ); + } + }
We should generally do something as:
if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
tst_res(TPASS, "setrlimit() caused SIGSEGV");
return;
}
tst_brk(TBROK, "Child ended with status %i", status);But that prints the status as a number, which is hard to decipher. And this is not the first time pattern like this emerges in test code. Maybe we just need a library function to dissect the status as returned by wait and print it content, then we can print the status in human-readable format here and exit. I will try to sketch such function and send a patch to ML as RFC.
Quoted 11 lines
testcases/kernel/syscalls/setrlimit/setrlimit05.c new file +6
-0+} + +static struct tst_test test = { + .test_all = verify_setrlimit, + .forks_child =1 , +};Signature · 1 line
1.8.3.1
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v5 1/2 syscalls/setrlimit05.c: Add a test for EFAULT
1) Usually, setrlimit() returns EFAULT when rlim points outside the accessible address space.
2) In some cases, setrlimit() could return SIGSEGV as expected when rlim points outside the accessible address space. Please see the following url for reasons:
https://github.com/linux-test-project/ltp/issues/193
--- runtest/syscalls | 1 + testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/setrlimit/setrlimit05.c | 73 +++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 testcases/kernel/syscalls/setrlimit/setrlimit05.c
runtest/syscalls +1 -0
@@ -1144,6 +1144,7 @@ setrlimit01 setrlimit01 setrlimit02 setrlimit02 setrlimit03 setrlimit03 setrlimit04 setrlimit04 +setrlimit05 setrlimit05 set_robust_list01 set_robust_list01 set_thread_area01 set_thread_area01
testcases/kernel/syscalls/.gitignore +1 -0
@@ -931,6 +931,7 @@ /setrlimit/setrlimit02 /setrlimit/setrlimit03 /setrlimit/setrlimit04 +/setrlimit/setrlimit05 /setsid/setsid01 /setsockopt/setsockopt01 /settimeofday/settimeofday01
testcases/kernel/syscalls/setrlimit/setrlimit05.c new file +73 -0
73 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v5 1/2 syscalls/setrlimit05.c: Add a test for EFAULT
Hi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]