• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (c) 2023 Huawei Device Co., Ltd.
4  */
5 
6 #ifndef _XPM_REPORT_H
7 #define _XPM_REPORT_H
8 
9 #include <linux/sched.h>
10 #include <linux/mm.h>
11 #include <linux/xpm_types.h>
12 
13 #define NULL_STR "NULL"
14 
15 #define MAX_FILENAME_LEN 128
16 
17 /* EVENT_INIT */
18 #define DEVICEFS_UNINIT      "devicefs uninitialized"
19 #define DEBUGFS_UNINIT       "debugfs uninitialized"
20 #define DM_DISABLE           "dm-verity disable"
21 
22 /* EVENT_FILE */
23 #define FORMAT_UNDEF         "unkown file format"
24 
25 /* EVENT_MMAP */
26 #define ANON_EXEC            "anon executed"
27 #define GET_SIGN_FAIL        "get signature info failed"
28 #define SIGN_INVALID         "invalid signature"
29 #define DATA_MMAP_CODE       "data mmap code"
30 #define OWNERID_INCONSISTENT "ownerid inconsistent"
31 
32 /* EVENT_INTEGRITY */
33 #define INTEGRITY_RO         "code tampered"
34 #define INTEGRITY_WT         "data executed"
35 
36 enum xpm_code_type {
37 	TYPE_ABC = 0,
38 	TYPE_ELF,
39 	TYPE_ANON,
40 };
41 
42 enum xpm_event_id {
43 	EVENT_INIT      = 1011009110,
44 	EVENT_FILE      = 1011009111,
45 	EVENT_MMAP      = 1011009112,
46 	EVENT_INTEGRITY = 1011009113,
47 };
48 
49 /* set of report info */
50 struct xpm_report_info {
51 	char *event_type;
52 	char *code_type;
53 
54 	pid_t pid;
55 	char comm[TASK_COMM_LEN];
56 	char filename[MAX_FILENAME_LEN + 1];
57 	struct cs_info pcs_info;
58 	struct cs_info fcs_info;
59 
60 	unsigned long vm_prot;
61 	unsigned long vm_pgprot;
62 	unsigned long vm_pgoff;
63 	unsigned long vm_size;
64 
65 	char *page_type;
66 	pgoff_t page_index;
67 
68 	ktime_t timestamp;
69 };
70 
71 /* set of caller parameters */
72 struct xpm_report_param {
73 	char *event_type;
74 	enum xpm_event_id event_id;
75 	enum xpm_code_type code_type;
76 	struct vm_area_struct *vma;
77 	unsigned long vm_prot;
78 	struct page *page;
79 	struct file *file;
80 
81 	int (*set_content)(struct xpm_report_info *info, uint8_t *content,
82 		uint32_t content_len);
83 };
84 
85 #define MAX_CONTENT_LEN 900
86 #define XPM_EVENT_VERSION 0
87 
88 #ifndef CONFIG_SECURITY_XPM_DEBUG
89 #define xpm_report_ratelimited(func, fmt, ...) \
90 	do { \
91 		static DEFINE_RATELIMIT_STATE(_rs, DEFAULT_RATELIMIT_INTERVAL, \
92 			DEFAULT_RATELIMIT_BURST); \
93 		if (__ratelimit(&_rs)) \
94 			func(fmt, ##__VA_ARGS__); \
95 	} while (0)
96 #else
97 #define xpm_report_ratelimited(func, fmt, ...) \
98 	func(fmt, ##__VA_ARGS__);
99 
100 #endif
101 
102 #define JSTR(val) "\""#val"\""
103 #define JVAL_PAIR(val, format) JSTR(val) ": " #format
104 #define JSTR_PAIR(val, format) JSTR(val) ": " JSTR(format)
105 
106 void report_init_event(char *event_type);
107 void report_file_event(char *event_type, struct file *file);
108 void report_mmap_event(char *event_type, enum xpm_code_type code_type,
109 	struct vm_area_struct *vma, unsigned long prot);
110 void report_integrity_event(char *event_type, struct vm_area_struct *vma,
111 	struct page *page);
112 
113 #endif /* _XPM_REPORT_H */
114