syscalls/prctl02: add more error tests
PATCH 1/1 syscalls/prctl02: add more error tests
--- include/lapi/prctl.h | 10 ++++ testcases/kernel/syscalls/prctl/prctl02.c | 68 ++++++++++++++++++++--- 2 files changed, 71 insertions(+), 7 deletions(-)
include/lapi/prctl.h +10 -0
@@ -29,6 +29,11 @@# define PR_GET_NO_NEW_PRIVS 39#endif +#ifndef PR_SET_THP_DISABLE +# define PR_SET_THP_DISABLE 41 +# define PR_GET_THP_DISABLE 42 +#endif +#ifndef PR_CAP_AMBIENT # define PR_CAP_AMBIENT 47# define PR_CAP_AMBIENT_IS_SET 1
@@ -37,4 +42,9 @@# define PR_CAP_AMBIENT_CLEAR_ALL 4#endif +#ifndef PR_GET_SPECULATION_CTRL +# define PR_GET_SPECULATION_CTRL 52 +# define PR_SET_SPECULATION_CTRL 53 +#endif +#endif /* LAPI_PRCTL_H__ */
testcases/kernel/syscalls/prctl/prctl02.c +61 -7
104 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v2 1/1 syscalls/prctl02: add more error tests
------v1->v2:
1. add EACCES tests
2. remove ENOSYS, if kernel doesn't support option, it reports EINVAL. use ltp-prctl.m4 to distinguish.
------
--- include/lapi/prctl.h | 10 +++ m4/ltp-prctl.m4 | 3 +- testcases/kernel/syscalls/prctl/prctl02.c | 104 ++++++++++++++++++++-- 3 files changed, 110 insertions(+), 7 deletions(-)
include/lapi/prctl.h +10 -0
@@ -29,6 +29,11 @@# define PR_GET_NO_NEW_PRIVS 39#endif +#ifndef PR_SET_THP_DISABLE +# define PR_SET_THP_DISABLE 41 +# define PR_GET_THP_DISABLE 42 +#endif +#ifndef PR_CAP_AMBIENT # define PR_CAP_AMBIENT 47# define PR_CAP_AMBIENT_IS_SET 1
@@ -37,4 +42,9 @@# define PR_CAP_AMBIENT_CLEAR_ALL 4#endif +#ifndef PR_GET_SPECULATION_CTRL +# define PR_GET_SPECULATION_CTRL 52 +# define PR_SET_SPECULATION_CTRL 53 +#endif +#endif /* LAPI_PRCTL_H__ */
m4/ltp-prctl.m4 +2 -1
@@ -4,7 +4,8 @@ dnl Author: Ngie Cooper <[email protected]> AC_DEFUN([LTP_CHECK_PRCTL_SUPPORT],[ AC_CHECK_HEADERS(sys/prctl.h,[ - AC_CHECK_DECLS([PR_CAPBSET_DROP, PR_CAPBSET_READ], [],[],[ + AC_CHECK_DECLS([PR_CAPBSET_DROP, PR_CAPBSET_READ, PR_CAP_AMBIENT, +PR_SET_NO_NEW_PRIVS, PR_GET_SPECULATION_CTRL, PR_SET_THP_DISABLE], [],[],[ #include <sys/prctl.h> ]) dnl AC_CHECK_DECLS ])]
testcases/kernel/syscalls/prctl/prctl02.c +98 -6
141 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v2 1/1 syscalls/prctl02: add more error tests
Hi Xu,
testcases/kernel/syscalls/prctl/prctl02.c static void verify_prctl(unsigned int n) · line 138
Quoted 8 lines
Signed-off-by Yang Xu <[email protected]>static struct
tst_testtest = {testcases/kernel/syscalls/prctl/prctl02.c +3
-0.tcnt = ARRAY_SIZE(tcases), .test = verify_prctl, + .caps = (struct tst_cap []) { +TST_CAP (TST_CAP_DROP ,CAP_SYS_ADMIN ), +TST_CAP (TST_CAP_DROP ,CAP_SETPCAP ),
This fails on some old distros (Debian stable [1], CentOS 6 [2]), but also on new (Fedora latest [3]):
undeclared identifier 'CAP_SETPCAP'
Could you please setup travis for your LTP fork and validate builds before posting to ML?
BTW it'd be nice to have this feature in our patchwork [4], but not sure if this is available and configurable on our patchwork instance (we don't host it).
Kind regards,
Petr
[1] https://travis-ci.org/pevik/ltp/jobs/605881703
[2] https://travis-ci.org/pevik/ltp/jobs/605881705
[3] https://travis-ci.org/pevik/ltp/jobs/605881704
[4] https://github.com/linux-test-project/ltp/issues/599
PATCH v2 1/1 syscalls/prctl02: add more error tests
Quoted 12 lines · Petr Vorel
Hi Xu,
testcases/kernel/syscalls/prctl/prctl02.c static void verify_prctl(unsigned int n) · line 138
Quoted 7 lines
Signed-off-by Yang Xu <[email protected]>static struct
tst_testtest = {
.tcnt =ARRAY_SIZE(tcases),
.test =verify_prctl,testcases/kernel/syscalls/prctl/prctl02.c +3
-0+ .caps = (struct tst_cap []) { +TST_CAP (TST_CAP_DROP ,CAP_SYS_ADMIN ), +TST_CAP (TST_CAP_DROP ,CAP_SETPCAP ),This fails on some old distros (Debian stable [1], CentOS 6 [2]), but also on new (Fedora latest [3]):
Quoted 4 lines
undeclared identifier '
CAP_SETPCAP'Could you please setup travis for your LTP fork and validate builds before posting to ML?
Hi Petr
Ok. I use travis before sending quotactl patches, but I forgot to use it for prctl02.
Sorry. I will test my patches in my ltp forklater.
ps: I add missing linux/capability.h to fix this build error and this is building in my ltp fork.
Thanks
Yang Xu
Quoted 4 lines
BTW it'd be nice to have this feature in our patchwork [4], but not sure if this is available and configurable on our patchwork instance (we don't host it).
Quoted 9 lines
Kind regards,
Petr[1] https://travis-ci.org/pevik/ltp/jobs/605881703
[2] https://travis-ci.org/pevik/ltp/jobs/605881705
[3] https://travis-ci.org/pevik/ltp/jobs/605881704
[4] https://github.com/linux-test-project/ltp/issues/599
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191101/838008eb/attachment.htm>
PATCH v3 1/1 syscalls/prctl02: add more error tests
In reply to Petr Vorel------v2->v3:
1.add missing <linux/capability.h>
------
--- include/lapi/prctl.h | 10 +++ m4/ltp-prctl.m4 | 3 +- testcases/kernel/syscalls/prctl/prctl02.c | 105 ++++++++++++++++++++-- 3 files changed, 111 insertions(+), 7 deletions(-)
include/lapi/prctl.h +10 -0
@@ -29,6 +29,11 @@# define PR_GET_NO_NEW_PRIVS 39#endif +#ifndef PR_SET_THP_DISABLE +# define PR_SET_THP_DISABLE 41 +# define PR_GET_THP_DISABLE 42 +#endif +#ifndef PR_CAP_AMBIENT # define PR_CAP_AMBIENT 47# define PR_CAP_AMBIENT_IS_SET 1
@@ -37,4 +42,9 @@# define PR_CAP_AMBIENT_CLEAR_ALL 4#endif +#ifndef PR_GET_SPECULATION_CTRL +# define PR_GET_SPECULATION_CTRL 52 +# define PR_SET_SPECULATION_CTRL 53 +#endif +#endif /* LAPI_PRCTL_H__ */
m4/ltp-prctl.m4 +2 -1
@@ -4,7 +4,8 @@ dnl Author: Ngie Cooper <[email protected]> AC_DEFUN([LTP_CHECK_PRCTL_SUPPORT],[ AC_CHECK_HEADERS(sys/prctl.h,[ - AC_CHECK_DECLS([PR_CAPBSET_DROP, PR_CAPBSET_READ], [],[],[ + AC_CHECK_DECLS([PR_CAPBSET_DROP, PR_CAPBSET_READ, PR_CAP_AMBIENT, +PR_SET_NO_NEW_PRIVS, PR_GET_SPECULATION_CTRL, PR_SET_THP_DISABLE], [],[],[ #include <sys/prctl.h> ]) dnl AC_CHECK_DECLS ])]
testcases/kernel/syscalls/prctl/prctl02.c +99 -6
142 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v3 1/1 syscalls/prctl02: add more error tests
Hi!
Quoted 26 lines
#include <
errno.h>
#include <signal.h>
#include <sys/prctl.h>testcases/kernel/syscalls/prctl/prctl02.c +17
-1- +#include <linux/filter.h> +#include <linux/capability.h> +#include <unistd.h> +#include <stdlib.h> +#include <stddef.h> +#include "config.h" +#include "lapi/prctl.h" +#include "lapi/seccomp.h" +#include "lapi/syscalls.h" #include "tst_test.h" +#include "tst_capability.h" #define OPTION_INVALID 999#define INVALID_ARG 999 +static const struct sock_filter strict_filter[] = { +BPF_STMT (BPF_LD |BPF_W |BPF_ABS , (offsetof (struct seccomp_data , nr))), + +BPF_JUMP (BPF_JMP |BPF_JEQ , __NR_close,5 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ , __NR_exit,4 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ , __NR_wait4,3 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ , __NR_write,2 ,0 ),
testcases/kernel/syscalls/prctl/prctl02.c line 70
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl02.c +10
-0+BPF_JUMP (BPF_JMP |BPF_JEQ , __NR_clone,1 ,0 ), + +BPF_STMT (BPF_RET |BPF_K ,SECCOMP_RET_KILL ), + BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW) +}; + +static const struct sock_fprog strict = { + .len = (unsigned short )ARRAY_SIZE (strict_filter), + .filter = (struct sock_filter *)strict_filter +};
We do have the exact same bytecode in the prctl04.c, can we put it to a header and include it in both tests?
Or alternatively do we need more than just one-liner with BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW) here?
Quoted 38 lines
static struct tcase {
testcases/kernel/syscalls/prctl/prctl02.c +26
-2int option;unsigned long arg2; +unsigned long arg3;int exp_errno; +int bad_addr; } tcases[] = { - {OPTION_INVALID, 0, EINVAL}, - {PR_SET_PDEATHSIG, INVALID_ARG, EINVAL}, + {OPTION_INVALID, 0, 0, EINVAL, 0}, + {PR_SET_PDEATHSIG, INVALID_ARG, 0, EINVAL, 0}, + {PR_SET_DUMPABLE, 2, 0, EINVAL, 0}, + {PR_SET_NAME, 0, 0, EFAULT, 1}, + {PR_SET_SECCOMP, 2, 0, EFAULT, 1}, + {PR_SET_SECCOMP, 2, 2, EACCES, 0}, + {PR_SET_TIMING, 1, 0, EINVAL, 0}, +#ifdef HAVE_DECL_PR_SET_NO_NEW_PRIVS + {PR_SET_NO_NEW_PRIVS, 0, 0, EINVAL, 0}, + {PR_SET_NO_NEW_PRIVS, 1, 1, EINVAL, 0}, + {PR_GET_NO_NEW_PRIVS, 1, 0, EINVAL, 0}, +#endif +#ifdef HAVE_DECL_PR_SET_THP_DISABLE + {PR_SET_THP_DISABLE, 0, 1, EINVAL, 0}, + {PR_GET_THP_DISABLE, 1, 0, EINVAL, 0}, +#endif +#ifdef HAVE_DECL_PR_CAP_AMBIENT + {PR_CAP_AMBIENT, 2, 1, EINVAL, 0}, +#endif +#ifdef HAVE_DECL_PR_GET_SPECULATION_CTR + {PR_GET_SPECULATION_CTRL, 1, 0, EINVAL, 0}, +#endif + {PR_SET_SECUREBITS, 0, 0, EPERM, 0}, + {PR_CAPBSET_DROP, 1, 0, EPERM, 0}, }; static void verify_prctl(unsigned int n) { struct tcase *tc = &tcases[n];
testcases/kernel/syscalls/prctl/prctl02.c line 116
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl02.c +8
-1-TEST (prctl (tc->option, tc->arg2)); +if (tc->arg3 ==2 ) + tc->arg3 = (unsigned long )&strict; +if (tc->bad_addr) { +if (tc->arg2) + tc->arg3 = (unsigned long )tst_get_bad_addr (NULL ); +else + tc->arg2 = (unsigned long )tst_get_bad_addr (NULL ); + }
I do not like this hackery, can't we just change the test to use pointers to pointers and initialize global variables in the test setup as we usually do?
Quoted 34 lines
testcases/kernel/syscalls/prctl/prctl02.c +10
-1+TEST (prctl (tc->option, tc->arg2, tc->arg3));if (TST_RET ==0 ) {tst_res (TFAIL ,"prctl() succeeded unexpectedly" );return ;@@ -38,7 +123,10 @@ static void verify_prctl(unsigned int n)if (tc->exp_errno ==TST_ERR ) {tst_res (TPASS |TTERRNO ,"prctl() failed as expected" ); }else { -tst_res (TFAIL |TTERRNO ,"prctl() failed unexpectedly, expected %s" , +if (tc->option ==PR_SET_SECCOMP &&TST_ERR ==EINVAL ) +tst_res (TCONF ,"current system was not built with CONFIG_SECCOMP." ); +else +tst_res (TFAIL |TTERRNO ,"prctl() failed unexpectedly, expected %s" ,tst_strerrno (tc->exp_errno)); } }@@ -46,4 +134,9 @@ static void verify_prctl(unsigned int n)static struct tst_test test = { .tcnt =ARRAY_SIZE (tcases), .test = verify_prctl, + .caps = (struct tst_cap []) { +TST_CAP (TST_CAP_DROP ,CAP_SYS_ADMIN ), +TST_CAP (TST_CAP_DROP ,CAP_SETPCAP ), + {} + }, };Signature · 7 lines
2.18.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/1 syscalls/prctl02: add more error tests
Quoted 40 lines · Cyril Hrubis
Hi!
Quoted 26 lines
#include <errno.h> #include <signal.h> #include <sys/prctl.h>testcases/kernel/syscalls/prctl/prctl02.c +17
-1- +#include <linux/filter.h> +#include <linux/capability.h> +#include <unistd.h> +#include <stdlib.h> +#include <stddef.h> +#include "config.h" +#include "lapi/prctl.h" +#include "lapi/seccomp.h" +#include "lapi/syscalls.h" #include "tst_test.h" +#include "tst_capability.h" #define OPTION_INVALID 999#define INVALID_ARG 999 +static const struct sock_filter strict_filter[] = { +BPF_STMT (BPF_LD |BPF_W |BPF_ABS , (offsetof (struct seccomp_data , nr))), + +BPF_JUMP (BPF_JMP |BPF_JEQ , __NR_close,5 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ , __NR_exit,4 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ , __NR_wait4,3 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ , __NR_write,2 ,0 ),testcases/kernel/syscalls/prctl/prctl02.c line 70
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl02.c +10
-0+BPF_JUMP (BPF_JMP |BPF_JEQ , __NR_clone,1 ,0 ), + +BPF_STMT (BPF_RET |BPF_K ,SECCOMP_RET_KILL ), + BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW) +}; + +static const struct sock_fprog strict = { + .len = (unsigned short )ARRAY_SIZE (strict_filter), + .filter = (struct sock_filter *)strict_filter +};We do have the exact same bytecode in the
prctl04.c, can we put it to a header and include it in both tests?
Quoted 2 lines
Or alternatively do we need more than just one-liner with
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW)here?
we only need one-liner with BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW) here.
Quoted 40 lines
Quoted 40 lines
static struct tcase { int option; unsigned long arg2;testcases/kernel/syscalls/prctl/prctl02.c +26
-2+unsigned long arg3;int exp_errno; +int bad_addr; } tcases[] = { - {OPTION_INVALID, 0, EINVAL}, - {PR_SET_PDEATHSIG, INVALID_ARG, EINVAL}, + {OPTION_INVALID, 0, 0, EINVAL, 0}, + {PR_SET_PDEATHSIG, INVALID_ARG, 0, EINVAL, 0}, + {PR_SET_DUMPABLE, 2, 0, EINVAL, 0}, + {PR_SET_NAME, 0, 0, EFAULT, 1}, + {PR_SET_SECCOMP, 2, 0, EFAULT, 1}, + {PR_SET_SECCOMP, 2, 2, EACCES, 0}, + {PR_SET_TIMING, 1, 0, EINVAL, 0}, +#ifdef HAVE_DECL_PR_SET_NO_NEW_PRIVS + {PR_SET_NO_NEW_PRIVS, 0, 0, EINVAL, 0}, + {PR_SET_NO_NEW_PRIVS, 1, 1, EINVAL, 0}, + {PR_GET_NO_NEW_PRIVS, 1, 0, EINVAL, 0}, +#endif +#ifdef HAVE_DECL_PR_SET_THP_DISABLE + {PR_SET_THP_DISABLE, 0, 1, EINVAL, 0}, + {PR_GET_THP_DISABLE, 1, 0, EINVAL, 0}, +#endif +#ifdef HAVE_DECL_PR_CAP_AMBIENT + {PR_CAP_AMBIENT, 2, 1, EINVAL, 0}, +#endif +#ifdef HAVE_DECL_PR_GET_SPECULATION_CTR + {PR_GET_SPECULATION_CTRL, 1, 0, EINVAL, 0}, +#endif + {PR_SET_SECUREBITS, 0, 0, EPERM, 0}, + {PR_CAPBSET_DROP, 1, 0, EPERM, 0}, }; static void verify_prctl(unsigned int n) { struct tcase *tc = &tcases[n];
Quoted 12 lines
testcases/kernel/syscalls/prctl/prctl02.c line 116
Quoted 9 lines
testcases/kernel/syscalls/prctl/prctl02.c +8
-1-TEST (prctl (tc->option, tc->arg2)); +if (tc->arg3 ==2 ) + tc->arg3 = (unsigned long )&strict; +if (tc->bad_addr) { +if (tc->arg2) + tc->arg3 = (unsigned long )tst_get_bad_addr (NULL ); +else + tc->arg2 = (unsigned long )tst_get_bad_addr (NULL ); + }I do not like this hackery, can't we just change the test to use pointers to pointers and initialize global variables in the test setup as we usually do?
Ok. I will do it as we usually do.
Quoted 33 lines
Quoted 33 lines
testcases/kernel/syscalls/prctl/prctl02.c +10
-1+TEST (prctl (tc->option, tc->arg2, tc->arg3));if (TST_RET ==0 ) {tst_res (TFAIL ,"prctl() succeeded unexpectedly" );return ;@@ -38,7 +123,10 @@ static void verify_prctl(unsigned int n)if (tc->exp_errno ==TST_ERR ) {tst_res (TPASS |TTERRNO ,"prctl() failed as expected" ); }else { -tst_res (TFAIL |TTERRNO ,"prctl() failed unexpectedly, expected %s" , +if (tc->option ==PR_SET_SECCOMP &&TST_ERR ==EINVAL ) +tst_res (TCONF ,"current system was not built with CONFIG_SECCOMP." ); +else +tst_res (TFAIL |TTERRNO ,"prctl() failed unexpectedly, expected %s" ,tst_strerrno (tc->exp_errno)); } }@@ -46,4 +134,9 @@ static void verify_prctl(unsigned int n)static struct tst_test test = { .tcnt =ARRAY_SIZE (tcases), .test = verify_prctl, + .caps = (struct tst_cap []) { +TST_CAP (TST_CAP_DROP ,CAP_SYS_ADMIN ), +TST_CAP (TST_CAP_DROP ,CAP_SETPCAP ), + {} + }, };Signature · 1 line
2.18.0
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191108/19aa2243/attachment.htm>
PATCH v3 1/1 syscalls/prctl02: add more error tests
Quoted 96 lines · Yang Xu
Quoted 40 lines · Cyril Hrubis
Hi!
Quoted 26 lines
#include <errno.h> #include <signal.h> #include <sys/prctl.h>testcases/kernel/syscalls/prctl/prctl02.c +17
-1- +#include <linux/filter.h> +#include <linux/capability.h> +#include <unistd.h> +#include <stdlib.h> +#include <stddef.h> +#include "config.h" +#include "lapi/prctl.h" +#include "lapi/seccomp.h" +#include "lapi/syscalls.h" #include "tst_test.h" +#include "tst_capability.h" #define OPTION_INVALID 999#define INVALID_ARG 999 +static const struct sock_filter strict_filter[] = { +BPF_STMT (BPF_LD |BPF_W |BPF_ABS , (offsetof (struct seccomp_data , nr))), + +BPF_JUMP (BPF_JMP |BPF_JEQ , __NR_close,5 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ , __NR_exit,4 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ , __NR_wait4,3 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ , __NR_write,2 ,0 ),testcases/kernel/syscalls/prctl/prctl02.c line 70
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl02.c +10
-0+BPF_JUMP (BPF_JMP |BPF_JEQ , __NR_clone,1 ,0 ), + +BPF_STMT (BPF_RET |BPF_K ,SECCOMP_RET_KILL ), + BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW) +}; + +static const struct sock_fprog strict = { + .len = (unsigned short )ARRAY_SIZE (strict_filter), + .filter = (struct sock_filter *)strict_filter +};We do have the exact same bytecode in the
prctl04.c, can we put it to a header and include it in both tests?Quoted 2 lines
Or alternatively do we need more than just one-liner with
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW)here?we only need one-liner with
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW)here.Quoted 39 lines
Quoted 39 lines
static struct tcase { int option; unsigned long arg2;testcases/kernel/syscalls/prctl/prctl02.c +26
-2+unsigned long arg3;int exp_errno; +int bad_addr; } tcases[] = { - {OPTION_INVALID, 0, EINVAL}, - {PR_SET_PDEATHSIG, INVALID_ARG, EINVAL}, + {OPTION_INVALID, 0, 0, EINVAL, 0}, + {PR_SET_PDEATHSIG, INVALID_ARG, 0, EINVAL, 0}, + {PR_SET_DUMPABLE, 2, 0, EINVAL, 0}, + {PR_SET_NAME, 0, 0, EFAULT, 1}, + {PR_SET_SECCOMP, 2, 0, EFAULT, 1}, + {PR_SET_SECCOMP, 2, 2, EACCES, 0}, + {PR_SET_TIMING, 1, 0, EINVAL, 0}, +#ifdef HAVE_DECL_PR_SET_NO_NEW_PRIVS + {PR_SET_NO_NEW_PRIVS, 0, 0, EINVAL, 0}, + {PR_SET_NO_NEW_PRIVS, 1, 1, EINVAL, 0}, + {PR_GET_NO_NEW_PRIVS, 1, 0, EINVAL, 0}, +#endif +#ifdef HAVE_DECL_PR_SET_THP_DISABLE + {PR_SET_THP_DISABLE, 0, 1, EINVAL, 0}, + {PR_GET_THP_DISABLE, 1, 0, EINVAL, 0}, +#endif +#ifdef HAVE_DECL_PR_CAP_AMBIENT + {PR_CAP_AMBIENT, 2, 1, EINVAL, 0}, +#endif +#ifdef HAVE_DECL_PR_GET_SPECULATION_CTR + {PR_GET_SPECULATION_CTRL, 1, 0, EINVAL, 0}, +#endif + {PR_SET_SECUREBITS, 0, 0, EPERM, 0}, + {PR_CAPBSET_DROP, 1, 0, EPERM, 0}, }; static void verify_prctl(unsigned int n) { struct tcase *tc = &tcases[n];Quoted 12 lines
testcases/kernel/syscalls/prctl/prctl02.c line 116
Quoted 9 lines
testcases/kernel/syscalls/prctl/prctl02.c +8
-1-TEST (prctl (tc->option, tc->arg2)); +if (tc->arg3 ==2 ) + tc->arg3 = (unsigned long )&strict; +if (tc->bad_addr) { +if (tc->arg2) + tc->arg3 = (unsigned long )tst_get_bad_addr (NULL ); +else + tc->arg2 = (unsigned long )tst_get_bad_addr (NULL ); + }I do not like this hackery, can't we just change the test to use pointers to pointers and initialize global variables in the test setup as we usually do?
Quoted 1 line
Ok. I will do it as we usually do.
?I think about it again. The argument of prctl is all unsigned long type. Do we need to use
pointers to pointers? Or, move this code to setup function like above?
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
testcases/kernel/syscalls/prctl/prctl02.c +10
-1+TEST (prctl (tc->option, tc->arg2, tc->arg3));if (TST_RET ==0 ) {tst_res (TFAIL ,"prctl() succeeded unexpectedly" );return ;@@ -38,7 +123,10 @@ static void verify_prctl(unsigned int n)if (tc->exp_errno ==TST_ERR ) {tst_res (TPASS |TTERRNO ,"prctl() failed as expected" ); }else { -tst_res (TFAIL |TTERRNO ,"prctl() failed unexpectedly, expected %s" , +if (tc->option ==PR_SET_SECCOMP &&TST_ERR ==EINVAL ) +tst_res (TCONF ,"current system was not built with CONFIG_SECCOMP." ); +else +tst_res (TFAIL |TTERRNO ,"prctl() failed unexpectedly, expected %s" ,tst_strerrno (tc->exp_errno)); } }@@ -46,4 +134,9 @@ static void verify_prctl(unsigned int n)static struct tst_test test = { .tcnt =ARRAY_SIZE (tcases), .test = verify_prctl, + .caps = (struct tst_cap []) { +TST_CAP (TST_CAP_DROP ,CAP_SYS_ADMIN ), +TST_CAP (TST_CAP_DROP ,CAP_SETPCAP ), + {} + }, };Signature · 1 line
2.18.0
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
Mailing list info:https://lists.linux.it/listinfo/ltp
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191108/5a18bc04/attachment-0001.htm>
PATCH v3 1/1 syscalls/prctl02: add more error tests
Hi!
Quoted 4 lines
Quoted 1 line
Ok. I will do it as we usually do.
??I think about it again. The argument of prctl is all unsigned long type. Do we need to use
pointers to pointers??? Or, move this code to setup function like above?
Just pointer to unsigned long and do the cast in the test setup as:
static unsigned long bad_addr;
static struct tcase = {
...
unsigned long *arg3;
...
} tcases[] = {
...
{..., &bad_addr, ...},
...
}static void setup(void)
{
invalid_addr = (unigned long)tst_get_bad_addr();
}Then call it as prctl(..., *tc->arg3).
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 1/1 syscalls/prctl02: add more error tests
--- include/lapi/prctl.h | 10 ++ m4/ltp-prctl.m4 | 3 +- testcases/kernel/syscalls/prctl/prctl02.c | 106 ++++++++++++++++++++-- 3 files changed, 109 insertions(+), 10 deletions(-)
include/lapi/prctl.h +10 -0
@@ -34,6 +34,11 @@# define PR_GET_NO_NEW_PRIVS 39#endif +#ifndef PR_SET_THP_DISABLE +# define PR_SET_THP_DISABLE 41 +# define PR_GET_THP_DISABLE 42 +#endif +#ifndef PR_CAP_AMBIENT # define PR_CAP_AMBIENT 47# define PR_CAP_AMBIENT_IS_SET 1
@@ -42,4 +47,9 @@# define PR_CAP_AMBIENT_CLEAR_ALL 4#endif +#ifndef PR_GET_SPECULATION_CTRL +# define PR_GET_SPECULATION_CTRL 52 +# define PR_SET_SPECULATION_CTRL 53 +#endif +#endif /* LAPI_PRCTL_H__ */
m4/ltp-prctl.m4 +2 -1
@@ -4,7 +4,8 @@ dnl Author: Ngie Cooper <[email protected]> AC_DEFUN([LTP_CHECK_PRCTL_SUPPORT],[ AC_CHECK_HEADERS(sys/prctl.h,[ - AC_CHECK_DECLS([PR_CAPBSET_DROP, PR_CAPBSET_READ], [],[],[ + AC_CHECK_DECLS([PR_CAPBSET_DROP, PR_CAPBSET_READ, PR_CAP_AMBIENT, +PR_SET_NO_NEW_PRIVS, PR_GET_SPECULATION_CTRL, PR_SET_THP_DISABLE], [],[],[ #include <sys/prctl.h> ]) dnl AC_CHECK_DECLS ])]
testcases/kernel/syscalls/prctl/prctl02.c +97 -9
143 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v4 1/1 syscalls/prctl02: add more error tests
Hi!
testcases/kernel/syscalls/prctl/prctl02.c line 62
Quoted 6 lines
testcases/kernel/syscalls/prctl/prctl02.c +6
-0+static const struct sock_fprog strict = { + .len = (unsigned short )ARRAY_SIZE (strict_filter), + .filter = (struct sock_filter *)strict_filter +}; + +static const struct sock_fprog *strict_addr = &strict;
This should be:
static unsigned long strict_addr = (unsigned long)&strict;
Quoted 27 lines
testcases/kernel/syscalls/prctl/prctl02.c +19
-3+static unsigned long bad_addr; +static unsigned long num_0; +static unsigned long num_1 =1 ; +static unsigned long num_2 =2 ; +static unsigned long num_invalid =999 ;static struct tcase {int option; -unsigned long arg2; +unsigned long *arg2; +unsigned long *arg3;int exp_errno; } tcases[] = { - {OPTION_INVALID ,0 ,EINVAL }, - {PR_SET_PDEATHSIG ,INVALID_ARG ,EINVAL }, + {OPTION_INVALID , &num_1, &num_0,EINVAL }, + {PR_SET_PDEATHSIG , &num_invalid, &num_0,EINVAL }, + {PR_SET_DUMPABLE , &num_2, &num_0,EINVAL }, + {PR_SET_NAME , &bad_addr, &num_0,EFAULT }, + {PR_SET_SECCOMP , &num_2, &bad_addr,EFAULT }, + {PR_SET_SECCOMP , &num_2, &strict_addr,EACCES }, + {PR_SET_TIMING , &num_1, &num_0,EINVAL }, +#ifdef HAVE_DECL_PR_SET_NO_NEW_PRIVS + {PR_SET_NO_NEW_PRIVS , &num_0, &num_0,EINVAL }, + {PR_SET_NO_NEW_PRIVS , &num_1, &num_0,EINVAL }, + {PR_GET_NO_NEW_PRIVS , &num_1, &num_0,EINVAL }, +#endif
testcases/kernel/syscalls/prctl/prctl02.c line 97
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl02.c +10
-0+#ifdef HAVE_DECL_PR_SET_THP_DISABLE + {PR_SET_THP_DISABLE, &num_0, &num_1, EINVAL}, + {PR_GET_THP_DISABLE, &num_1, &num_1, EINVAL}, +#endif +#ifdef HAVE_DECL_PR_CAP_AMBIENT + {PR_CAP_AMBIENT, &num_2, &num_1, EINVAL}, +#endif +#ifdef HAVE_DECL_PR_GET_SPECULATION_CTRL + {PR_GET_SPECULATION_CTRL, &num_1, &num_0, EINVAL}, +#endif
Why the ifdefs, you have even added a fallback definitions into the lapi header?
The usuall way how to deal with these is to:
1) Add fallback definitions to lapi
2) Ensure these tests does not fail on older kernels
We do expect EINVAL in these cases anyways, which is what we would get if the prctl() option is unknown to the kernel anyways, so here we can just get rid of these ifdefs and things should work fine.
Quoted 48 lines
testcases/kernel/syscalls/prctl/prctl02.c +19
-3+ {PR_SET_SECUREBITS, &num_0, &num_0, EPERM}, + {PR_CAPBSET_DROP, &num_1, &num_0, EPERM}, };static void verify_prctl (unsigned int n) {struct tcase *tc = &tcases[n]; -TEST (prctl (tc->option, tc->arg2)); +TEST (prctl (tc->option, *tc->arg2, *tc->arg3));if (TST_RET ==0 ) {tst_res (TFAIL ,"prctl() succeeded unexpectedly" );return ; }if (tc->exp_errno ==TST_ERR ) { -tst_res (TPASS |TTERRNO ,"prctl() failed as expected" ); +tst_res (TPASS |TTERRNO ,"prctl() %d failed as expected" , tc->option); }else { -tst_res (TFAIL |TTERRNO ,"prctl() failed unexpectedly, expected %s" , +if (tc->option ==PR_SET_SECCOMP &&TST_ERR ==EINVAL ) +tst_res (TCONF ,"current system was not built with CONFIG_SECCOMP." ); +else +tst_res (TFAIL |TTERRNO ,"prctl() failed unexpectedly, expected %s" ,tst_strerrno (tc->exp_errno)); } } +static void setup (void ) +{ + bad_addr = (unsigned long )tst_get_bad_addr (NULL ); +} +static struct tst_test test = { + .setup = setup, .tcnt =ARRAY_SIZE (tcases), .test = verify_prctl, + .caps = (struct tst_cap []) { +TST_CAP (TST_CAP_DROP ,CAP_SYS_ADMIN ), +TST_CAP (TST_CAP_DROP ,CAP_SETPCAP ), + {} + }, };Signature · 1 line
2.18.0
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 1/1 syscalls/prctl02: add more error tests
Quoted 10 lines · Cyril Hrubis
Hi!
testcases/kernel/syscalls/prctl/prctl02.c line 62
Quoted 6 lines
testcases/kernel/syscalls/prctl/prctl02.c +6
-0+static const struct sock_fprog strict = { + .len = (unsigned short )ARRAY_SIZE (strict_filter), + .filter = (struct sock_filter *)strict_filter +}; + +static const struct sock_fprog *strict_addr = &strict;This should be:
static unsigned long
strict_addr= (unsigned long)&strict;
OK.
Quoted 41 lines
Quoted 28 lines
testcases/kernel/syscalls/prctl/prctl02.c +19
-3+static unsigned long bad_addr; +static unsigned long num_0; +static unsigned long num_1 =1 ; +static unsigned long num_2 =2 ; +static unsigned long num_invalid =999 ;static struct tcase {int option; -unsigned long arg2; +unsigned long *arg2; +unsigned long *arg3;int exp_errno; } tcases[] = { - {OPTION_INVALID ,0 ,EINVAL }, - {PR_SET_PDEATHSIG ,INVALID_ARG ,EINVAL }, + {OPTION_INVALID , &num_1, &num_0,EINVAL }, + {PR_SET_PDEATHSIG , &num_invalid, &num_0,EINVAL }, + {PR_SET_DUMPABLE , &num_2, &num_0,EINVAL }, + {PR_SET_NAME , &bad_addr, &num_0,EFAULT }, + {PR_SET_SECCOMP , &num_2, &bad_addr,EFAULT }, + {PR_SET_SECCOMP , &num_2, &strict_addr,EACCES }, + {PR_SET_TIMING , &num_1, &num_0,EINVAL }, +#ifdef HAVE_DECL_PR_SET_NO_NEW_PRIVS + {PR_SET_NO_NEW_PRIVS , &num_0, &num_0,EINVAL }, + {PR_SET_NO_NEW_PRIVS , &num_1, &num_0,EINVAL }, + {PR_GET_NO_NEW_PRIVS , &num_1, &num_0,EINVAL }, +#endiftestcases/kernel/syscalls/prctl/prctl02.c line 97
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl02.c +10
-0+#ifdef HAVE_DECL_PR_SET_THP_DISABLE + {PR_SET_THP_DISABLE, &num_0, &num_1, EINVAL}, + {PR_GET_THP_DISABLE, &num_1, &num_1, EINVAL}, +#endif +#ifdef HAVE_DECL_PR_CAP_AMBIENT + {PR_CAP_AMBIENT, &num_2, &num_1, EINVAL}, +#endif +#ifdef HAVE_DECL_PR_GET_SPECULATION_CTRL + {PR_GET_SPECULATION_CTRL, &num_1, &num_0, EINVAL}, +#endifWhy the ifdefs, you have even added a fallback definitions into the lapi header?
Quoted 8 lines
The usuall way how to deal with these is to:
1) Add fallback definitions to lapi
2) Ensure these tests does not fail on older kernelsWe do expect EINVAL in these cases anyways, which is what we would get if the
prctl()option is unknown to the kernel anyways, so here we can just get rid of these ifdefs and things should work fine.
For me, a fallback definitions into the lapi header is only for fixing undefined error on old kernel.
IMO, we only test options that kernel supports.
If we test an unsupported option, our case reports EINVAL that will give user a false impression(kernel supports it, but argument or environment is bad). I think we should check they whether supported before run (ifdef is a way).
ps: If we test EPERM error(cap is not in PI or PP) of PR_CAP_AMBIENT on old kernel, they will report EINVAL. So, I think ifdef is needed.
Quoted 41 lines
Quoted 41 lines
testcases/kernel/syscalls/prctl/prctl02.c +17
-3+ {PR_SET_SECUREBITS, &num_0, &num_0, EPERM}, + {PR_CAPBSET_DROP, &num_1, &num_0, EPERM}, }; static void verify_prctl(unsigned int n) { struct tcase *tc = &tcases[n]; -TEST (prctl (tc->option, tc->arg2)); + TEST(prctl(tc->option, *tc->arg2, *tc->arg3)); if (TST_RET == 0) { tst_res(TFAIL, "prctl() succeeded unexpectedly"); return; } if (tc->exp_errno == TST_ERR) { -tst_res (TPASS |TTERRNO ,"prctl() failed as expected" ); + tst_res(TPASS | TTERRNO, "prctl() %d failed as expected", tc->option); } else { -tst_res (TFAIL |TTERRNO ,"prctl() failed unexpectedly, expected %s" , + if (tc->option == PR_SET_SECCOMP && TST_ERR == EINVAL) + tst_res(TCONF, "current system was not built with CONFIG_SECCOMP."); + else + tst_res(TFAIL | TTERRNO, "prctl() failed unexpectedly, expected %s", tst_strerrno(tc->exp_errno)); } } +static void setup(void) +{ + bad_addr = (unsigned long)tst_get_bad_addr(NULL); +} + static struct tst_test test = { + .setup = setup, .tcnt = ARRAY_SIZE(tcases), .test = verify_prctl, + .caps = (struct tst_cap []) { + TST_CAP(TST_CAP_DROP, CAP_SYS_ADMIN), + TST_CAP(TST_CAP_DROP, CAP_SETPCAP),
Quoted 8 lines
Quoted 8 lines
testcases/kernel/syscalls/prctl/prctl02.c +2
-0+ {} + }, };Signature · 1 line
2.18.0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191112/7d08e222/attachment.htm>
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v4 1/1 syscalls/prctl02: add more error tests
Quoted 60 lines · Xiao Yang
Quoted 59 lines · Yang Xu
Quoted 10 lines · Cyril Hrubis
Hi!
testcases/kernel/syscalls/prctl/prctl02.c line 62
Quoted 6 lines
testcases/kernel/syscalls/prctl/prctl02.c +6
-0+static const struct sock_fprog strict = { + .len = (unsigned short )ARRAY_SIZE (strict_filter), + .filter = (struct sock_filter *)strict_filter +}; + +static const struct sock_fprog *strict_addr = &strict;This should be:
static unsigned long
strict_addr= (unsigned long)&strict;OK.
Quoted 45 lines
Quoted 27 lines
testcases/kernel/syscalls/prctl/prctl02.c +19
-3+static unsigned long bad_addr; +static unsigned long num_0; +static unsigned long num_1 =1 ; +static unsigned long num_2 =2 ; +static unsigned long num_invalid =999 ;static struct tcase {int option; -unsigned long arg2; +unsigned long *arg2; +unsigned long *arg3;int exp_errno; } tcases[] = { - {OPTION_INVALID ,0 ,EINVAL }, - {PR_SET_PDEATHSIG ,INVALID_ARG ,EINVAL }, + {OPTION_INVALID , &num_1, &num_0,EINVAL }, + {PR_SET_PDEATHSIG , &num_invalid, &num_0,EINVAL }, + {PR_SET_DUMPABLE , &num_2, &num_0,EINVAL }, + {PR_SET_NAME , &bad_addr, &num_0,EFAULT }, + {PR_SET_SECCOMP , &num_2, &bad_addr,EFAULT }, + {PR_SET_SECCOMP , &num_2, &strict_addr,EACCES }, + {PR_SET_TIMING , &num_1, &num_0,EINVAL }, +#ifdef HAVE_DECL_PR_SET_NO_NEW_PRIVS + {PR_SET_NO_NEW_PRIVS , &num_0, &num_0,EINVAL }, + {PR_SET_NO_NEW_PRIVS , &num_1, &num_0,EINVAL }, + {PR_GET_NO_NEW_PRIVS , &num_1, &num_0,EINVAL }, +#endiftestcases/kernel/syscalls/prctl/prctl02.c line 97
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl02.c +10
-0+#ifdef HAVE_DECL_PR_SET_THP_DISABLE + {PR_SET_THP_DISABLE, &num_0, &num_1, EINVAL}, + {PR_GET_THP_DISABLE, &num_1, &num_1, EINVAL}, +#endif +#ifdef HAVE_DECL_PR_CAP_AMBIENT + {PR_CAP_AMBIENT, &num_2, &num_1, EINVAL}, +#endif +#ifdef HAVE_DECL_PR_GET_SPECULATION_CTRL + {PR_GET_SPECULATION_CTRL, &num_1, &num_0, EINVAL}, +#endifWhy the ifdefs, you have even added a fallback definitions into the lapi header?
The usuall way how to deal with these is to:
1) Add fallback definitions to lapi
2) Ensure these tests does not fail on older kernels
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
We do expect EINVAL in these cases anyways, which is what we would get if the
prctl()option is unknown to the kernel anyways, so here we can just get rid of these ifdefs and things should work fine.For me, a fallback definitions into the lapi header is only for fixing undefined error on old kernel.
Hi Yang,
1) Can undefined error be triggered on old kernel if you use ifdef? It seems unnecessary for ifdef method to include lapi header.
Yes. It can be triggered and it should use #if HAVE_DECL_PR_GET_SPECULATION_CTRL instead of #ifdef.
Yes. And we should add more check( such as PR_SET_SECCOMP undefined 2.6.18-398.el5) in m4/ltp-prctl.m4 so that we cannot include lapi header.
Quoted 1 line
2) Undfined option in glibc doesn't mean that kernel doesn't support it as well.
options definitions is in linux/prctl.h. For most distributions, I think if it is in supported in kernel-header, it should also been supported on kernel.
Quoted 10 lines
Quoted 7 lines
IMO, we only test options that kernel supports.
If we test an unsupported option, our case reports EINVAL that will give user a falseimpression(kernel supports it, but argument or environment is bad). I think we should check they whether supported before run (ifdef is a way).ps: If we test EPERM error(cap is not in PI or PP) of
PR_CAP_AMBIENTon old kernel, they will report EINVAL. So, I think ifdef is needed.Why don't we check if the specified option is supported by calling it with correct args?(i.e. don't mix unsupported option up with wrong args).
It sounds reasonable. I will try it in verify_prctl function if you and cyril have strong opposition to #if.
Quoted 54 lines
Best Regards,
Xiao YangQuoted 50 lines
Quoted 48 lines
Quoted 48 lines
testcases/kernel/syscalls/prctl/prctl02.c +19
-3+ {PR_SET_SECUREBITS, &num_0, &num_0, EPERM}, + {PR_CAPBSET_DROP, &num_1, &num_0, EPERM}, };static void verify_prctl (unsigned int n) {struct tcase *tc = &tcases[n]; -TEST (prctl (tc->option, tc->arg2)); +TEST (prctl (tc->option, *tc->arg2, *tc->arg3));if (TST_RET ==0 ) {tst_res (TFAIL ,"prctl() succeeded unexpectedly" );return ; }if (tc->exp_errno ==TST_ERR ) { -tst_res (TPASS |TTERRNO ,"prctl() failed as expected" ); +tst_res (TPASS |TTERRNO ,"prctl() %d failed as expected" , tc->option); }else { -tst_res (TFAIL |TTERRNO ,"prctl() failed unexpectedly, expected %s" , +if (tc->option ==PR_SET_SECCOMP &&TST_ERR ==EINVAL ) +tst_res (TCONF ,"current system was not built with CONFIG_SECCOMP." ); +else +tst_res (TFAIL |TTERRNO ,"prctl() failed unexpectedly, expected %s" ,tst_strerrno (tc->exp_errno)); } } +static void setup (void ) +{ + bad_addr = (unsigned long )tst_get_bad_addr (NULL ); +} +static struct tst_test test = { + .setup = setup, .tcnt =ARRAY_SIZE (tcases), .test = verify_prctl, + .caps = (struct tst_cap []) { +TST_CAP (TST_CAP_DROP ,CAP_SYS_ADMIN ), +TST_CAP (TST_CAP_DROP ,CAP_SETPCAP ), + {} + }, };Signature · 1 line
2.18.0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191112/40f74356/attachment-0001.htm>
PATCH v4 1/1 syscalls/prctl02: add more error tests
Hi!
Quoted 9 lines
Quoted 1 line
1) Can undefined error be triggered on old kernel if you use ifdef? It seems unnecessary for ifdef method to include lapi header.
Yes. It can be triggered and it should use #if
HAVE_DECL_PR_GET_SPECULATION_CTRLinstead of #ifdef.
Yes. And we should add morecheck( such as PR_SET_SECCOMP undefined 2.6.18-398.el5)in m4/ltp-prctl.m4 so that we cannot include lapi header.Quoted 1 line
2) Undfined option in glibc doesn't mean that kernel doesn't support it as well.
options definitions is in
linux/prctl.h. For most distributions, I think if it is in supported in kernel-header, it should also been supported on kernel.
That is usually the case, but there are cons that I explained in the previous email.
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines
IMO, we only test options that kernel supports.
If we test an unsupported option, our case reports EINVAL that will give user a falseimpression(kernel supports it, but argument or environment is bad). I think we should check they whether supported before run (ifdef is a way).ps: If we test EPERM error(cap is not in PI or PP) of
PR_CAP_AMBIENTon old kernel, they will report EINVAL. So, I think ifdef is needed.Why don't we check if the specified option is supported by calling it with correct args?(i.e. don't mix unsupported option up with wrong args).
It sounds reasonable. I will try it in
verify_prctlfunction if you and cyril have strong opposition to #if.
Okay, that will work. Calling it with correct parameters in test setup is 100% correct way how to find out if kernel implements the functionality.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 1/1 syscalls/prctl02: add more error tests
Quoted 10 lines · Cyril Hrubis
Hi!
Quoted 7 lines
Quoted 1 line
1) Can undefined error be triggered on old kernel if you use ifdef? It seems unnecessary for ifdef method to include lapi header.
Yes. It can be triggered and it should use #if
HAVE_DECL_PR_GET_SPECULATION_CTRLinstead of #ifdef.
Yes. And we should add morecheck( such as PR_SET_SECCOMP undefined 2.6.18-398.el5)in m4/ltp-prctl.m4 so that we cannot include lapi header.Quoted 1 line
2) Undfined option in glibc doesn't mean that kernel doesn't support it as well.
options definitions is in
linux/prctl.h. For most distributions, I think if it is in supported in kernel-header, it should also been supported on kernel.That is usually the case, but there are cons that I explained in the previous email.
OK.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
IMO, we only test options that kernel supports.
If we test an unsupported option, our case reports EINVAL that will give user a falseimpression(kernel supports it, but argument or environment is bad). I think we should check they whether supported before run (ifdef is a way).ps: If we test EPERM error(cap is not in PI or PP) of
PR_CAP_AMBIENTon old kernel, they will report EINVAL. So, I think ifdef is needed.
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Why don't we check if the specified option is supported by calling it with correct args?(i.e. don't mix unsupported option up with wrong args).
It sounds reasonable. I will try it in
verify_prctlfunction if you and cyril have strong opposition to #if.Okay, that will work. Calling it with correct parameters in test setup is 100% correct way how to find out if kernel implements the functionality.
OK. I will use correct parameters to check whether kernel implements the functionality in setup. Thanks for your patiently explation.
ps: I will make v5 patch tomorrow.
Quoted 1 line
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191112/c64c5257/attachment.htm>
PATCH v5 1/1 syscalls/prctl02: add more error tests
In reply to Cyril HrubisI check these new options(PR_GET_SECCOMP,PR_GET_NO_NEW_PRIVS,PR_GET_THP_DISABLE, PR_GET_SPECULATION_CTRL) whether support on current kernel. If it is non-supported, skip it. For some old options(PR_SET_PDEATHSIG,PR_SET_DUMPABLE,PR_SET_NAME,PR_SET_TIMING), I don't check them because they are supported since prctl was introduced on v2.6.12-rc2. For remaining options(PR_SET_SECUREBITS,PR_CAPBSET_DROP), they are supported since Linux 2.6.26. I think we also don't need to check them because they are too old(It was 11 years old).
--- include/lapi/prctl.h | 10 ++ testcases/kernel/syscalls/prctl/prctl02.c | 161 ++++++++++++++++++++-- 2 files changed, 163 insertions(+), 8 deletions(-)
include/lapi/prctl.h +10 -0
@@ -34,6 +34,11 @@# define PR_GET_NO_NEW_PRIVS 39#endif +#ifndef PR_SET_THP_DISABLE +# define PR_SET_THP_DISABLE 41 +# define PR_GET_THP_DISABLE 42 +#endif +#ifndef PR_CAP_AMBIENT # define PR_CAP_AMBIENT 47# define PR_CAP_AMBIENT_IS_SET 1
@@ -42,4 +47,9 @@# define PR_CAP_AMBIENT_CLEAR_ALL 4#endif +#ifndef PR_GET_SPECULATION_CTRL +# define PR_GET_SPECULATION_CTRL 52 +# define PR_SET_SPECULATION_CTRL 53 +#endif +#endif /* LAPI_PRCTL_H__ */
testcases/kernel/syscalls/prctl/prctl02.c +153 -8
197 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH v5 1/1 syscalls/prctl02: add more error tests
Hi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 1/1 syscalls/prctl02: add more error tests
In reply to Yang XuHi!
Quoted 7 lines
Quoted 6 lines
1) Add fallback definitions to lapi
2) Ensure these tests does not fail on older kernelsWe do expect EINVAL in these cases anyways, which is what we would get if the
prctl()option is unknown to the kernel anyways, so here we can just get rid of these ifdefs and things should work fine.
Quoted 6 lines
For me, a fallback definitions into the lapi header is only for fixing undefined error on old kernel.
IMO, we only test options that kernel supports.
If we test an unsupported option, our case reports EINVAL that will give user a falseimpression(kernel supports it, but argument or environment is bad). I think we should check they whether supported before run (ifdef is a way).
However using ifdefs to assert kernel features never worked at all. The kernel headers usally lag behind the installed kernel in distribution and it's even more wrong when you are testing latest kernel on any given distro.
If you want to check for kernel support the best thing is to use the tst_kvercmp() that checks the kernel version and even that does not work 100% reliably.
Quoted 2 lines
ps: If we test EPERM error(cap is not in PI or PP) of
PR_CAP_AMBIENTon old kernel, they will report EINVAL. So, I think ifdef is needed.
No, ifdefs are never solution here. It will still fail if you compiled the test on newer distro and booted it up with older kernel.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 1/1 syscalls/prctl02: add more error tests
Quoted 13 lines · Cyril Hrubis
Hi!
Quoted 6 lines
Quoted 6 lines
1) Add fallback definitions to lapi
2) Ensure these tests does not fail on older kernelsWe do expect EINVAL in these cases anyways, which is what we would get if the
prctl()option is unknown to the kernel anyways, so here we can just get rid of these ifdefs and things should work fine.Quoted 6 lines
For me, a fallback definitions into the lapi header is only for fixing undefined error on old kernel.
IMO, we only test options that kernel supports.
If we test an unsupported option, our case reports EINVAL that will give user a falseimpression(kernel supports it, but argument or environment is bad). I think we should check they whether supported before run (ifdef is a way).
Quoted 8 lines
However using ifdefs to assert kernel features never worked at all. The kernel headers usally lag behind the installed kernel in distribution and it's even more wrong when you are testing latest kernel on any given distro.
If you want to check for kernel support the best thing is to use the
tst_kvercmp()that checks the kernel version and even that does not work 100% reliably.
Yes. most distros backport upstream kernel patch and tst_kvercmp maybe useless.
Quoted 4 lines
Quoted 2 lines
ps: If we test EPERM error(cap is not in PI or PP) of
PR_CAP_AMBIENTon old kernel, they will report EINVAL. So, I think ifdef is needed.No, ifdefs are never solution here. It will still fail if you compiled the test on newer distro and booted it up with older kernel.
Now, I agree with you. If new distro and booted it with older kernel, the ifdef is useless. I think we should use correct argument as xiao said to check whether kernel supports these options.
Quoted 1 line
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191112/0bf02da8/attachment-0001.htm>