Return-Path: Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XhbhT-0005Bm-GI for ltp-list@lists.sourceforge.net; Fri, 24 Oct 2014 10:02:27 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1XhbhR-0006P6-Ka for ltp-list@lists.sourceforge.net; Fri, 24 Oct 2014 10:02:27 +0000 From: Li Wang Date: Fri, 24 Oct 2014 18:02:12 +0800 Message-Id: <1414144932-14710-1-git-send-email-liwang@redhat.com> Subject: [LTP] [PATCH] /kenel/syscalls/prctl: add prctl03 List-Id: Linux Test Project General Discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ltp-list-bounces@lists.sourceforge.net To: ltp-list@lists.sourceforge.net Cc: wangli.ahau@gmail.com Signed-off-by: Li Wang --- 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 diff --git a/runtest/syscalls b/runtest/syscalls index 6b8de24..daa72ea 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -752,6 +752,7 @@ ppoll01 ppoll01 prctl01 prctl01 prctl02 prctl02 +prctl03 prctl03 pread01 pread01 pread01_64 pread01_64 diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore index 41fec07..442cacc 100644 --- a/testcases/kernel/syscalls/.gitignore +++ b/testcases/kernel/syscalls/.gitignore @@ -630,6 +630,7 @@ /ppoll/ppoll01 /prctl/prctl01 /prctl/prctl02 +/prctl/prctl03 /pread/pread01 /pread/pread01_64 /pread/pread02 diff --git a/testcases/kernel/syscalls/prctl/prctl03.c b/testcases/kernel/syscalls/prctl/prctl03.c new file mode 100644 index 0000000..c91f1d7 --- /dev/null +++ b/testcases/kernel/syscalls/prctl/prctl03.c @@ -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 +#include +#include +#include +#include +#include +#include + +#include "test.h" +#include "usctest.h" + +static void setup(void); +static void cleanup(void); + +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; + 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; + + 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"); + + 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); + 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) +{ + tst_sig(FORK, DEF_HANDLER, cleanup); + TEST_PAUSE; +} + +static void cleanup(void) +{ + TEST_CLEANUP; +} -- 1.9.3 ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list