xref: /linux/security/ipe/policy.h (revision 2261306f4a3cea362fc40285e750a801dc0cfbe3)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2020-2024 Microsoft Corporation. All rights reserved.
4  */
5 #ifndef _IPE_POLICY_H
6 #define _IPE_POLICY_H
7 
8 #include <linux/list.h>
9 #include <linux/types.h>
10 #include <linux/fs.h>
11 
12 enum ipe_op_type {
13 	IPE_OP_EXEC = 0,
14 	IPE_OP_FIRMWARE,
15 	IPE_OP_KERNEL_MODULE,
16 	IPE_OP_KEXEC_IMAGE,
17 	IPE_OP_KEXEC_INITRAMFS,
18 	IPE_OP_POLICY,
19 	IPE_OP_X509,
20 	__IPE_OP_MAX,
21 };
22 
23 #define IPE_OP_INVALID __IPE_OP_MAX
24 
25 enum ipe_action_type {
26 	IPE_ACTION_ALLOW = 0,
27 	IPE_ACTION_DENY,
28 	__IPE_ACTION_MAX
29 };
30 
31 #define IPE_ACTION_INVALID __IPE_ACTION_MAX
32 
33 enum ipe_prop_type {
34 	IPE_PROP_BOOT_VERIFIED_FALSE,
35 	IPE_PROP_BOOT_VERIFIED_TRUE,
36 	__IPE_PROP_MAX
37 };
38 
39 #define IPE_PROP_INVALID __IPE_PROP_MAX
40 
41 struct ipe_prop {
42 	struct list_head next;
43 	enum ipe_prop_type type;
44 	void *value;
45 };
46 
47 struct ipe_rule {
48 	enum ipe_op_type op;
49 	enum ipe_action_type action;
50 	struct list_head props;
51 	struct list_head next;
52 };
53 
54 struct ipe_op_table {
55 	struct list_head rules;
56 	enum ipe_action_type default_action;
57 };
58 
59 struct ipe_parsed_policy {
60 	const char *name;
61 	struct {
62 		u16 major;
63 		u16 minor;
64 		u16 rev;
65 	} version;
66 
67 	enum ipe_action_type global_default_action;
68 
69 	struct ipe_op_table rules[__IPE_OP_MAX];
70 };
71 
72 struct ipe_policy {
73 	const char *pkcs7;
74 	size_t pkcs7len;
75 
76 	const char *text;
77 	size_t textlen;
78 
79 	struct ipe_parsed_policy *parsed;
80 
81 	struct dentry *policyfs;
82 };
83 
84 struct ipe_policy *ipe_new_policy(const char *text, size_t textlen,
85 				  const char *pkcs7, size_t pkcs7len);
86 void ipe_free_policy(struct ipe_policy *pol);
87 int ipe_update_policy(struct inode *root, const char *text, size_t textlen,
88 		      const char *pkcs7, size_t pkcs7len);
89 int ipe_set_active_pol(const struct ipe_policy *p);
90 extern struct mutex ipe_policy_lock;
91 
92 #endif /* _IPE_POLICY_H */
93