All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 2/2] syscalls/ptrace02: Add another EPERM error test
Date: Wed, 11 Nov 2020 16:09:26 +0100	[thread overview]
Message-ID: <20201111150926.GA21539@yuki.lan> (raw)
In-Reply-To: <1604317409-22871-1-git-send-email-xuyang2018.jy@cn.fujitsu.com>

Hi!
> +static void verify_ptrace(void)
> +{
> +	int child_pid;
> +
> +	tst_res(TINFO, "Trace a process that don't have CAP_SYS_PTRACE capability(nobody user) for it");

I wouldn't be printing this verbose info here, anyone who will have to
debug the test failures will look into the source code and at the test
description in the top level comment.

> +	child_pid = SAFE_FORK();
> +	if (!child_pid)
> +		pause();
> +
> +	if (!SAFE_FORK()) {
> +		SAFE_SETUID(uid);
> +		TEST(ptrace(PTRACE_ATTACH, child_pid, NULL, NULL));
> +		if (TST_RET == 0) {
> +			tst_res(TFAIL, "ptrace() succeeded unexpectedly");
> +			TST_CHECKPOINT_WAKE(0);
> +			exit(0);
> +		}
> +		if (TST_ERR == EPERM)
> +			tst_res(TPASS | TTERRNO, "ptrace() failed as expected");
> +		else
> +			tst_res(TFAIL | TTERRNO, "ptrace() expected EPERM, but got");
> +		TST_CHECKPOINT_WAKE(0);
> +		exit(0);
> +	}
> +	TST_CHECKPOINT_WAIT(0);
> +	SAFE_KILL(child_pid, SIGKILL);
> +	SAFE_WAITPID(child_pid, NULL, 0);

We do not need the checkpoints here at all, we just need to waitpid for
the second child before we kill the first one.

> +	tst_reap_children();
> +}
> +
> +static void setup(void)
> +{
> +	struct passwd *pw;
> +
> +	pw = SAFE_GETPWNAM("nobody");
> +	uid = pw->pw_uid;
> +}
> +
> +static struct tst_test test = {
> +	.setup = setup,
> +	.test_all = verify_ptrace,
> +	.forks_child = 1,
> +	.needs_root = 1,
> +	.needs_checkpoints = 1,
> +};
> -- 
> 2.23.0
> 
> 
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2020-11-11 15:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-02 11:43 [LTP] [PATCH 2/2] syscalls/ptrace02: Add another EPERM error test Yang Xu
2020-11-11 15:09 ` Cyril Hrubis [this message]
2020-11-12  6:31   ` Yang Xu
2020-11-12  6:48   ` [LTP] [PATCH v2 1/2] " Yang Xu
2020-11-12  6:48     ` [LTP] [PATCH v2 2/2] syscalls/ptrace11: Add test for tracing init process Yang Xu
2020-11-12 10:32       ` Cyril Hrubis
2020-11-12 12:05         ` Cyril Hrubis
2020-11-13  1:33           ` Yang Xu
2020-11-13  2:07           ` [LTP] [PATCH v3] " Yang Xu
2020-11-13 15:12             ` Cyril Hrubis
2020-11-16 10:51               ` Yang Xu
2020-11-19 15:31                 ` Cyril Hrubis
2020-11-20  2:30                   ` Yang Xu
2020-11-20  3:16                   ` [LTP] [PATCH v4] " Yang Xu
2020-11-20 10:16                     ` Cyril Hrubis
2020-11-12 10:27     ` [LTP] [PATCH v2 1/2] syscalls/ptrace02: Add another EPERM error test Cyril Hrubis
2020-11-12 10:31       ` Cyril Hrubis
2020-11-13  1:29         ` Yang Xu

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=20201111150926.GA21539@yuki.lan \
    --to=chrubis@suse.cz \
    --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.