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 12 enum xpm_event_id { 13 EVENT_INIT = 1011009110, 14 EVENT_FILE = 1011009111, 15 EVENT_MMAP = 1011009112, 16 EVENT_INTEGRITY = 1011009113, 17 }; 18 19 enum xpm_event_type { 20 TYPE_DEVICEFS_UNINIT = 0, 21 TYPE_DEBUGFS_UNINIT, 22 TYPE_DM_DISABLE, 23 TYPE_FORMAT_UNDEF, 24 TYPE_ANON_EXEC, 25 TYPE_SIGN_INVALID, 26 TYPE_DATA_MMAP_CODE, 27 TYPE_INTEGRITY_RO, 28 TYPE_INTEGRITY_WT, 29 }; 30 31 enum { 32 TYPE_ABC, 33 TYPE_ELF, 34 TYPE_ANON, 35 }; 36 37 struct xpm_event_param { 38 char *event_type; 39 char *filename; 40 ktime_t timestamp; 41 pid_t pid; 42 43 struct vm_area_struct *vma; 44 struct page *page; 45 struct file *file; 46 int code; 47 unsigned long prot; 48 }; 49 50 struct xpm_event_info { 51 char *event_type; 52 enum xpm_event_id event_id; 53 int (*set_content)(struct xpm_event_param *param, uint8_t *content, 54 uint32_t content_len); 55 }; 56 57 #define MAX_CONTENT_LEN 900 58 #define XPM_EVENT_VERSION 0 59 60 #ifndef CONFIG_SECURITY_XPM_DEBUG 61 62 #define xpm_report_ratelimited(func, fmt, ...) \ 63 do { \ 64 static DEFINE_RATELIMIT_STATE(_rs, DEFAULT_RATELIMIT_INTERVAL, \ 65 DEFAULT_RATELIMIT_BURST); \ 66 if (__ratelimit(&_rs)) \ 67 func(fmt, ##__VA_ARGS__); \ 68 } while (0) 69 #else 70 #define xpm_report_ratelimited(func, fmt, ...) \ 71 func(fmt, ##__VA_ARGS__); 72 73 #endif 74 75 #define JSTR(val) "\""#val"\"" 76 #define JVAL_PAIR(val, format) JSTR(val) ": " #format 77 #define JSTR_PAIR(val, format) JSTR(val) ": " JSTR(format) 78 79 void report_init_event(enum xpm_event_type type); 80 void report_file_event(enum xpm_event_type type, struct file *file); 81 void report_mmap_event(enum xpm_event_type type, struct vm_area_struct *vma, 82 int code, int prot); 83 void report_integrity_event(enum xpm_event_type type, 84 struct vm_area_struct *vma, struct page *page); 85 86 #endif /* _XPM_REPORT_H */ 87