NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
app_shield_agent_core.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2024 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 APP_SHIELD_AGENT_CORE_H_
27 #define APP_SHIELD_AGENT_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 
47 struct apsh_config {
48  DOCA_APSH_PROCESS_PID_TYPE pid; /* Pid of process to validate integrity of */
49  char exec_hash_map_path[MAX_PATH_LEN]; /* Path to APSH's hash.zip file */
50  char system_mem_region_path[MAX_PATH_LEN]; /* Path to APSH's mem_regions.json file */
51  char system_vuid[DOCA_DEVINFO_VUID_SIZE + 1]; /* Virtual Unique Identifier belonging to the PF/VF
52  * that is exposed to the target system.
53  */
54  char dma_dev_name[DOCA_DEVINFO_IBDEV_NAME_SIZE + 1]; /* DMA device name */
55  char system_os_symbol_map_path[MAX_PATH_LEN]; /* Path to APSH's os_symbols.json file */
56  enum doca_apsh_system_os os_type; /* Enum describing the target system OS type */
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 */
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 scanned */
74  int32_t result; /* The end result of the scan, 0 on uncompromising, error otherwise */
75  uint64_t scan_count; /* This scan number, beginning with 0 */
76  char path[MAX_PATH_LEN + 1]; /* The path of that process */
77 } __attribute__((packed));
78 
79 struct event_indexes {
80  doca_telemetry_exporter_type_index_t attest_index; /* Wrapper to the telemetry index corresponding to a user
81  * defined telemetry event.
82  */
83 };
84 
85 /*
86  * Register the command line parameters for the application
87  *
88  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
89  */
91 
92 /*
93  * Created and initialized all needed resources for the agent to run
94  *
95  * @conf [in]: Configuration values
96  * @resources [out]: Memory location to store the created resources
97  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
98  *
99  * @NOTE: In case of failure, all already allocated resource are freed
100  */
102 
103 /*
104  * Close and free the given resources, freed resources are set to NULL and unset/freed resources are expected to be NULL
105  *
106  * @resources [in]: Resources to cleanup
107  */
109 
110 /*
111  * Searches the target system for a process with the provided PID.
112  *
113  * @resources [in]: Resources to use with lib APSH API
114  * @apsh_conf [in]: Configuration values, including the PID to search for
115  * @pslist [out]: Allocated target-system processes list
116  * @process [out]: The process with the PID
117  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
118  *
119  * @NOTE: In case of failure, all allocated resource are freed
120  */
122  struct apsh_config *apsh_conf,
123  struct doca_apsh_process ***pslist,
124  struct doca_apsh_process **process);
125 
126 /*
127  * Creates a new DOCA Telemetry schema and source, with a register attestation event
128  *
129  * @telemetry_schema [out]: Memory location to store the created schema
130  * @telemetry_source [out]: Memory location to store the created source
131  * @indexes [out]: Memory location to store the attestation event type index in the telemetry schema
132  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
133  */
134 doca_error_t telemetry_start(struct doca_telemetry_exporter_schema **telemetry_schema,
135  struct doca_telemetry_exporter_source **telemetry_source,
136  struct event_indexes *indexes);
137 
138 /*
139  * Destroys the DOCA Telemetry schema and source
140  *
141  * @telemetry_schema [in]: Pointer to the DOCA Telemetry schema
142  * @telemetry_source [in]: Pointer to the DOCA Telemetry source
143  */
144 void telemetry_destroy(struct doca_telemetry_exporter_schema *telemetry_schema,
145  struct doca_telemetry_exporter_source *telemetry_source);
146 
147 #ifdef __cplusplus
148 } /* extern "C" */
149 #endif
150 
151 #endif /* APP_SHIELD_AGENT_CORE_H_ */
doca_error_t get_process_by_pid(struct apsh_resources *resources, struct apsh_config *apsh_conf, struct doca_apsh_process ***pslist, struct doca_apsh_process **process)
doca_error_t app_shield_agent_init(struct apsh_config *conf, struct apsh_resources *resources)
doca_error_t telemetry_start(struct doca_telemetry_exporter_schema **telemetry_schema, struct doca_telemetry_exporter_source **telemetry_source, struct event_indexes *indexes)
void app_shield_agent_cleanup(struct apsh_resources *resources)
struct event_indexes __attribute__
ARG varg integer array of triplets (dst offset, src offset, length in bytes)
#define MAX_PATH_LEN
doca_error_t register_apsh_params(void)
void telemetry_destroy(struct doca_telemetry_exporter_schema *telemetry_schema, struct doca_telemetry_exporter_source *telemetry_source)
doca_error_t pslist(const char *dma_device_name, const char *pci_vuid, enum doca_apsh_system_os os_type, const char *mem_region, const char *os_symbols)
struct rdma_resources resources
uint32_t DOCA_APSH_PROCESS_PID_TYPE
process pid type
doca_apsh_system_os
system os types
#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 system_vuid[DOCA_DEVINFO_VUID_SIZE+1]
char exec_hash_map_path[MAX_PATH_LEN]
DOCA_APSH_PROCESS_PID_TYPE pid
char dma_dev_name[DOCA_DEVINFO_IBDEV_NAME_SIZE+1]
char system_mem_region_path[MAX_PATH_LEN]
char system_os_symbol_map_path[MAX_PATH_LEN]
enum doca_apsh_system_os os_type
struct doca_apsh_system * sys
struct doca_dev_rep * system_device
struct doca_apsh_ctx * ctx
struct doca_dev * dma_device
doca_telemetry_exporter_timestamp_t timestamp
char path[MAX_PATH_LEN+1]
doca_telemetry_exporter_type_index_t attest_index