NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
yara_inspection_core.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #ifndef YARA_INSPECTION_CORE_H_
27 #define YARA_INSPECTION_CORE_H_
28 
29 #include <doca_apsh.h>
30 #include <doca_apsh_attr.h>
31 #include <doca_dev.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * The path is read from the host memory, from the OS process structs.
40  * In the linux case the path is actually the process "comm" which max len is 16.
41  * In Windows the path is actually the process "image_file_name" which unofficial sources are saying is 0x20 bytes long,
42  * the official doc refer only to a full path to file and is saying the default MAX_PATH_LEN value is 260 (can be
43  * changed).
44  */
45 #define MAX_PATH_LEN 260
46 #define MAX_PROCESS_NAME_LEN 1000
47 
48 struct yara_config {
49  DOCA_APSH_PROCESS_PID_TYPE pid; /* Pid of process to validate integrity of */
50  char exec_hash_map_path[MAX_PATH_LEN]; /* Path to APSH's hash.zip file */
51  char system_mem_region_path[MAX_PATH_LEN]; /* Path to APSH's mem_regions.json file */
52  char system_vuid[DOCA_DEVINFO_VUID_SIZE + 1]; /* Virtual Unique Identifier belonging to the PF/VF
53  * that is exposed to the target system.
54  */
55  char dma_dev_name[DOCA_DEVINFO_IBDEV_NAME_SIZE + 1]; /* DMA device name */
56  char system_os_symbol_map_path[MAX_PATH_LEN]; /* Path to APSH's os_symbols.json file */
57  int time_interval; /* Seconds to sleep between two integrity checks */
58 };
59 
61  struct doca_apsh_ctx *ctx; /* Lib Asph context */
62  struct doca_apsh_system *sys; /* Lib Apsh system context */
63  struct doca_dev_rep *system_device; /* DOCA PF/VF representor exposed to the target system */
64  struct doca_dev *dma_device; /* DOCA device capable of DMA into the target system,
65  * matches to the PF of the system device.
66  */
67 };
68 
69 /* Event struct from which report will be serialized */
70 struct yara_event {
71  doca_telemetry_exporter_timestamp_t timestamp; /* Timestamp of when the scan and the validation were completed
72  */
73  int32_t pid; /* Process id number that have been matched by yara rule */
74  char process_name[MAX_PROCESS_NAME_LEN + 1]; /* The name of that process */
75  char yara_rule_name[MAX_PATH_LEN + 1]; /* The end result of the scan, 0 on uncompromising, error otherwise */
76  uint64_t vad; /* This scan number, beginning with 0 */
77 } __attribute__((packed));
78 
79 /*
80  * Register the command line parameters for the application
81  *
82  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
83  */
85 
86 /*
87  * Created and initialized all needed resources for the agent to run
88  *
89  * @conf [in]: Configuration values
90  * @resources [out]: Memory location to store the created resources
91  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
92  *
93  * @NOTE: In case of failure, all already allocated resource are freed
94  */
96 
97 /*
98  * Close and free the given resources, freed resources are set to NULL and unset/freed resources are expected to be NULL
99  *
100  * @resources [in]: Resources to cleanup
101  */
103 
104 /*
105  * Creates a new DOCA Telemetry schema and source, with a register yara event
106  *
107  * @telemetry_schema [out]: Memory location to store the created schema
108  * @telemetry_source [out]: Memory location to store the created source
109  * @index [out]: Memory location to store the yara event type index in the telemetry schema
110  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
111  */
112 doca_error_t telemetry_start(struct doca_telemetry_exporter_schema **telemetry_schema,
113  struct doca_telemetry_exporter_source **telemetry_source,
115 
116 /*
117  * Destroys the DOCA Telemetry schema and source
118  *
119  * @telemetry_schema [in]: Pointer to the DOCA Telemetry schema
120  * @telemetry_source [in]: Pointer to the DOCA Telemetry source
121  */
122 void telemetry_destroy(struct doca_telemetry_exporter_schema *telemetry_schema,
123  struct doca_telemetry_exporter_source *telemetry_source);
124 
125 #ifdef __cplusplus
126 } /* extern "C" */
127 #endif
128 
129 #endif /* YARA_INSPECTION_CORE_H_ */
struct rdma_resources resources
uint32_t DOCA_APSH_PROCESS_PID_TYPE
process pid type
#define DOCA_DEVINFO_IBDEV_NAME_SIZE
Buffer size to hold Infiniband/RoCE device name. Including a null terminator.
Definition: doca_dev.h:309
#define DOCA_DEVINFO_VUID_SIZE
Buffer size to hold VUID. Including a null terminator.
Definition: doca_dev.h:289
enum doca_error doca_error_t
DOCA API return codes.
uint8_t doca_telemetry_exporter_type_index_t
DOCA schema field type index.
uint64_t doca_telemetry_exporter_timestamp_t
DOCA schema type index type.
char dma_dev_name[DOCA_DEVINFO_IBDEV_NAME_SIZE+1]
char system_os_symbol_map_path[MAX_PATH_LEN]
char exec_hash_map_path[MAX_PATH_LEN]
char system_mem_region_path[MAX_PATH_LEN]
DOCA_APSH_PROCESS_PID_TYPE pid
char system_vuid[DOCA_DEVINFO_VUID_SIZE+1]
char yara_rule_name[MAX_PATH_LEN+1]
doca_telemetry_exporter_timestamp_t timestamp
char process_name[MAX_PROCESS_NAME_LEN+1]
struct doca_dev * dma_device
struct doca_dev_rep * system_device
struct doca_apsh_ctx * ctx
struct doca_apsh_system * sys
#define MAX_PROCESS_NAME_LEN
doca_error_t register_yara_params(void)
void yara_inspection_cleanup(struct yara_resources *resources)
doca_error_t yara_inspection_init(struct yara_config *conf, struct yara_resources *resources)
doca_error_t telemetry_start(struct doca_telemetry_exporter_schema **telemetry_schema, struct doca_telemetry_exporter_source **telemetry_source, doca_telemetry_exporter_type_index_t *index)
#define MAX_PATH_LEN
struct yara_event __attribute__((packed))
void telemetry_destroy(struct doca_telemetry_exporter_schema *telemetry_schema, struct doca_telemetry_exporter_source *telemetry_source)