blob: 7639f528835cb9e2ff37ae635ab71be59e75dd0f [file] [log] [blame]
Karl Zhang3de5ab12021-05-31 11:45:48 +08001#######################################
2TF-Fuzz (Trusted-Firmware Fuzzer) guide
3#######################################
4
5************
6Introduction
7************
8
9TF-Fuzz is a TF-M fuzzing tool, at the PSA-call level. At the time of writing
10this at least, presentations available at:
11
12- https://www.trustedfirmware.org/docs/TF-M_Fuzzing_Tool_TFOrg.pdf
13- https://zoom.us/rec/share/1dxZcZit111IadadyFqFU7IoP5X5aaa8gXUdr_UInxmMbyLzEqEmXQdx79-IWQ9p
14
15(These presentation materials may not all be viewable by all parties.)
16
Nik Dewally6fd2f992024-07-01 13:53:23 +010017****************
18Building TF-Fuzz
19****************
20
21.. Note::
22
23 These instructions assume the use of Ubuntu Linux.
24
25
26The following dependencies are required to build TF-Fuzz:
27
28
29.. code-block:: bash
30
31 sudo apt-get update
32 sudo apt-get install build-essential bison flex
33
34
Karl Zhang3de5ab12021-05-31 11:45:48 +080035To build TF-Fuzz, simply type ``make`` in this directory. The executable,
36called ``tfz``, is placed in this directory.
37
Nik Dewally6fd2f992024-07-01 13:53:23 +010038***************
39Running TF-Fuzz
40***************
41
42To run ``tfz``, two environment variables must first be assigned:
Karl Zhang3de5ab12021-05-31 11:45:48 +080043
44.. code-block:: bash
45
46 export TF_FUZZ_LIB_DIR=<path to this TF-M installation>/tools/tf_fuzz/lib
47 export TF_FUZZ_BPLATE=tfm_boilerplate.txt
48
Nik Dewally6fd2f992024-07-01 13:53:23 +010049
50Examples of usage can be found in the ``demo`` directory. For more details, see :doc:`source_structure/demo_dir`.
51
52=======================
53Generating a test suite
54=======================
55
56To generate a testsuite for TF-M from a set of template files, use
57`generate_test_suite.sh`.
58
59.. code-block:: bash
60
61 Usage: generate_test_suite.sh <template_dir> <suites_dir>
62
63 Where:
64 template_dir: The directory containing template files for the
65 fuzzing tool
66 suites_dir: The suites directory in the TF-M working copy.
67 i.e.: $TF-M_ROOT/test/suites
68 Example:
69 cd tf-m-tools/tf_fuzz
70 ./generate_test_suite.sh <path_to>/tf_fuzz/tests/ <path_to>/tf-m-tests/test_reg/test/secure_fw/suites
71
72
73After the test suite is generated, the new test suite needs to be added to the
74TF-M build by providing the following options to the CMake generate command
75(The path needs to be aligned with the test suite dir provided for the shell
76script above):
77
78.. code-block:: bash
79
80 -DTFM_FUZZER_TOOL_TESTS=1
81 -DTFM_FUZZER_TOOL_TESTS_CMAKE_INC_PATH=<path_to>/tf-m-tests/test_reg/test/secure_fw/suites/tf_fuzz
Karl Zhang3de5ab12021-05-31 11:45:48 +080082
83**********************************
84``.../tf_fuzz`` directory contents
85**********************************
86.. code-block:: bash
87
88 assets calls demo parser tests regression
89 backupStuff class_forwards.hpp lib document tf_fuzz.cpp utility
90 boilerplate commands Makefile template tf_fuzz.hpp visualStudio
91
92*************
93Code Overview
94*************
95To help understand the code, below is a C++-class hierarchy used in this code
96base. They are explained further in the documents in their respective
97directories, so the file names where the classes are defined is listed below (this,
98very roughly in order of functional interactions, of chronological usage during
99execution, and of most-to-least importance):
100
101.. code-block:: bash
102
103 template_line ./template/template_line.hpp
104 sst_template_line ./template/template_line.hpp
105 read_sst_template_line ./template/sst_template_line.hpp
106 remove_sst_template_line ./template/sst_template_line.hpp
107 set_sst_template_line ./template/sst_template_line.hpp
108 policy_template_line ./template/template_line.hpp
109 read_policy_template_line ./template/crypto_template_line.hpp
110 set_policy_template_line ./template/crypto_template_line.hpp
111 key_template_line ./template/template_line.hpp
112 read_key_template_line ./template/crypto_template_line.hpp
113 remove_key_template_line ./template/crypto_template_line.hpp
114 set_key_template_line ./template/crypto_template_line.hpp
115 security_template_line ./template/template_line.hpp
116 security_hash_template_line ./template/secure_template_line.hpp
117
118 psa_call ./calls/psa_call.hpp
119 crypto_call ./calls/psa_call.hpp
120 policy_call ./calls/crypto_call.hpp
121 init_policy_call ./calls/crypto_call.hpp
122 reset_policy_call ./calls/crypto_call.hpp
123 add_policy_usage_call ./calls/crypto_call.hpp
124 set_policy_lifetime_call ./calls/crypto_call.hpp
125 set_policy_type_call ./calls/crypto_call.hpp
126 set_policy_algorithm_call ./calls/crypto_call.hpp
127 set_policy_usage_call ./calls/crypto_call.hpp
128 get_policy_lifetime_call ./calls/crypto_call.hpp
129 get_policy_type_call ./calls/crypto_call.hpp
130 get_policy_algorithm_call ./calls/crypto_call.hpp
131 get_policy_usage_call ./calls/crypto_call.hpp
132 get_policy_size_call ./calls/crypto_call.hpp
133 get_policy_call ./calls/crypto_call.hpp
134 key_call ./calls/crypto_call.hpp
135 generate_key_call ./calls/crypto_call.hpp
136 create_key_call ./calls/crypto_call.hpp
137 copy_key_call ./calls/crypto_call.hpp
138 read_key_data_call ./calls/crypto_call.hpp
139 remove_key_call ./calls/crypto_call.hpp
140 sst_call ./calls/psa_call.hpp
141 sst_remove_call ./calls/sst_call.hpp
142 sst_get_call ./calls/sst_call.hpp
143 sst_set_call ./calls/sst_call.hpp
144 security_call ./calls/psa_call.hpp
145 hash_call ./calls/security_call.hpp
146
147 boilerplate ./boilerplate/boilerplate.hpp
148
149 psa_asset ./assets/psa_asset.hpp
150 crypto_asset ./assets/crypto_asset.hpp
151 policy_asset ./assets/crypto_asset.hpp
152 key_asset ./assets/crypto_asset.hpp
153 sst_asset ./assets/sst_asset.hpp
154
155 tf_fuzz_info ./tf_fuzz.hpp
156
157 variables ./utility/variables.hpp
158 crc32 ./utility/compute.hpp
159
160 gibberish ./utility/gibberish.hpp
161
162 expect_info ./utility/data_blocks.hpp
163 set_data_info ./utility/data_blocks.hpp
164 asset_name_id_info ./utility/data_blocks.hpp
165
Nik Dewally6fd2f992024-07-01 13:53:23 +0100166.. seealso::
167 Folder by folder descriptions of the code base can be found in :doc:`source_structure/index`.
168
Karl Zhang3de5ab12021-05-31 11:45:48 +0800169TF-Fuzz now has better-organized management of variables in the generated code.
170In particular, it maintains a list of variables named in the test template, and
171implicit in the code, notably variables assets are ``read`` into. It also now has
172completely separate execution phases to parse the test template, simulate the
173sequence of PSA calls generated, and write out the expected results. That
174simulation is only in enough detail to predict expected results. Since TF-Fuzz
175currectly mostly addresses only SST calls, that simulation is very simple in
176nature -- just tracking data movement.
177
Nik Dewally6fd2f992024-07-01 13:53:23 +0100178.. toctree::
179 :caption: Table of Contents
180 :maxdepth: 1
181
182 Source Structure <source_structure/index>
183
Karl Zhang3de5ab12021-05-31 11:45:48 +0800184--------------
185
Nik Dewally6fd2f992024-07-01 13:53:23 +0100186*Copyright (c) 2020-2024, Arm Limited. All rights reserved.*