@@ -40,6 +40,7 @@ impl TcgTpm {
40
40
}
41
41
42
42
fn teardown ( & self ) -> Result < ( ) , SvsmReqError > {
43
+ // SAFETY: FFI call. Return value is checked.
43
44
let result = unsafe { TPM_TearDown ( ) } ;
44
45
match result {
45
46
0 => Ok ( ( ) ) ,
@@ -51,6 +52,7 @@ impl TcgTpm {
51
52
}
52
53
53
54
fn manufacture ( & self , first_time : i32 ) -> Result < i32 , SvsmReqError > {
55
+ // SAFETY: FFI call. Parameter and return values are checked.
54
56
let result = unsafe { TPM_Manufacture ( first_time) } ;
55
57
match result {
56
58
// TPM manufactured successfully
@@ -96,6 +98,9 @@ impl TcgTpmSimulatorInterface for TcgTpm {
96
98
let mut response_ffi_p = response_ffi. as_mut_ptr ( ) ;
97
99
let mut response_ffi_size = TPM_BUFFER_MAX_SIZE as u32 ;
98
100
101
+ // SAFETY: FFI calls. Parameters are checked. Both calls are void,
102
+ // _plat__RunCommand() returns `response_ffi_size` value by reference
103
+ // and it is validated.
99
104
unsafe {
100
105
_plat__LocalitySet ( locality) ;
101
106
_plat__RunCommand (
@@ -128,10 +133,20 @@ impl TcgTpmSimulatorInterface for TcgTpm {
128
133
return Err ( SvsmReqError :: invalid_request ( ) ) ;
129
134
}
130
135
if !only_reset {
131
- unsafe { _plat__Signal_PowerOn ( ) } ;
136
+ // SAFETY: FFI call. No parameter, return value is checked.
137
+ let result = unsafe { _plat__Signal_PowerOn ( ) } ;
138
+ if result != 0 {
139
+ log:: error!( "_plat__Signal_PowerOn failed rc={}" , result) ;
140
+ return Err ( SvsmReqError :: incomplete ( ) ) ;
141
+ }
132
142
}
133
143
// It calls TPM_init() within to indicate that a TPM2_Startup is required.
134
- unsafe { _plat__Signal_Reset ( ) } ;
144
+ // SAFETY: FFI call. No parameter, return value is checked.
145
+ let result = unsafe { _plat__Signal_Reset ( ) } ;
146
+ if result != 0 {
147
+ log:: error!( "_plat__Signal_Reset failed rc={}" , result) ;
148
+ return Err ( SvsmReqError :: incomplete ( ) ) ;
149
+ }
135
150
self . is_powered_on = true ;
136
151
137
152
Ok ( ( ) )
@@ -141,6 +156,7 @@ impl TcgTpmSimulatorInterface for TcgTpm {
141
156
if !self . is_powered_on {
142
157
return Err ( SvsmReqError :: invalid_request ( ) ) ;
143
158
}
159
+ // SAFETY: FFI call. No Parameters or return values.
144
160
unsafe { _plat__SetNvAvail ( ) } ;
145
161
146
162
Ok ( ( ) )
@@ -162,10 +178,16 @@ impl VtpmInterface for TcgTpm {
162
178
// 5. Power it on indicating it requires startup. By default, OVMF will start
163
179
// and selftest it.
164
180
165
- unsafe { _plat__NVEnable ( VirtAddr :: null ( ) . as_mut_ptr :: < c_void > ( ) , 0 ) } ;
181
+ // SAFETY: FFI call. Parameters and return values are checked.
182
+ let mut rc = unsafe { _plat__NVEnable ( VirtAddr :: null ( ) . as_mut_ptr :: < c_void > ( ) , 0 ) } ;
183
+ if rc != 0 {
184
+ log:: error!( "_plat__NVEnable failed rc={}" , rc) ;
185
+ return Err ( SvsmReqError :: incomplete ( ) ) ;
186
+ }
166
187
167
- let mut rc = self . manufacture ( 1 ) ?;
188
+ rc = self . manufacture ( 1 ) ?;
168
189
if rc != 0 {
190
+ // SAFETY: FFI call. Parameter checked, no return value.
169
191
unsafe { _plat__NVDisable ( 1 as * mut c_void , 0 ) } ;
170
192
return Err ( SvsmReqError :: incomplete ( ) ) ;
171
193
}
0 commit comments