From: Jan Stancek <jstancek@redhat.com>
To: Yuan Sun <sunyuan3@huawei.com>
Cc: ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH] containers: new testcase userns07
Date: Tue, 8 Sep 2015 03:48:05 -0400 (EDT) [thread overview]
Message-ID: <1081951156.6922165.1441698485261.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <1440055253-23430-1-git-send-email-sunyuan3@huawei.com>
----- Original Message -----
> From: "Yuan Sun" <sunyuan3@huawei.com>
> To: jstancek@redhat.com
> Cc: ltp-list@lists.sourceforge.net
> Sent: Thursday, 20 August, 2015 9:20:53 AM
> Subject: [PATCH] containers: new testcase userns07
>
> Signed-off-by: Yuan Sun <sunyuan3@huawei.com>
Hi,
pushed with couple small changes (see comments below).
Regards,
Jan
> ---
> runtest/containers | 1 +
> testcases/kernel/containers/.gitignore | 1 +
> testcases/kernel/containers/userns/userns07.c | 133
> ++++++++++++++++++++++++++
> 3 files changed, 135 insertions(+)
> create mode 100644 testcases/kernel/containers/userns/userns07.c
>
> diff --git a/runtest/containers b/runtest/containers
> index ac37ab2..80de20e 100644
> --- a/runtest/containers
> +++ b/runtest/containers
> @@ -75,3 +75,4 @@ userns03 userns03
> userns04 userns04
> userns05 userns05
> userns06 userns06
> +userns07 userns07
> diff --git a/testcases/kernel/containers/.gitignore
> b/testcases/kernel/containers/.gitignore
> index 3f96f42..7dc2608 100644
> --- a/testcases/kernel/containers/.gitignore
> +++ b/testcases/kernel/containers/.gitignore
> @@ -10,3 +10,4 @@ userns/userns04
> userns/userns05
> userns/userns06_capcheck
> userns/userns06
> +userns/userns07
> diff --git a/testcases/kernel/containers/userns/userns07.c
> b/testcases/kernel/containers/userns/userns07.c
> new file mode 100644
> index 0000000..decabc8
> --- /dev/null
> +++ b/testcases/kernel/containers/userns/userns07.c
> @@ -0,0 +1,133 @@
> +/*
> + * Copyright (c) Huawei Technologies Co., Ltd., 2015
> + * 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.
> + */
> +
> +/*
> + * Verify that:
> + * The kernel imposes a limit of 32 nested levels of user namespaces.
> + */
Changed to ".. of at least 32 nested levels ...".
> +
> +#define _GNU_SOURCE
> +#include <sys/wait.h>
> +#include <assert.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +#include <string.h>
> +#include <errno.h>
> +#include "test.h"
> +#include "userns_helper.h"
> +
> +#define MAXNEST 32
> +
> +char *TCID = "userns07";
> +int TST_TOTAL = 1;
> +
> +static void setup(void)
> +{
> + check_newuser();
> + tst_tmpdir();
> + TST_CHECKPOINT_INIT(NULL);
> +}
> +
> +static void cleanup(void)
> +{
> + tst_rmdir();
> +}
> +
> +static int child_fn1(void *arg)
> +{
> + pid_t cpid1;
> + long level = (long)arg;
> + int status;
> + int parentuid;
> + int parentgid;
> +
> + TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
> +
> + if (level == MAXNEST)
> + return 0;
> + cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
> + (void *)child_fn1, (void *)(level + 1));
> + if (cpid1 < 0) {
> + printf("level %ld:unexpected error: (%d) %s\n",
> + level, errno, strerror(errno));
> + return 1;
> + }
> +
> + parentuid = geteuid();
> + parentgid = getegid();
> +
> + updatemap(cpid1, UID_MAP, 0, parentuid, cleanup);
> + updatemap(cpid1, GID_MAP, 0, parentgid, cleanup);
updatemap in child process shouldn't call cleanup.
> +
> + TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
> +
> + if (waitpid(cpid1, &status, 0) == -1)
> + return 1;
> +
> + if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
> + printf("child exited abnormally\n");
> + return 1;
> + } else if (WIFSIGNALED(status)) {
> + printf("child was killed with signal = %d", WTERMSIG(status));
> + return 1;
> + }
> + return 0;
> +}
> +
> +static void test_max_nest(void)
> +{
> + pid_t cpid1;
> + int parentuid;
> + int parentgid;
> + int fd;
> + char path[BUFSIZ];
> +
> + cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
> + (void *)child_fn1, (void *)0);
> + if (cpid1 < 0)
> + tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
> +
> + parentuid = geteuid();
> + parentgid = getegid();
> +
> + if (access("/proc/self/setgroups", F_OK) == 0) {
> + sprintf(path, "/proc/%d/setgroups", cpid1);
> + fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
> + SAFE_WRITE(cleanup, 1, fd, "deny", 4);
> + SAFE_CLOSE(cleanup, fd);
> + }
> +
> + updatemap(cpid1, UID_MAP, 0, parentuid, cleanup);
> + updatemap(cpid1, GID_MAP, 0, parentgid, cleanup);
> +
> + TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
> + tst_record_childstatus(cleanup, cpid1);
> +}
> +
> +int main(int argc, char *argv[])
> +{
> + int lc;
> +
> + setup();
> + tst_parse_opts(argc, argv, NULL, NULL);
> +
> + for (lc = 0; TEST_LOOPING(lc); lc++) {
> + tst_count = 0;
> + test_max_nest();
> + }
> +
> + cleanup();
> + tst_exit();
> +}
> +
> --
> 1.9.1
>
>
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next prev parent reply other threads:[~2015-09-08 7:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-20 7:20 [LTP] [PATCH] containers: new testcase userns07 Yuan Sun
2015-09-08 7:48 ` Jan Stancek [this message]
2015-09-08 9:34 ` Yuan Sun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1081951156.6922165.1441698485261.JavaMail.zimbra@redhat.com \
--to=jstancek@redhat.com \
--cc=ltp-list@lists.sourceforge.net \
--cc=sunyuan3@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.