* [LTP] [PATCH 1/2] syscalls/setrlimit02.c: Add a test for EFAULT @ 2017-10-04 5:51 Xiao Yang 2017-10-04 5:52 ` [LTP] [PATCH 2/2] syscalls/setrlimit03.c: Cleanup && Convert to new API Xiao Yang 2017-10-09 14:23 ` [LTP] [PATCH 1/2] syscalls/setrlimit02.c: Add a test for EFAULT Cyril Hrubis 0 siblings, 2 replies; 14+ messages in thread From: Xiao Yang @ 2017-10-04 5:51 UTC (permalink / raw) To: ltp Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com> --- testcases/kernel/syscalls/setrlimit/setrlimit02.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit02.c b/testcases/kernel/syscalls/setrlimit/setrlimit02.c index 633279c..abcf2bc 100644 --- a/testcases/kernel/syscalls/setrlimit/setrlimit02.c +++ b/testcases/kernel/syscalls/setrlimit/setrlimit02.c @@ -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} }; -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [LTP] [PATCH 2/2] syscalls/setrlimit03.c: Cleanup && Convert to new API 2017-10-04 5:51 [LTP] [PATCH 1/2] syscalls/setrlimit02.c: Add a test for EFAULT Xiao Yang @ 2017-10-04 5:52 ` Xiao Yang 2017-10-09 14:23 ` [LTP] [PATCH 1/2] syscalls/setrlimit02.c: Add a test for EFAULT Cyril Hrubis 1 sibling, 0 replies; 14+ messages in thread From: Xiao Yang @ 2017-10-04 5:52 UTC (permalink / raw) To: ltp 1) take use of safe macros 2) add a test for EINVAL Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com> --- testcases/kernel/syscalls/setrlimit/setrlimit03.c | 143 ++++++++-------------- 1 file changed, 53 insertions(+), 90 deletions(-) diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit03.c b/testcases/kernel/syscalls/setrlimit/setrlimit03.c index e0beb17..b4da6e4 100644 --- a/testcases/kernel/syscalls/setrlimit/setrlimit03.c +++ b/testcases/kernel/syscalls/setrlimit/setrlimit03.c @@ -1,116 +1,79 @@ /* + * Copyright (c) International Business Machines Corp., 2001 + * Copyright (c) 2017 Xiao Yang <yangx.jy@cn.fujitsu.com> * - * 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 +}; -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [LTP] [PATCH 1/2] syscalls/setrlimit02.c: Add a test for EFAULT 2017-10-04 5:51 [LTP] [PATCH 1/2] syscalls/setrlimit02.c: Add a test for EFAULT Xiao Yang 2017-10-04 5:52 ` [LTP] [PATCH 2/2] syscalls/setrlimit03.c: Cleanup && Convert to new API Xiao Yang @ 2017-10-09 14:23 ` Cyril Hrubis 2017-10-10 1:52 ` [LTP] [PATCH v2 " Xiao Yang 1 sibling, 1 reply; 14+ messages in thread From: Cyril Hrubis @ 2017-10-09 14:23 UTC (permalink / raw) To: ltp Hi! > + * 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. -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 14+ messages in thread
* [LTP] [PATCH v2 1/2] syscalls/setrlimit02.c: Add a test for EFAULT 2017-10-09 14:23 ` [LTP] [PATCH 1/2] syscalls/setrlimit02.c: Add a test for EFAULT Cyril Hrubis @ 2017-10-10 1:52 ` Xiao Yang 2017-10-10 1:52 ` [LTP] [PATCH v2 2/2] syscalls/setrlimit03.c: Cleanup && Convert to new API Xiao Yang 2017-10-10 12:55 ` [LTP] [PATCH v2 1/2] syscalls/setrlimit02.c: Add a test for EFAULT Cyril Hrubis 0 siblings, 2 replies; 14+ messages in thread From: Xiao Yang @ 2017-10-10 1:52 UTC (permalink / raw) To: ltp Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com> --- testcases/kernel/syscalls/setrlimit/setrlimit02.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit02.c b/testcases/kernel/syscalls/setrlimit/setrlimit02.c index 633279c..d1781ec 100644 --- a/testcases/kernel/syscalls/setrlimit/setrlimit02.c +++ b/testcases/kernel/syscalls/setrlimit/setrlimit02.c @@ -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} }; -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [LTP] [PATCH v2 2/2] syscalls/setrlimit03.c: Cleanup && Convert to new API 2017-10-10 1:52 ` [LTP] [PATCH v2 " Xiao Yang @ 2017-10-10 1:52 ` Xiao Yang 2017-10-19 5:12 ` Xiao Yang 2017-10-26 8:31 ` Cyril Hrubis 2017-10-10 12:55 ` [LTP] [PATCH v2 1/2] syscalls/setrlimit02.c: Add a test for EFAULT Cyril Hrubis 1 sibling, 2 replies; 14+ messages in thread From: Xiao Yang @ 2017-10-10 1:52 UTC (permalink / raw) To: ltp 1) take use of safe macros 2) add a test for EINVAL Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com> --- testcases/kernel/syscalls/setrlimit/setrlimit03.c | 143 ++++++++-------------- 1 file changed, 53 insertions(+), 90 deletions(-) diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit03.c b/testcases/kernel/syscalls/setrlimit/setrlimit03.c index e0beb17..d551c90 100644 --- a/testcases/kernel/syscalls/setrlimit/setrlimit03.c +++ b/testcases/kernel/syscalls/setrlimit/setrlimit03.c @@ -1,116 +1,79 @@ /* + * Copyright (c) International Business Machines Corp., 2001 + * Copyright (c) 2017 Xiao Yang <yangx.jy@cn.fujitsu.com> * - * 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 +}; -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [LTP] [PATCH v2 2/2] syscalls/setrlimit03.c: Cleanup && Convert to new API 2017-10-10 1:52 ` [LTP] [PATCH v2 2/2] syscalls/setrlimit03.c: Cleanup && Convert to new API Xiao Yang @ 2017-10-19 5:12 ` Xiao Yang 2017-10-26 8:31 ` Cyril Hrubis 1 sibling, 0 replies; 14+ messages in thread From: Xiao Yang @ 2017-10-19 5:12 UTC (permalink / raw) To: ltp Hi Cyril, Could you help me review this patch? Thanks a lot. Thanks, Xiao Yang On 2017/10/10 9:52, Xiao Yang wrote: > 1) take use of safe macros > 2) add a test for EINVAL > > Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com> > --- > testcases/kernel/syscalls/setrlimit/setrlimit03.c | 143 ++++++++-------------- > 1 file changed, 53 insertions(+), 90 deletions(-) > > diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit03.c b/testcases/kernel/syscalls/setrlimit/setrlimit03.c > index e0beb17..d551c90 100644 > --- a/testcases/kernel/syscalls/setrlimit/setrlimit03.c > +++ b/testcases/kernel/syscalls/setrlimit/setrlimit03.c > @@ -1,116 +1,79 @@ > /* > + * Copyright (c) International Business Machines Corp., 2001 > + * Copyright (c) 2017 Xiao Yang <yangx.jy@cn.fujitsu.com> > * > - * 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 > +}; ^ permalink raw reply [flat|nested] 14+ messages in thread
* [LTP] [PATCH v2 2/2] syscalls/setrlimit03.c: Cleanup && Convert to new API 2017-10-10 1:52 ` [LTP] [PATCH v2 2/2] syscalls/setrlimit03.c: Cleanup && Convert to new API Xiao Yang 2017-10-19 5:12 ` Xiao Yang @ 2017-10-26 8:31 ` Cyril Hrubis 1 sibling, 0 replies; 14+ messages in thread From: Cyril Hrubis @ 2017-10-26 8:31 UTC (permalink / raw) To: ltp Hi! Pushed, thanks. -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 14+ messages in thread
* [LTP] [PATCH v2 1/2] syscalls/setrlimit02.c: Add a test for EFAULT 2017-10-10 1:52 ` [LTP] [PATCH v2 " Xiao Yang 2017-10-10 1:52 ` [LTP] [PATCH v2 2/2] syscalls/setrlimit03.c: Cleanup && Convert to new API Xiao Yang @ 2017-10-10 12:55 ` Cyril Hrubis 2017-10-11 4:43 ` [LTP] [PATCH v3 1/2] syscalls/setrlimit05.c: " Xiao Yang 1 sibling, 1 reply; 14+ messages in thread From: Cyril Hrubis @ 2017-10-10 12:55 UTC (permalink / raw) To: ltp Hi! > + * 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} > }; I've rembered why there is no EFAULT test for the setrlimit: commit 259db6fed55f88ab32a0875e66803eee44d298be Author: Cyril Hrubis <chrubis@suse.cz> 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. -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 14+ messages in thread
* [LTP] [PATCH v3 1/2] syscalls/setrlimit05.c: Add a test for EFAULT 2017-10-10 12:55 ` [LTP] [PATCH v2 1/2] syscalls/setrlimit02.c: Add a test for EFAULT Cyril Hrubis @ 2017-10-11 4:43 ` Xiao Yang 2017-10-11 11:46 ` Cyril Hrubis 0 siblings, 1 reply; 14+ messages in thread From: Xiao Yang @ 2017-10-11 4:43 UTC (permalink / raw) To: ltp 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 Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com> --- 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 diff --git a/runtest/syscalls b/runtest/syscalls index 2362a23..dc1c452 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -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 diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore index 930f3f9..e4a8df2 100644 --- a/testcases/kernel/syscalls/.gitignore +++ b/testcases/kernel/syscalls/.gitignore @@ -930,6 +930,7 @@ /setrlimit/setrlimit02 /setrlimit/setrlimit03 /setrlimit/setrlimit04 +/setrlimit/setrlimit05 /setsid/setsid01 /setsockopt/setsockopt01 /settimeofday/settimeofday01 diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit05.c b/testcases/kernel/syscalls/setrlimit/setrlimit05.c new file mode 100644 index 0000000..3d708df --- /dev/null +++ b/testcases/kernel/syscalls/setrlimit/setrlimit05.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017 FUJITSU LIMITED. All rights reserved. + * Author: Xiao Yang <yangx.jy@cn.fujitsu.com> + * + * 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. + */ + +/* + * 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) +{ + 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); + } + + 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"); + 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, +}; -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [LTP] [PATCH v3 1/2] syscalls/setrlimit05.c: Add a test for EFAULT 2017-10-11 4:43 ` [LTP] [PATCH v3 1/2] syscalls/setrlimit05.c: " Xiao Yang @ 2017-10-11 11:46 ` Cyril Hrubis 2017-10-11 12:26 ` [LTP] [PATCH v4 " Xiao Yang 0 siblings, 1 reply; 14+ messages in thread From: Cyril Hrubis @ 2017-10-11 11:46 UTC (permalink / raw) To: ltp Hi! > +#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) > +{ > + 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. > + } > + > + 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"); > + 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? > +}; > -- > 1.8.3.1 > > > -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 14+ messages in thread
* [LTP] [PATCH v4 1/2] syscalls/setrlimit05.c: Add a test for EFAULT 2017-10-11 11:46 ` Cyril Hrubis @ 2017-10-11 12:26 ` Xiao Yang 2017-10-12 14:15 ` Cyril Hrubis 0 siblings, 1 reply; 14+ messages in thread From: Xiao Yang @ 2017-10-11 12:26 UTC (permalink / raw) To: ltp 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 Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com> --- 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 diff --git a/runtest/syscalls b/runtest/syscalls index 2362a23..dc1c452 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -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 diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore index 930f3f9..e4a8df2 100644 --- a/testcases/kernel/syscalls/.gitignore +++ b/testcases/kernel/syscalls/.gitignore @@ -930,6 +930,7 @@ /setrlimit/setrlimit02 /setrlimit/setrlimit03 /setrlimit/setrlimit04 +/setrlimit/setrlimit05 /setsid/setsid01 /setsockopt/setsockopt01 /settimeofday/settimeofday01 diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit05.c b/testcases/kernel/syscalls/setrlimit/setrlimit05.c new file mode 100644 index 0000000..d690085 --- /dev/null +++ b/testcases/kernel/syscalls/setrlimit/setrlimit05.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2017 FUJITSU LIMITED. All rights reserved. + * Author: Xiao Yang <yangx.jy@cn.fujitsu.com> + * + * 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. + */ + +/* + * 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) +{ + 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; + } + + /* 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: + 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) { + tst_res(TPASS, + "setrlimit() returned SIGSEGV as expected"); + } else { + tst_res(TFAIL, "setrlimit() did not return SIGSEGV"); + } + } + +} + +static struct tst_test test = { + .test_all = verify_setrlimit, + .forks_child = 1, +}; -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [LTP] [PATCH v4 1/2] syscalls/setrlimit05.c: Add a test for EFAULT 2017-10-11 12:26 ` [LTP] [PATCH v4 " Xiao Yang @ 2017-10-12 14:15 ` Cyril Hrubis 2017-10-16 10:30 ` [LTP] [PATCH v5 " Xiao Yang 0 siblings, 1 reply; 14+ messages in thread From: Cyril Hrubis @ 2017-10-12 14:15 UTC (permalink / raw) To: ltp Hi! > +/* > + * 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) > +{ > + 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? > + } > + > + /* 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: > + 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 > + 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. > +} > + > +static struct tst_test test = { > + .test_all = verify_setrlimit, > + .forks_child = 1, > +}; > -- > 1.8.3.1 > > > -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 14+ messages in thread
* [LTP] [PATCH v5 1/2] syscalls/setrlimit05.c: Add a test for EFAULT 2017-10-12 14:15 ` Cyril Hrubis @ 2017-10-16 10:30 ` Xiao Yang 2017-10-18 15:07 ` Cyril Hrubis 0 siblings, 1 reply; 14+ messages in thread From: Xiao Yang @ 2017-10-16 10:30 UTC (permalink / raw) To: ltp 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 Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com> --- 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 diff --git a/runtest/syscalls b/runtest/syscalls index b1e988d..ad67dfa 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -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 diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore index 4dc2f8b..4caf547 100644 --- a/testcases/kernel/syscalls/.gitignore +++ b/testcases/kernel/syscalls/.gitignore @@ -931,6 +931,7 @@ /setrlimit/setrlimit02 /setrlimit/setrlimit03 /setrlimit/setrlimit04 +/setrlimit/setrlimit05 /setsid/setsid01 /setsockopt/setsockopt01 /settimeofday/settimeofday01 diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit05.c b/testcases/kernel/syscalls/setrlimit/setrlimit05.c new file mode 100644 index 0000000..7ea7d62 --- /dev/null +++ b/testcases/kernel/syscalls/setrlimit/setrlimit05.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2017 FUJITSU LIMITED. All rights reserved. + * Author: Xiao Yang <yangx.jy@cn.fujitsu.com> + * + * 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. + */ + +/* + * 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) +{ + 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"); + exit(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"); + } + + 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 (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) { + tst_res(TPASS, "setrlimit() caused SIGSEGV"); + return; + } + + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) + return; + + tst_res(TBROK, "child %s", tst_strstatus(status)); +} + +static struct tst_test test = { + .test_all = verify_setrlimit, + .forks_child = 1, +}; -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [LTP] [PATCH v5 1/2] syscalls/setrlimit05.c: Add a test for EFAULT 2017-10-16 10:30 ` [LTP] [PATCH v5 " Xiao Yang @ 2017-10-18 15:07 ` Cyril Hrubis 0 siblings, 0 replies; 14+ messages in thread From: Cyril Hrubis @ 2017-10-18 15:07 UTC (permalink / raw) To: ltp Hi! Pushed, thanks. -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2017-10-26 8:31 UTC | newest] Thread overview: 14+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2017-10-04 5:51 [LTP] [PATCH 1/2] syscalls/setrlimit02.c: Add a test for EFAULT Xiao Yang 2017-10-04 5:52 ` [LTP] [PATCH 2/2] syscalls/setrlimit03.c: Cleanup && Convert to new API Xiao Yang 2017-10-09 14:23 ` [LTP] [PATCH 1/2] syscalls/setrlimit02.c: Add a test for EFAULT Cyril Hrubis 2017-10-10 1:52 ` [LTP] [PATCH v2 " Xiao Yang 2017-10-10 1:52 ` [LTP] [PATCH v2 2/2] syscalls/setrlimit03.c: Cleanup && Convert to new API Xiao Yang 2017-10-19 5:12 ` Xiao Yang 2017-10-26 8:31 ` Cyril Hrubis 2017-10-10 12:55 ` [LTP] [PATCH v2 1/2] syscalls/setrlimit02.c: Add a test for EFAULT Cyril Hrubis 2017-10-11 4:43 ` [LTP] [PATCH v3 1/2] syscalls/setrlimit05.c: " Xiao Yang 2017-10-11 11:46 ` Cyril Hrubis 2017-10-11 12:26 ` [LTP] [PATCH v4 " Xiao Yang 2017-10-12 14:15 ` Cyril Hrubis 2017-10-16 10:30 ` [LTP] [PATCH v5 " Xiao Yang 2017-10-18 15:07 ` Cyril Hrubis
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox