/kenel/syscalls/prctl: add prctl03
PATCH 1/1 /kenel/syscalls/prctl: add prctl03
Signed-off-by Li Wang <[email protected]>
--- runtest/syscalls | 1 + testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/prctl/prctl03.c | 160 ++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 testcases/kernel/syscalls/prctl/prctl03.c
runtest/syscalls +1 -0
@@ -752,6 +752,7 @@ ppoll01 ppoll01 prctl01 prctl01 prctl02 prctl02 +prctl03 prctl03 pread01 pread01 pread01_64 pread01_64
testcases/kernel/syscalls/.gitignore +1 -0
@@ -630,6 +630,7 @@ /ppoll/ppoll01 /prctl/prctl01 /prctl/prctl02 +/prctl/prctl03 /pread/pread01 /pread/pread01_64 /pread/pread02
testcases/kernel/syscalls/prctl/prctl03.c new file +160 -0
160 lines not on this page · raw message
Signature · 8 lines
1.9.3 ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Quoted 89 lines · Li Wang
Signed-off-by Li Wang <[email protected]>--- runtest/syscalls | 1 + testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/prctl/prctl03.c | 160 ++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 testcases/kernel/syscalls/prctl/prctl03.cruntest/syscalls +1
-0@@ -752,6 +752,7 @@ ppoll01 ppoll01 prctl01 prctl01 prctl02 prctl02 +prctl03 prctl03 pread01 pread01 pread01_64 pread01_64testcases/kernel/syscalls/.gitignore +1
-0@@ -630,6 +630,7 @@ /ppoll/ppoll01 /prctl/prctl01 /prctl/prctl02 +/prctl/prctl03 /pread/pread01 /pread/pread01_64 /pread/pread02testcases/kernel/syscalls/prctl/prctl03.c new file +51
-0@@ -0,0 +1,160 @@ +/* +* Copyright (C) 2014 Linux Test Project +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of version 2 of the GNU General Public +* License as published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* +* Further, this software is distributed without any warranty that it +* is free of the rightful claim of any third person regarding +* infringement or the like. Any license provided herein, whether +* implied or otherwise, applies only to this software file. Patent +* licenses, if any, provided herein do not apply to combinations of +* this program with other software, or any other product whatsoever. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA. +*/ + +/* +* Dummy test program to do basic validation for RH BZ #1056347 +* -> https://bugzilla.redhat.com/show_bug.cgi?id=1056347 +* +* 1. The CAPBSET test drops CAP_DAC_OVERRIDE; the output should show +* it missing from the bounding set. +* 2. The SECUREBITS test sets the NOROOT bit; the output should show +* the "secure-noroot" bit set. +* 3. The KEEPCAPS test sets/checks the KEEPCAPS bit; the output should +* show the value changing from zero to one. +* +*/ + +#include <errno.h> +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <linux/capability.h> +#include <linux/securebits.h> +#include <sys/prctl.h> + +#include "test.h" +#include "usctest.h" + +static void setup (void ); +static void cleanup (void ); +
testcases/kernel/syscalls/prctl/prctl03.c line 61
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl03.c new file +10
-0+static void test_capbset (void ); +static void test_securebits (void ); +static void test_keepcaps (void ); + +char *TCID ="prctl03" ; +int TST_TOTAL =1 ; + +int main (int ac,char **av) +{ +int lc, i;
My apologies for the useless variable "i" here.
Quoted 11 lines
testcases/kernel/syscalls/prctl/prctl03.c new file +11
-0+const char *msg; +pid_t pid; + +if ((msg =parse_opts (ac, av,NULL ,NULL )) !=NULL ) +tst_brkm (TBROK ,NULL ,"OPTION PARSING ERROR - %s" , msg); + +setup (); + +for (lc =0 ;TEST_LOOPING (lc); lc++){ + + tst_count =0 ;
testcases/kernel/syscalls/prctl/prctl03.c line 82
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl03.c new file +10
-0+ +tst_resm (TINFO ,"Testing CAPBSET" ); + pid =fork (); +if (pid ==0 ) { +test_capbset (); + }else if (pid <0 ) +tst_brkm (TBROK |TERRNO , cleanup,"the pid[%d] is invalid" , pid); +if (waitpid (pid,NULL ,0 ) != pid) +tst_brkm (TBROK |TERRNO , cleanup,"waitpid[%d]" , pid); +tst_resm (TPASS ,"Test Passed.\n" );
From my re-test, these codes print TPASS even if the failure occur above, so we should reconsider the process structure again.
Quoted 60 lines
testcases/kernel/syscalls/prctl/prctl03.c new file +60
-0+ +tst_resm (TINFO ,"Testing SECUREBITS" ); + pid =fork (); +if (pid ==0 ) { +test_securebits (); + }else if (pid <0 ) +tst_brkm (TBROK |TERRNO , cleanup,"the pid[%d] is invalid" , pid); +if (waitpid (pid,NULL ,0 ) != pid) +tst_brkm (TBROK |TERRNO , cleanup,"waitpid[%d]" , pid); +tst_resm (TPASS ,"Test Passed.\n" ); + +tst_resm (TINFO ,"Testing KEEPCAPS" ); + pid =fork (); +if (pid ==0 ) { +test_keepcaps (); + }else if (pid <0 ) +tst_brkm (TBROK |TERRNO , cleanup,"the pid[%d] is invalid" , pid); +if (waitpid (pid,NULL ,0 ) != pid) +tst_brkm (TBROK |TERRNO , cleanup,"waitpid[%d]" , pid); +tst_resm (TPASS ,"Test Passed.\n" ); + } + +cleanup (); +tst_exit (); +} + +static void test_capbset (void ) +{ +int rc; + + rc =prctl (PR_CAPBSET_DROP ,CAP_DAC_OVERRIDE ,0 ,0 ,0 ); +if (rc) +tst_brkm (TBROK |TERRNO ,NULL ,"test failue rc = %d" , rc); +if (prctl (PR_CAPBSET_READ ,CAP_DAC_OVERRIDE ,0 ,0 ,0 ) !=0 ) +tst_brkm (TBROK |TERRNO ,NULL ,"unknow test failure" ); +execl ("/usr/sbin/capsh" ,"capsh" ,"--print" ,NULL ); +exit (0 ); +} + +static void test_securebits (void ) +{ +int rc; + + rc =prctl (PR_SET_SECUREBITS ,SECBIT_NOROOT ,0 ,0 ,0 ); +if (rc) +tst_brkm (TBROK |TERRNO ,NULL ,"test failue rc = %d" , rc); + rc =prctl (PR_GET_SECUREBITS ,0 ,0 ,0 ,0 ); +if (!(rc &SECBIT_NOROOT )) +tst_brkm (TBROK |TERRNO ,NULL ,"unknow test failure" ); +execl ("/usr/sbin/capsh" ,"capsh" ,"--print" ,NULL ); +exit (0 ); +} + +static void test_keepcaps (void ) +{ +int rc; + + rc =prctl (PR_GET_KEEPCAPS ,0 ,0 ,0 ,0 ); +tst_resm (TINFO ,"pr_get_keepcaps(orig) = %d" , rc); + rc =prctl (PR_SET_KEEPCAPS ,1 ,0 ,0 ,0 );
testcases/kernel/syscalls/prctl/prctl03.c line 152
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl03.c new file +10
-0+if (rc) +tst_brkm (TBROK |TERRNO ,NULL ,"test failue rc = %d" , rc); + rc =prctl (PR_GET_KEEPCAPS ,0 ,0 ,0 ,0 ); +tst_resm (TINFO ,"pr_get_keepcaps(test) = %d" , rc); +exit (0 ); +} + + +static void setup (void ) +{
Seems the case require_root permission.
Okay, please ignore this testcase directly, i will push new one for LTP.
Quoted 11 lines
testcases/kernel/syscalls/prctl/prctl03.c new file +8
-1+tst_sig (FORK ,DEF_HANDLER , cleanup); +TEST_PAUSE ; +} + +static void cleanup (void ) +{ +TEST_CLEANUP ; +} --1.9.3
Signature · 9 lines
Regards, Li Wang Email: [email protected] ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list