All of lore.kernel.org
 help / color / mirror / Atom feed
From: s00318865 <sunyuan3@huawei.com>
To: Jan Stancek <jstancek@redhat.com>
Cc: ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH V2] Add userns01 testcase to verify user namespace.
Date: Mon, 25 May 2015 08:27:41 +0800	[thread overview]
Message-ID: <55626C7D.8030202@huawei.com> (raw)
In-Reply-To: <2017045962.3832879.1432304176940.JavaMail.zimbra@redhat.com>

Hi Jan,
     Got. Thanks for your help.You are very professional.
     Best regards.
         Yuan


On 2015/5/22 22:16, Jan Stancek wrote:
>
>
>
> ----- Original Message -----
>> From: "Yuan Sun" <sunyuan3@huawei.com>
>> To: jstancek@redhat.com
>> Cc: ltp-list@lists.sourceforge.net
>> Sent: Thursday, 21 May, 2015 12:31:58 PM
>> Subject: [PATCH V2] Add userns01 testcase to verify user namespace.
>>
>> Signed-off-by: Yuan Sun <sunyuan3@huawei.com>
>> ---
>>   testcases/kernel/containers/userns01/Makefile      | 26 +++++++
>>   testcases/kernel/containers/userns01/userns01.c    | 90
>>   ++++++++++++++++++++++
>>   .../kernel/containers/userns01/userns_helper.h     | 37 +++++++++
>>   3 files changed, 153 insertions(+)
>>   create mode 100644 testcases/kernel/containers/userns01/Makefile
>>   create mode 100644 testcases/kernel/containers/userns01/userns01.c
>>   create mode 100644 testcases/kernel/containers/userns01/userns_helper.h
> I added it to .gitignore and container runtest file, slightly fixed
> commit message, made GPL license look the same in both files and pushed.
>
> Thank you,
> Jan
>
>> diff --git a/testcases/kernel/containers/userns01/Makefile
>> b/testcases/kernel/containers/userns01/Makefile
>> new file mode 100644
>> index 0000000..9f67216
>> --- /dev/null
>> +++ b/testcases/kernel/containers/userns01/Makefile
>> @@ -0,0 +1,26 @@
>> +###############################################################################
>> +#
>> ##
>> +# 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.
>> ##
>> +#
>> ##
>> +# You should have received a copy of the GNU General Public License
>> ##
>> +# along with this program.
>> ##
>> +###############################################################################
>> +
>> +top_srcdir		?= ../../../..
>> +
>> +include $(top_srcdir)/include/mk/testcases.mk
>> +include $(abs_srcdir)/../Makefile.inc
>> +
>> +LDLIBS			:= -lclone -lltp
>> +
>> +include $(top_srcdir)/include/mk/generic_leaf_target.mk
>> diff --git a/testcases/kernel/containers/userns01/userns01.c
>> b/testcases/kernel/containers/userns01/userns01.c
>> new file mode 100644
>> index 0000000..c6022b5
>> --- /dev/null
>> +++ b/testcases/kernel/containers/userns01/userns01.c
>> @@ -0,0 +1,90 @@
>> +/*
>> +* 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. You should have received a copy of the
>> GNU
>> +* General Public License along with this program.
>> +*
>> +*
>> +* Verify that:
>> +*  If a user ID has no mapping inside the namespace, user ID and group
>> +* ID will be the value defined in the file /proc/sys/kernel/overflowuid,
>> 65534.
>> +*/
>> +
>> +#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 "libclone.h"
>> +#include "userns_helper.h"
>> +#define OVERFLOWUIDPATH "/proc/sys/kernel/overflowuid"
>> +
>> +char *TCID = "user_namespace1";
>> +int TST_TOTAL = 1;
>> +
>> +char fullpath[BUFSIZ];
>> +long overflowuid;
>> +
>> +/*
>> + * child_fn1() - Inside a new user namespace
>> + */
>> +static int child_fn1(void *arg)
>> +{
>> +	int exit_val;
>> +	int uid, gid;
>> +
>> +	uid = geteuid();
>> +	gid = getegid();
>> +
>> +	tst_resm(TINFO, "USERNS test is running in a new user namespace.");
>> +	if (uid == overflowuid && gid == overflowuid) {
>> +		printf("Got expected uid and gid\n");
>> +		exit_val = 0;
>> +	} else {
>> +		printf("Got unexpected result of uid=%d gid=%d\n", uid, gid);
>> +		exit_val = 1;
>> +	}
>> +
>> +	return exit_val;
>> +}
>> +
>> +static void setup(void)
>> +{
>> +	check_newuser();
>> +	SAFE_FILE_SCANF(NULL, OVERFLOWUIDPATH, "%ld", &overflowuid);
>> +}
>> +
>> +int main(int argc, char *argv[])
>> +{
>> +	int status;
>> +
>> +	tst_parse_opts(argc, argv, NULL, NULL);
>> +	setup();
>> +
>> +	TEST(do_clone_unshare_test(T_CLONE, CLONE_NEWUSER, child_fn1, NULL));
>> +
>> +	if (TEST_RETURN == -1)
>> +		tst_brkm(TFAIL | TTERRNO, NULL, "clone failed");
>> +	else if ((wait(&status)) == -1)
>> +		tst_brkm(TWARN | TERRNO, NULL, "wait failed");
>> +
>> +	if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
>> +		tst_resm(TFAIL, "child exited abnormally");
>> +	else if (WIFSIGNALED(status)) {
>> +		tst_resm(TFAIL, "child was killed with signal = %d",
>> +			 WTERMSIG(status));
>> +	}
>> +
>> +	tst_resm(TPASS, "the uid and the gid are right inside the container");
>> +	tst_exit();
>> +}
>> +
>> diff --git a/testcases/kernel/containers/userns01/userns_helper.h
>> b/testcases/kernel/containers/userns01/userns_helper.h
>> new file mode 100644
>> index 0000000..3fb7288
>> --- /dev/null
>> +++ b/testcases/kernel/containers/userns01/userns_helper.h
>> @@ -0,0 +1,37 @@
>> +/*
>> +* 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.
>> +*/
>> +
>> +#include "../libclone/libclone.h"
>> +#include "test.h"
>> +#include "safe_macros.h"
>> +
>> +static int dummy_child(void *v)
>> +{
>> +	(void) v;
>> +	return 0;
>> +}
>> +
>> +static int check_newuser(void)
>> +{
>> +	int pid, status;
>> +
>> +	if (tst_kvercmp(3, 8, 0) < 0)
>> +		tst_brkm(TCONF, NULL, "CLONE_NEWUSER not supported");
>> +
>> +	pid = do_clone_unshare_test(T_CLONE, CLONE_NEWUSER, dummy_child, NULL);
>> +	if (pid == -1)
>> +		tst_brkm(TCONF | TERRNO, NULL, "CLONE_NEWUSER not supported");
>> +	SAFE_WAIT(NULL, &status);
>> +
>> +	return 0;
>> +}
>> --
>> 1.9.1
>>
>>
> .
>


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

      reply	other threads:[~2015-05-25  0:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-21 10:31 [LTP] [PATCH V2] Add userns01 testcase to verify user namespace Yuan Sun
2015-05-22 14:16 ` Jan Stancek
2015-05-25  0:27   ` s00318865 [this message]

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=55626C7D.8030202@huawei.com \
    --to=sunyuan3@huawei.com \
    --cc=jstancek@redhat.com \
    --cc=ltp-list@lists.sourceforge.net \
    /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.