Skip to content

Commit 8376226

Browse files
committed
landlock: Refactor network access mask management
Replace get_raw_handled_net_accesses() and get_current_net_domain() with a call to landlock_get_applicable_domain(). Cc: Konstantin Meskhidze <[email protected]> Cc: Mikhail Ivanov <[email protected]> Reviewed-by: Günther Noack <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mickaël Salaün <[email protected]>
1 parent 0c0effb commit 8376226

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

security/landlock/net.c

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,9 @@ int landlock_append_net_rule(struct landlock_ruleset *const ruleset,
3939
return err;
4040
}
4141

42-
static access_mask_t
43-
get_raw_handled_net_accesses(const struct landlock_ruleset *const domain)
44-
{
45-
access_mask_t access_dom = 0;
46-
size_t layer_level;
47-
48-
for (layer_level = 0; layer_level < domain->num_layers; layer_level++)
49-
access_dom |= landlock_get_net_access_mask(domain, layer_level);
50-
return access_dom;
51-
}
52-
53-
static const struct landlock_ruleset *get_current_net_domain(void)
54-
{
55-
const struct landlock_ruleset *const dom =
56-
landlock_get_current_domain();
57-
58-
if (!dom || !get_raw_handled_net_accesses(dom))
59-
return NULL;
60-
61-
return dom;
62-
}
42+
static const struct access_masks any_net = {
43+
.net = ~0,
44+
};
6345

6446
static int current_check_access_socket(struct socket *const sock,
6547
struct sockaddr *const address,
@@ -72,7 +54,9 @@ static int current_check_access_socket(struct socket *const sock,
7254
struct landlock_id id = {
7355
.type = LANDLOCK_KEY_NET_PORT,
7456
};
75-
const struct landlock_ruleset *const dom = get_current_net_domain();
57+
const struct landlock_ruleset *const dom =
58+
landlock_get_applicable_domain(landlock_get_current_domain(),
59+
any_net);
7660

7761
if (!dom)
7862
return 0;

0 commit comments

Comments
 (0)