Skip to content

Commit 55dc93a

Browse files
micromaomaol0kod
authored andcommitted
selftests/landlock: Use scoped_base_variants.h for ptrace_test
ptrace_test.c currently contains a duplicated version of the scoped_domains fixture variants. This patch removes that and make it use the shared scoped_base_variants.h instead, like in scoped_abstract_unix_test and scoped_signal_test. This required renaming the hierarchy fixture to scoped_domains, but the test is otherwise the same. Cc: Tahera Fahimi <fahimitahera@gmail.com> Signed-off-by: Tingmao Wang <m@maowtm.org> Link: https://lore.kernel.org/r/48148f0134f95f819a25277486a875a6fd88ecf9.1766885035.git.m@maowtm.org Signed-off-by: Mickaël Salaün <mic@digikod.net>
1 parent 7aa593d commit 55dc93a

2 files changed

Lines changed: 12 additions & 151 deletions

File tree

tools/testing/selftests/landlock/ptrace_test.c

Lines changed: 5 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,9 @@ static int get_yama_ptrace_scope(void)
8686
}
8787

8888
/* clang-format off */
89-
FIXTURE(hierarchy) {};
89+
FIXTURE(scoped_domains) {};
9090
/* clang-format on */
9191

92-
FIXTURE_VARIANT(hierarchy)
93-
{
94-
const bool domain_both;
95-
const bool domain_parent;
96-
const bool domain_child;
97-
};
98-
9992
/*
10093
* Test multiple tracing combinations between a parent process P1 and a child
10194
* process P2.
@@ -104,155 +97,18 @@ FIXTURE_VARIANT(hierarchy)
10497
* restriction is enforced in addition to any Landlock check, which means that
10598
* all P2 requests to trace P1 would be denied.
10699
*/
100+
#include "scoped_base_variants.h"
107101

108-
/*
109-
* No domain
110-
*
111-
* P1-. P1 -> P2 : allow
112-
* \ P2 -> P1 : allow
113-
* 'P2
114-
*/
115-
/* clang-format off */
116-
FIXTURE_VARIANT_ADD(hierarchy, allow_without_domain) {
117-
/* clang-format on */
118-
.domain_both = false,
119-
.domain_parent = false,
120-
.domain_child = false,
121-
};
122-
123-
/*
124-
* Child domain
125-
*
126-
* P1--. P1 -> P2 : allow
127-
* \ P2 -> P1 : deny
128-
* .'-----.
129-
* | P2 |
130-
* '------'
131-
*/
132-
/* clang-format off */
133-
FIXTURE_VARIANT_ADD(hierarchy, allow_with_one_domain) {
134-
/* clang-format on */
135-
.domain_both = false,
136-
.domain_parent = false,
137-
.domain_child = true,
138-
};
139-
140-
/*
141-
* Parent domain
142-
* .------.
143-
* | P1 --. P1 -> P2 : deny
144-
* '------' \ P2 -> P1 : allow
145-
* '
146-
* P2
147-
*/
148-
/* clang-format off */
149-
FIXTURE_VARIANT_ADD(hierarchy, deny_with_parent_domain) {
150-
/* clang-format on */
151-
.domain_both = false,
152-
.domain_parent = true,
153-
.domain_child = false,
154-
};
155-
156-
/*
157-
* Parent + child domain (siblings)
158-
* .------.
159-
* | P1 ---. P1 -> P2 : deny
160-
* '------' \ P2 -> P1 : deny
161-
* .---'--.
162-
* | P2 |
163-
* '------'
164-
*/
165-
/* clang-format off */
166-
FIXTURE_VARIANT_ADD(hierarchy, deny_with_sibling_domain) {
167-
/* clang-format on */
168-
.domain_both = false,
169-
.domain_parent = true,
170-
.domain_child = true,
171-
};
172-
173-
/*
174-
* Same domain (inherited)
175-
* .-------------.
176-
* | P1----. | P1 -> P2 : allow
177-
* | \ | P2 -> P1 : allow
178-
* | ' |
179-
* | P2 |
180-
* '-------------'
181-
*/
182-
/* clang-format off */
183-
FIXTURE_VARIANT_ADD(hierarchy, allow_sibling_domain) {
184-
/* clang-format on */
185-
.domain_both = true,
186-
.domain_parent = false,
187-
.domain_child = false,
188-
};
189-
190-
/*
191-
* Inherited + child domain
192-
* .-----------------.
193-
* | P1----. | P1 -> P2 : allow
194-
* | \ | P2 -> P1 : deny
195-
* | .-'----. |
196-
* | | P2 | |
197-
* | '------' |
198-
* '-----------------'
199-
*/
200-
/* clang-format off */
201-
FIXTURE_VARIANT_ADD(hierarchy, allow_with_nested_domain) {
202-
/* clang-format on */
203-
.domain_both = true,
204-
.domain_parent = false,
205-
.domain_child = true,
206-
};
207-
208-
/*
209-
* Inherited + parent domain
210-
* .-----------------.
211-
* |.------. | P1 -> P2 : deny
212-
* || P1 ----. | P2 -> P1 : allow
213-
* |'------' \ |
214-
* | ' |
215-
* | P2 |
216-
* '-----------------'
217-
*/
218-
/* clang-format off */
219-
FIXTURE_VARIANT_ADD(hierarchy, deny_with_nested_and_parent_domain) {
220-
/* clang-format on */
221-
.domain_both = true,
222-
.domain_parent = true,
223-
.domain_child = false,
224-
};
225-
226-
/*
227-
* Inherited + parent and child domain (siblings)
228-
* .-----------------.
229-
* | .------. | P1 -> P2 : deny
230-
* | | P1 . | P2 -> P1 : deny
231-
* | '------'\ |
232-
* | \ |
233-
* | .--'---. |
234-
* | | P2 | |
235-
* | '------' |
236-
* '-----------------'
237-
*/
238-
/* clang-format off */
239-
FIXTURE_VARIANT_ADD(hierarchy, deny_with_forked_domain) {
240-
/* clang-format on */
241-
.domain_both = true,
242-
.domain_parent = true,
243-
.domain_child = true,
244-
};
245-
246-
FIXTURE_SETUP(hierarchy)
102+
FIXTURE_SETUP(scoped_domains)
247103
{
248104
}
249105

250-
FIXTURE_TEARDOWN(hierarchy)
106+
FIXTURE_TEARDOWN(scoped_domains)
251107
{
252108
}
253109

254110
/* Test PTRACE_TRACEME and PTRACE_ATTACH for parent and child. */
255-
TEST_F(hierarchy, trace)
111+
TEST_F(scoped_domains, trace)
256112
{
257113
pid_t child, parent;
258114
int status, err_proc_read;

tools/testing/selftests/landlock/scoped_base_variants.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22
/*
3-
* Landlock scoped_domains variants
3+
* Landlock scoped_domains test variant definition.
44
*
5-
* See the hierarchy variants from ptrace_test.c
5+
* This file defines a fixture variant "scoped_domains" that has all
6+
* permutations of parent/child process being in separate or shared
7+
* Landlock domain, or not being in a Landlock domain at all.
8+
*
9+
* Scoped access tests can include this file to avoid repeating these
10+
* combinations.
611
*
712
* Copyright © 2017-2020 Mickaël Salaün <mic@digikod.net>
813
* Copyright © 2019-2020 ANSSI

0 commit comments

Comments
 (0)