YARA Inspection
NVIDIA DOCA YARA Inspection Application Guide
This guide provides YARA inspection implementation on top of NVIDIA® BlueField® DPU.
YARA inspection monitors all processes in the host system for specific YARA rules using the DOCA App Shield library.
This security capability helps identify malware detection patterns in host processes from an independent and trusted DPU. This is an innovative intrusion detection system (IDS) as it is designed to run independently on the DPU's Arm cores without hindering the host.
This DOCA App Shield based application provides the capability to read, analyze, and authenticate the host (bare metal/VM) memory directly from the DPU.
Using the library, this application scans host processes and looks for pre-defined YARA rules. After every scan iteration, the application indicates if any of the rules matched. Once there is a match, the application reports which rules were detected in which process. The reports are both printed to the console and exported to the DOCA Telemetry Service (DTS) using inter-process communication (IPC). This guide describes how to build YARA inspection using the DOCA App Shield library which leverages DPU abilities such as hardware-based DMA, integrity, and more.
The host's involvement is limited to generating the required ZIP and JSON files to pass to the DPU. This is done before the app is triggered, when the host is still in a "safe" state.
Generating the needed files can be done by running DOCA App Shield's doca_apsh_config.py
tool on the host. See NVIDIA DOCA App Shield Programming Guide for more info.
![system-design-diagram.png](https://docscontent.nvidia.com/dims4/default/1444ae8/2147483647/strip/true/crop/707x1030+0+0/resize/707x1030!/quality/90/?url=https%3A%2F%2Fk3-prod-nvidia-docs.s3.us-west-2.amazonaws.com%2Fbrightspot%2Fdita%2F0000018b-62e0-d62f-a3ff-76e9fea00000%2Fdoca%2Farchive%2Fdoca-v2.2.0%2Fyara-inspection%2Fgraphics%2Fsystem-design-diagram.png)
The user creates the ZIP and JSON files using the DOCA tool doca_apsh_config.py
and copies them to the DPU.
The application can report YARA rules detection to the:
- File
- Terminal
- DTS
![application-architecture-diagram.png](https://docscontent.nvidia.com/dims4/default/1595566/2147483647/strip/true/crop/2152x942+0+0/resize/1440x630!/quality/90/?url=https%3A%2F%2Fk3-prod-nvidia-docs.s3.us-west-2.amazonaws.com%2Fbrightspot%2Fdita%2F0000018b-62e0-d62f-a3ff-76e9fea00000%2Fdoca%2Farchive%2Fdoca-v2.2.0%2Fyara-inspection%2Fgraphics%2Fapplication-architecture-diagram.png)
-
The files are generated by running
doca_apsh_config.py
on the host against the process at time zero. -
The following steps recur at regular time intervals:
- The YARA inspection app requests a list of all apps from the DOCA App Shield library.
- The app loops over all processes and checks for YARA rules match using the DOCA App Shield library.
- If YARA rules are found (1 or more), the YARA attestation app reports results with a timestamp and details about the process and rules to:
- Local telemetry files – a folder and files representing the data a real DTS would have received
- DOCA log
- DTS IPC interface (even if no DTS is active)
- The App Shield agent exits on first YARA rule detection.
- Parse application argument.
- Initialize arg parser resources and register DOCA general parameters.
doca_argp_init();
- Register application parameters.
register_apsh_params();
- Parse app flags.
doca_argp_start();
- Initialize arg parser resources and register DOCA general parameters.
- Initialize DOCA App Shield lib context.
- Create lib context.
doca_apsh_create();
- Set DMA device for lib.
open_doca_device_with_ibdev_name(); doca_apsh_dma_dev_set();
- Start the context.
doca_apsh_start(); apsh_system_init();
- Create lib context.
- Initialize DOCA App Shield lib system context handler.
- Get the representor of the remote PCIe function exposed to the system.
open_doca_device_rep_with_vuid();
- Create and start the system context handler.
doca_apsh_system_create(); doca_apsh_sys_os_symbol_map_set(); doca_apsh_sys_mem_region_set(); doca_apsh_sys_dev_set(); doca_apsh_sys_os_type_set(); doca_apsh_system_start();
- Get the representor of the remote PCIe function exposed to the system.
- Telemetry initialization.
telemetry_start();
- Initialize a new telemetry schema.
- Register YARA type event.
- Set up output to file (in addition to default IPC).
- Start the telemetry schema.
- Initialize and start a new DTS source with the
gethostname()
name as source ID.
- Loop until YARA rule is matched.
- Get all processes from the host.
doca_apsh_processes_get();
- Check for YARA rule identification and send a DTS event if there is a match.
doca_apsh_yara_get(); if (yara_matches_size != 0) { /* event fill logic doca_telemetry_source_report(); DOCA_LOG_INFO(); sleep();
- Get all processes from the host.
- Telemetry destroy.
telemetry_destroy();
- YARA inspection clean-up.
doca_apsh_system_destroy(); doca_apsh_destroy(); doca_dev_close(); doca_dev_rep_close();
- Arg parser destroy.
doca_argp_destroy();
- Refer to the following documents:
- NVIDIA DOCA Installation Guide for Linux for details on how to install BlueField-related software.
- NVIDIA DOCA Troubleshooting Guide for any issue you may encounter with the installation, compilation, or execution of DOCA applications.
- NVIDIA DOCA Applications Overview for additional compilation instructions and development tips of DOCA applications.
- The App Shield Agent binary is located under
/opt/mellanox/doca/applications/yara_inspection/bin/doca_yara_inspection
. To build the applications together, run:cd /opt/mellanox/doca/applications/ meson build ninja -C build
- To build only the App Shield Agent application:
- Edit the following flags in
/opt/mellanox/doca/applications/meson_options.txt
:- Set
enable_all_applications
tofalse
- Set
enable_yara_inspection
totrue
- Set
- Run the commands in step 2.
Note:
doca_yara_inspection
is created under./build/yara_inspection/src/
.
Application usage:
Usage: doca_yara_inspection [DOCA Flags] [Program Flags] DOCA Flags: -h, --help Print a help synopsis -v, --version Print program version information -l, --log-level Set the log level for the program <CRITICAL=20, ERROR=30, WARNING=40, INFO=50, DEBUG=60> Program Flags: -m, --memr <path> System memory regions map -f, --vuid VUID of the System device -d, --dma DMA device name -o, --osym <path> System OS symbol map path -t, --time <seconds> Scan time interval in seconds
Note:For additional information on the application, use the
-h
flag:/opt/mellanox/doca/applications/yara_inspection/bin/doca_yara_inspection -h
- Edit the following flags in
- The following steps must be done only once.
- Configure the BlueField's firmware.
- On the BlueField system, configure the PF base address register and NVME emulation. Run:
dpu> mlxconfig -d /dev/mst/mt41686_pciconf0 s PF_BAR2_SIZE=2 PF_BAR2_ENABLE=1 NVME_EMULATION_ENABLE=1
- Perform a cold boot from the host. Run:
host> ipmitool power cycle
Note:These configurations can be checked using the following command:
dpu> mlxconfig -d /dev/mst/mt41686_pciconf0 q | grep -E "NVME|BAR"
- On the BlueField system, configure the PF base address register and NVME emulation. Run:
- Perform IOMMU passthrough. This stage is only necessary in cases where IOMMU is not enabled by default (e.g., when the host is using an AMD CPU).
Note:
- Locate your OS's grub file (most likely
/boot/grub/grub.conf
,/boot/grub2/grub.cfg
, or/etc/default/grub
) and open it for editing. Run:host> vim /etc/default/grub
- Search for the line defining
GRUB_CMDLINE_LINUX_DEFAULT
and add the argumentiommu=pt
. For example:GRUB_CMDLINE_LINUX_DEFAULT="iommu=pt <intel/amd>_iommu=on"
- Run:
- For Ubuntu:
host> sudo update-grub host> ipmitool power cycle
- For CentOS:
host> grub2-mkconfig -o /boot/grub2/grub.cfg host> ipmitool power cycle
- For Ubuntu:
- Locate your OS's grub file (most likely
- For Windows targets only, turn off Hyper-V capability
- Configure the BlueField's firmware.
- Running the application on BlueField:
- Pre-run setup:
- The DOCA App Shield library uses huge pages for DMA buffers. Therefore, the user must allocate 42 huge pages. Run:
dpu> nr_huge=$(cat /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages) nr_huge=$((42+$nr_huge)) sudo echo $nr_huge > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages
- Create the ZIP and JSON files. Run:
Note:
If the kernel and process
.exe
have not changed, there no need to redo this step.target-system> cd /opt/mellanox/doca/tools/ target-system> python3 doca_apsh_config.py <pid-of-process-to-monitor> --os <windows/linux> --path <path to dwarf2json executable or pdbparse-to-json.py> target-system> cp /opt/mellanox/doca/tools/*.* <shared-folder-with-baremetal> dpu> scp <shared-folder-with-baremetal>/* <path-to-app-shield-binary>
If the target system does not have DOCA installed, the script can be copied from the BlueField.
The required
dwaf2json
andpdbparse-to-json.py
are not provided with DOCA. Follow the NVIDIA DOCA App Shield Programming Guide for more information.
- The DOCA App Shield library uses huge pages for DMA buffers. Therefore, the user must allocate 42 huge pages. Run:
- CLI example for running the app:
dpu> /opt/mellanox/doca/applications/yara_inspection/bin/doca_yara_inspection -m mem_regions.json -o symbols.json -f MT2125X03335MLNXS0D0F0VF1 -d mlx5_0 -t 3
- Pre-run setup:
Flag Type | Short Flag | Long Flag/JSON Key | Description |
---|---|---|---|
General flags | l | log-level | Set the log level for the application:
|
v | version | Print program version information | |
h | help | Print a help synopsis | |
Program flags | m | memr | Path to the pre-generated mem_regions.json file transfered from the host |
f | pcif | System PCIe function vendor unique identifier (VUID) of the VF/PF exposed to the target system. Used for DMA operations.
To obtain this argument, run:
Two VUIDs are printed for each DPU connected to the target system. The first is of the DPU on pf0 and the second is of the DPU on port pf1 .
Note:
Running this command on the DPU outputs VUIDs with an additional "EC" string in the middle. You must remove the "EC" to arrive at the correct VUID. The VUID of a VF allocated on PF0/1 is the VUID of the PF with an additional suffix, VF<vf-number>, where vf-number is the VF index +1. For example, for the output in the example above:
VUIDs are persistent even on reset. |
|
d | dma | DMA device name to use | |
o | osym | Path to the pre-generated symbols.json file transferred from the host |
|
t | time | Number of seconds to sleep between scans |
Notice
This document is provided for information purposes only and shall not be regarded as a warranty of a certain functionality, condition, or quality of a product. NVIDIA Corporation nor any of its direct or indirect subsidiaries and affiliates (collectively: “NVIDIA”) make no representations or warranties, expressed or implied, as to the accuracy or completeness of the information contained in this document and assume no responsibility for any errors contained herein. NVIDIA shall have no liability for the consequences or use of such information or for any infringement of patents or other rights of third parties that may result from its use. This document is not a commitment to develop, release, or deliver any Material (defined below), code, or functionality.
NVIDIA reserves the right to make corrections, modifications, enhancements, improvements, and any other changes to this document, at any time without notice.
Customer should obtain the latest relevant information before placing orders and should verify that such information is current and complete.
NVIDIA products are sold subject to the NVIDIA standard terms and conditions of sale supplied at the time of order acknowledgement, unless otherwise agreed in an individual sales agreement signed by authorized representatives of NVIDIA and customer (“Terms of Sale”). NVIDIA hereby expressly objects to applying any customer general terms and conditions with regards to the purchase of the NVIDIA product referenced in this document. No contractual obligations are formed either directly or indirectly by this document.
NVIDIA products are not designed, authorized, or warranted to be suitable for use in medical, military, aircraft, space, or life support equipment, nor in applications where failure or malfunction of the NVIDIA product can reasonably be expected to result in personal injury, death, or property or environmental damage. NVIDIA accepts no liability for inclusion and/or use of NVIDIA products in such equipment or applications and therefore such inclusion and/or use is at customer’s own risk.
NVIDIA makes no representation or warranty that products based on this document will be suitable for any specified use. Testing of all parameters of each product is not necessarily performed by NVIDIA. It is customer’s sole responsibility to evaluate and determine the applicability of any information contained in this document, ensure the product is suitable and fit for the application planned by customer, and perform the necessary testing for the application in order to avoid a default of the application or the product. Weaknesses in customer’s product designs may affect the quality and reliability of the NVIDIA product and may result in additional or different conditions and/or requirements beyond those contained in this document. NVIDIA accepts no liability related to any default, damage, costs, or problem which may be based on or attributable to: (i) the use of the NVIDIA product in any manner that is contrary to this document or (ii) customer product designs.
No license, either expressed or implied, is granted under any NVIDIA patent right, copyright, or other NVIDIA intellectual property right under this document. Information published by NVIDIA regarding third-party products or services does not constitute a license from NVIDIA to use such products or services or a warranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual property rights of the third party, or a license from NVIDIA under the patents or other intellectual property rights of NVIDIA.
Reproduction of information in this document is permissible only if approved in advance by NVIDIA in writing, reproduced without alteration and in full compliance with all applicable export laws and regulations, and accompanied by all associated conditions, limitations, and notices.
THIS DOCUMENT AND ALL NVIDIA DESIGN SPECIFICATIONS, REFERENCE BOARDS, FILES, DRAWINGS, DIAGNOSTICS, LISTS, AND OTHER DOCUMENTS (TOGETHER AND SEPARATELY, “MATERIALS”) ARE BEING PROVIDED “AS IS.” NVIDIA MAKES NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL NVIDIA BE LIABLE FOR ANY DAMAGES, INCLUDING WITHOUT LIMITATION ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF ANY USE OF THIS DOCUMENT, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Notwithstanding any damages that customer might incur for any reason whatsoever, NVIDIA’s aggregate and cumulative liability towards customer for the products described herein shall be limited in accordance with the Terms of Sale for the product.
Trademarks
NVIDIA, the NVIDIA logo, and Mellanox are trademarks and/or registered trademarks of Mellanox Technologies Ltd. and/or NVIDIA Corporation in the U.S. and in other countries. The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world¬wide basis. Other company and product names may be trademarks of the respective companies with which they are associated.
Copyright
© 2023 NVIDIA Corporation & affiliates. All rights reserved.