Skip to content

Commit 05a3516

Browse files
bowerscd-corppcmoore
authored andcommitted
ipe: add evaluation loop
Introduce a core evaluation function in IPE that will be triggered by various security hooks (e.g., mmap, bprm_check, kexec). This function systematically assesses actions against the defined IPE policy, by iterating over rules specific to the action being taken. This critical addition enables IPE to enforce its security policies effectively, ensuring that actions intercepted by these hooks are scrutinized for policy compliance before they are allowed to proceed. Signed-off-by: Deven Bowers <[email protected]> Signed-off-by: Fan Wu <[email protected]> Reviewed-by: Serge Hallyn <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 54a88cd commit 05a3516

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed

security/ipe/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#
77

88
obj-$(CONFIG_SECURITY_IPE) += \
9+
eval.o \
910
ipe.o \
1011
policy.o \
1112
policy_parser.o \

security/ipe/eval.c

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (C) 2020-2024 Microsoft Corporation. All rights reserved.
4+
*/
5+
6+
#include <linux/fs.h>
7+
#include <linux/types.h>
8+
#include <linux/slab.h>
9+
#include <linux/file.h>
10+
#include <linux/sched.h>
11+
#include <linux/rcupdate.h>
12+
13+
#include "ipe.h"
14+
#include "eval.h"
15+
#include "policy.h"
16+
17+
struct ipe_policy __rcu *ipe_active_policy;
18+
19+
/**
20+
* evaluate_property() - Analyze @ctx against a rule property.
21+
* @ctx: Supplies a pointer to the context to be evaluated.
22+
* @p: Supplies a pointer to the property to be evaluated.
23+
*
24+
* This is a placeholder. The actual function will be introduced in the
25+
* latter commits.
26+
*
27+
* Return:
28+
* * %true - The current @ctx match the @p
29+
* * %false - The current @ctx doesn't match the @p
30+
*/
31+
static bool evaluate_property(const struct ipe_eval_ctx *const ctx,
32+
struct ipe_prop *p)
33+
{
34+
return false;
35+
}
36+
37+
/**
38+
* ipe_evaluate_event() - Analyze @ctx against the current active policy.
39+
* @ctx: Supplies a pointer to the context to be evaluated.
40+
*
41+
* This is the loop where all policy evaluations happen against the IPE policy.
42+
*
43+
* Return:
44+
* * %0 - Success
45+
* * %-EACCES - @ctx did not pass evaluation
46+
*/
47+
int ipe_evaluate_event(const struct ipe_eval_ctx *const ctx)
48+
{
49+
const struct ipe_op_table *rules = NULL;
50+
const struct ipe_rule *rule = NULL;
51+
struct ipe_policy *pol = NULL;
52+
struct ipe_prop *prop = NULL;
53+
enum ipe_action_type action;
54+
bool match = false;
55+
56+
rcu_read_lock();
57+
58+
pol = rcu_dereference(ipe_active_policy);
59+
if (!pol) {
60+
rcu_read_unlock();
61+
return 0;
62+
}
63+
64+
if (ctx->op == IPE_OP_INVALID) {
65+
if (pol->parsed->global_default_action == IPE_ACTION_DENY) {
66+
rcu_read_unlock();
67+
return -EACCES;
68+
}
69+
if (pol->parsed->global_default_action == IPE_ACTION_INVALID)
70+
WARN(1, "no default rule set for unknown op, ALLOW it");
71+
rcu_read_unlock();
72+
return 0;
73+
}
74+
75+
rules = &pol->parsed->rules[ctx->op];
76+
77+
list_for_each_entry(rule, &rules->rules, next) {
78+
match = true;
79+
80+
list_for_each_entry(prop, &rule->props, next) {
81+
match = evaluate_property(ctx, prop);
82+
if (!match)
83+
break;
84+
}
85+
86+
if (match)
87+
break;
88+
}
89+
90+
if (match)
91+
action = rule->action;
92+
else if (rules->default_action != IPE_ACTION_INVALID)
93+
action = rules->default_action;
94+
else
95+
action = pol->parsed->global_default_action;
96+
97+
rcu_read_unlock();
98+
if (action == IPE_ACTION_DENY)
99+
return -EACCES;
100+
101+
return 0;
102+
}

security/ipe/eval.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Copyright (C) 2020-2024 Microsoft Corporation. All rights reserved.
4+
*/
5+
6+
#ifndef _IPE_EVAL_H
7+
#define _IPE_EVAL_H
8+
9+
#include <linux/file.h>
10+
#include <linux/types.h>
11+
12+
#include "policy.h"
13+
14+
extern struct ipe_policy __rcu *ipe_active_policy;
15+
16+
struct ipe_eval_ctx {
17+
enum ipe_op_type op;
18+
19+
const struct file *file;
20+
};
21+
22+
int ipe_evaluate_event(const struct ipe_eval_ctx *const ctx);
23+
24+
#endif /* _IPE_EVAL_H */

0 commit comments

Comments
 (0)