All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Palethorpe <rpalethorpe@suse.de>
To: Andrea Cervesato <andrea.cervesato@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v1 01/10] Refactor userns01 test
Date: Tue, 28 Feb 2023 10:52:09 +0000	[thread overview]
Message-ID: <87sfeqt637.fsf@suse.de> (raw)
In-Reply-To: <87wn42t696.fsf@suse.de>

Hello,

Richard Palethorpe <rpalethorpe@suse.de> writes:

> Hello,
>
> Andrea Cervesato via ltp <ltp@lists.linux.it> writes:
>
>> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
>> ---
>>  testcases/kernel/containers/userns/userns01.c | 27 +++++++------------
>>  1 file changed, 10 insertions(+), 17 deletions(-)
>>
>> diff --git a/testcases/kernel/containers/userns/userns01.c b/testcases/kernel/containers/userns/userns01.c
>> index 8ed7a9f41..cbe0da245 100644
>> --- a/testcases/kernel/containers/userns/userns01.c
>> +++ b/testcases/kernel/containers/userns/userns01.c
>> @@ -20,9 +20,9 @@
>>  #define _GNU_SOURCE
>>  
>>  #include <stdio.h>
>> -#include "common.h"
>>  #include "config.h"
>>  #include <sys/capability.h>
>> +#include "lapi/sched.h"
>>  
>>  #define OVERFLOWUIDPATH "/proc/sys/kernel/overflowuid"
>>  #define OVERFLOWGIDPATH "/proc/sys/kernel/overflowgid"
>> @@ -30,10 +30,7 @@
>>  static long overflowuid;
>>  static long overflowgid;
>>  
>> -/*
>> - * child_fn1() - Inside a new user namespace
>> - */
>> -static int child_fn1(LTP_ATTRIBUTE_UNUSED void *arg)
>> +static void child_fn1(void)
>>  {
>>  	int uid, gid;
>>  	cap_t caps;
>> @@ -45,10 +42,8 @@ static int child_fn1(LTP_ATTRIBUTE_UNUSED void *arg)
>>  
>>  	tst_res(TINFO, "USERNS test is running in a new user namespace.");
>>  
>> -	if (uid != overflowuid || gid != overflowgid)
>> -		tst_res(TFAIL, "got unexpected uid=%d gid=%d", uid, gid);
>> -	else
>> -		tst_res(TPASS, "got expected uid and gid");
>> +	TST_EXP_EQ_LI(uid, overflowuid);
>> +	TST_EXP_EQ_LI(gid, overflowgid);
>>  
>>  	caps = cap_get_proc();
>>  
>> @@ -68,31 +63,29 @@ static int child_fn1(LTP_ATTRIBUTE_UNUSED void *arg)
>>  		tst_res(TFAIL, "unexpected effective/permitted caps at %d", i);
>>  	else
>>  		tst_res(TPASS, "expected capabilities");
>> -
>> -	return 0;
>>  }
>>  
>>  static void setup(void)
>>  {
>> -	check_newuser();
>
> User namespaces have been in the kernel a long time, but they can be
> disabled at compile time.
>
> So we need to check for CONFIG_USER_NS in the kernel config.

Ah, ignore that, I see it's already there.

>
>> -
>>  	SAFE_FILE_SCANF(OVERFLOWUIDPATH, "%ld", &overflowuid);
>>  	SAFE_FILE_SCANF(OVERFLOWGIDPATH, "%ld", &overflowgid);
>>  }
>>  
>>  static void run(void)
>>  {
>> -	int pid;
>> +	const struct tst_clone_args args = { CLONE_NEWUSER, SIGCHLD };
>>  
>> -	pid = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD, child_fn1, NULL);
>> -	if (pid < 0)
>> -		tst_brk(TBROK | TTERRNO, "clone failed");
>> +	if (!SAFE_CLONE(&args)) {
>> +		child_fn1();
>> +		return;
>> +	}
>>  }
>>  
>>  static struct tst_test test = {
>>  	.setup = setup,
>>  	.test_all = run,
>>  	.needs_root = 1,
>> +	.forks_child = 1,
>>  	.caps = (struct tst_cap []) {
>>  		TST_CAP(TST_CAP_DROP, CAP_NET_RAW),
>>  		{}
>> -- 
>> 2.35.3


-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2023-02-28 10:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-15 10:16 [LTP] [PATCH v1 00/10] Remove libclone support from userns testing suite Andrea Cervesato via ltp
2023-02-15 10:16 ` [LTP] [PATCH v1 01/10] Refactor userns01 test Andrea Cervesato via ltp
2023-02-28 10:46   ` Richard Palethorpe
2023-02-28 10:52     ` Richard Palethorpe [this message]
2023-02-15 10:16 ` [LTP] [PATCH v1 02/10] Refactor userns02 test Andrea Cervesato via ltp
2023-02-15 10:16 ` [LTP] [PATCH v1 03/10] Refactor userns03 test Andrea Cervesato via ltp
2023-02-15 10:16 ` [LTP] [PATCH v1 04/10] Refactor userns04 test Andrea Cervesato via ltp
2023-02-15 10:16 ` [LTP] [PATCH v1 05/10] Refactor userns05 test Andrea Cervesato via ltp
2023-02-15 10:16 ` [LTP] [PATCH v1 06/10] Refactor userns06 test Andrea Cervesato via ltp
2023-02-15 10:16 ` [LTP] [PATCH v1 07/10] Refactor userns07 test Andrea Cervesato via ltp
2023-02-28 11:23   ` Richard Palethorpe
2023-02-15 10:16 ` [LTP] [PATCH v1 08/10] Remove check_newuser from userns testing suite Andrea Cervesato via ltp
2023-02-15 10:16 ` [LTP] [PATCH v1 09/10] Remove libclone dependency from userns suite Andrea Cervesato via ltp
2023-02-15 10:16 ` [LTP] [PATCH v1 10/10] Delete userns_helper.h " Andrea Cervesato via ltp

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=87sfeqt637.fsf@suse.de \
    --to=rpalethorpe@suse.de \
    --cc=andrea.cervesato@suse.com \
    --cc=ltp@lists.linux.it \
    /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.