Message ID | 1605163724-20306-2-git-send-email-xuyang2018.jy@cn.fujitsu.com |
---|---|
State | Changes Requested |
Headers | show |
Series | [v2,1/2] syscalls/ptrace02: Add another EPERM error test | expand |
Hi! > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. > + * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com > + * > + * This case just check whether we can trace init(1) process and > + * doesn't trigger error. > + */ Why is init(1) special here? Is this a regression test?
Hi! > > +// SPDX-License-Identifier: GPL-2.0-or-later > > +/* > > + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. > > + * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com > > + * > > + * This case just check whether we can trace init(1) process and > > + * doesn't trigger error. > > + */ > > Why is init(1) special here? Is this a regression test? Looking into the manual page this wasn't supported until 2.6.26. I guess that we should mention that here in the test description.
Hi Cyril > Hi! >>> +// SPDX-License-Identifier: GPL-2.0-or-later >>> +/* >>> + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. >>> + * Author: Yang Xu<xuyang2018.jy@cn.fujitsu.com >>> + * >>> + * This case just check whether we can trace init(1) process and >>> + * doesn't trigger error. >>> + */ >> >> Why is init(1) special here? Is this a regression test? > > Looking into the manual page this wasn't supported until 2.6.26. I guess > that we should mention that here in the test description. Yes, it should be added into the test description. Sorry for not explaining why testing init process. Will add it in v2. >
diff --git a/runtest/syscalls b/runtest/syscalls index aeacb8bc8..6b5908662 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1000,6 +1000,7 @@ ptrace07 ptrace07 ptrace08 ptrace08 ptrace09 ptrace09 ptrace10 ptrace10 +ptrace11 ptrace11 pwrite01 pwrite01 pwrite02 pwrite02 diff --git a/testcases/kernel/syscalls/ptrace/.gitignore b/testcases/kernel/syscalls/ptrace/.gitignore index 34be5148f..01cbc6072 100644 --- a/testcases/kernel/syscalls/ptrace/.gitignore +++ b/testcases/kernel/syscalls/ptrace/.gitignore @@ -7,3 +7,4 @@ /ptrace08 /ptrace09 /ptrace10 +/ptrace11 diff --git a/testcases/kernel/syscalls/ptrace/ptrace11.c b/testcases/kernel/syscalls/ptrace/ptrace11.c new file mode 100644 index 000000000..6375964f9 --- /dev/null +++ b/testcases/kernel/syscalls/ptrace/ptrace11.c @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com + * + * This case just check whether we can trace init(1) process and + * doesn't trigger error. + */ + +#include <errno.h> +#include <signal.h> +#include <sys/wait.h> +#include <pwd.h> +#include <config.h> +#include <stdlib.h> +#include "ptrace.h" +#include "tst_test.h" + +static void verify_ptrace(void) +{ + TEST(ptrace(PTRACE_ATTACH, 1, NULL, NULL)); + if (TST_RET == 0) + tst_res(TPASS, "ptrace() traces init process succeeded"); + else + tst_res(TFAIL | TTERRNO, + "ptrace() returns %ld, failed unexpectedly", TST_RET); + + /* + * Running attach/detach more times will trigger a ESRCH error because + * ptrace_check_attach function in kernel will report it if its process + * stats is not __TASK_TRACED. + */ + TST_RETRY_FUNC(ptrace(PTRACE_DETACH, 1, NULL, NULL), TST_RETVAL_EQ0); +} + +static struct tst_test test = { + .test_all = verify_ptrace, + .needs_root = 1, +};
Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com> --- runtest/syscalls | 1 + testcases/kernel/syscalls/ptrace/.gitignore | 1 + testcases/kernel/syscalls/ptrace/ptrace11.c | 39 +++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 testcases/kernel/syscalls/ptrace/ptrace11.c