public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 5/5] syscalls/setpriority01: Use new user id to avoid messing system environment
Date: Tue, 6 Dec 2016 18:27:23 +0800	[thread overview]
Message-ID: <5846928B.2010805@cn.fujitsu.com> (raw)
In-Reply-To: <20161205144526.GH22344@rei.lan>

Hi!

On 12/05/2016 10:45 PM, Cyril Hrubis wrote:
> Hi!
>>  #include "tst_test.h"
>> +#include "linux_syscall_numbers.h"
>> +
>> +static char username[32];
>> +static uid_t uid;
>> +static struct __user_cap_header_struct header;
>> +static struct __user_cap_data_struct data;
> 
> Are you sure these are the right structure prototypes to use? The double
> underscore usually means "library internal, do not touch".
> 

It's my mistake, thanks for review, I will correct this.

>>  	int which;
>> @@ -35,9 +49,8 @@ static struct tcase {
>>  	{PRIO_USER}
>>  };
>>  
>> -static void verify_setpriority(unsigned int n)
>> +static void setpriority_test(struct tcase *tc)
>>  {
>> -	struct tcase *tc = &tcases[n];
>>  	int new_prio, cur_prio;
>>  	int failflag = 0;
>>  
>> @@ -68,9 +81,60 @@ static void verify_setpriority(unsigned int n)
>>  	}
>>  }
>>  
>> +static void verify_setpriority(unsigned int n)
>> +{
>> +	struct tcase *tc = &tcases[n];
>> +
>> +	if (!SAFE_FORK()) {
>> +		SAFE_PRCTL(PR_SET_KEEPCAPS, 1);
>> +
>> +		SAFE_SETUID(uid);
>> +		SAFE_SETPGID(0, 0);
>> +
>> +		if (tst_syscall(__NR_capset, &header, &data) == -1)
>> +			tst_brk(TBROK | TERRNO, "capset() failed");
>> +
>> +		setpriority_test(tc);
>> +
>> +		exit(0);
>> +	}
>> +
>> +	tst_reap_children();
> 
> Hmm, why do we run the actuall testcase in the child here? That
> complicates the whole test far more than it should have.
> 
> We can instead just run pause() in the child and run the setpriority()
> call in the parent with right pid/group/uid. Or did I miss something?
> 

Sorry, if we do the actual test in the parent, we have to do the process
synchronization, because parent needs child to be ready (prctl, setuid...)
and after every test, child's pause() needs to be waken up by parent, so
I feel it's more complicated by comparison...

Best Regards,
Guangwen Feng

>> +}
>> +
>> +static void setup(void)
>> +{
>> +	char cmd[64];
>> +	struct passwd *ltpuser;
>> +
>> +	sprintf(username, "setpriority01.%d", getpid());
>> +
>> +	sprintf(cmd, "useradd %s", username);
>> +	SAFE_SYSTEM(cmd);
>> +
>> +	ltpuser = SAFE_GETPWNAM(username);
>> +	uid = ltpuser->pw_uid;
>> +
>> +	header.version = _LINUX_CAPABILITY_VERSION;
>> +	header.pid = 0;
>> +	if (tst_syscall(__NR_capget, &header, &data) == -1)
>> +		tst_brk(TBROK | TERRNO, "capget() failed");
>> +}
>> +
>> +static void cleanup(void)
>> +{
>> +	char cmd[64];
>> +
>> +	sprintf(cmd, "userdel -r %s", username);
>> +	SAFE_SYSTEM(cmd);
>> +}
>> +
>>  static struct tst_test test = {
>>  	.tid = "setpriority01",
>>  	.tcnt = ARRAY_SIZE(tcases),
>>  	.needs_root = 1,
>> +	.forks_child = 1,
>> +	.setup = setup,
>> +	.cleanup = cleanup,
>>  	.test = verify_setpriority,
>>  };
>> -- 
>> 1.8.4.2
>>
>>
>>
>>
>> -- 
>> Mailing list info: https://lists.linux.it/listinfo/ltp
> 



  reply	other threads:[~2016-12-06 10:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-30 12:12 [LTP] [PATCH 1/5] Cleanup && Drop redundant space in safe macros Guangwen Feng
2016-11-30 12:12 ` [LTP] [PATCH 2/5] SAFE_MACROS: Add SAFE_SETPRIORITY() Guangwen Feng
2016-11-30 12:12 ` [LTP] [PATCH 3/5] SAFE_MACROS: Add SAFE_SYSTEM() Guangwen Feng
2016-12-05 14:33   ` Cyril Hrubis
2016-12-06 10:02     ` Guangwen Feng
2016-11-30 12:12 ` [LTP] [PATCH 4/5] SAFE_MACROS: Add SAFE_PRCTL() Guangwen Feng
2016-12-05 14:40   ` Cyril Hrubis
2016-12-15 10:17     ` Guangwen Feng
2016-12-15 10:43       ` Cyril Hrubis
2016-12-15 10:49         ` [LTP] [PATCH v2 1/4] Cleanup && Drop redundant space in safe macros Guangwen Feng
2016-12-15 10:49           ` [LTP] [PATCH v2 2/4] SAFE_MACROS: Add SAFE_SETPRIORITY() Guangwen Feng
2016-12-15 10:49           ` [LTP] [PATCH v2 3/4] SAFE_MACROS: Add SAFE_PRCTL() Guangwen Feng
2016-12-15 10:49           ` [LTP] [PATCH v2 4/4] syscalls/setpriority01: Use new user id to avoid messing system environment Guangwen Feng
2017-01-04 12:13             ` Cyril Hrubis
2016-11-30 12:12 ` [LTP] [PATCH 5/5] " Guangwen Feng
2016-12-05 14:45   ` Cyril Hrubis
2016-12-06 10:27     ` Guangwen Feng [this message]
2016-12-06 10:34       ` Cyril Hrubis

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=5846928B.2010805@cn.fujitsu.com \
    --to=fenggw-fnst@cn.fujitsu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox