File tree 1 file changed +16
-2
lines changed
src/hyperlight_host/src/hypervisor/gdb
1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -164,7 +164,14 @@ pub trait GuestMemoryDebug: GuestVcpuDebug {
164
164
data. len ( ) ,
165
165
( PAGE_SIZE - ( gpa & ( PAGE_SIZE - 1 ) ) ) . try_into ( ) . unwrap ( ) ,
166
166
) ;
167
- let offset = gpa as usize - SandboxMemoryLayout :: BASE_ADDRESS ;
167
+ let offset = ( gpa as usize )
168
+ . checked_sub ( SandboxMemoryLayout :: BASE_ADDRESS )
169
+ . ok_or_else ( || {
170
+ log:: warn!(
171
+ "gva=0x{:#X} causes subtract with underflow: \" gpa - BASE_ADDRESS={:#X}-{:#X}\" " ,
172
+ gva, gpa, SandboxMemoryLayout :: BASE_ADDRESS ) ;
173
+ HyperlightError :: TranslateGuestAddress ( gva)
174
+ } ) ?;
168
175
169
176
dbg_mem_access_fn
170
177
. try_lock ( )
@@ -220,7 +227,14 @@ pub trait GuestMemoryDebug: GuestVcpuDebug {
220
227
data. len ( ) ,
221
228
( PAGE_SIZE - ( gpa & ( PAGE_SIZE - 1 ) ) ) . try_into ( ) . unwrap ( ) ,
222
229
) ;
223
- let offset = gpa as usize - SandboxMemoryLayout :: BASE_ADDRESS ;
230
+ let offset = ( gpa as usize )
231
+ . checked_sub ( SandboxMemoryLayout :: BASE_ADDRESS )
232
+ . ok_or_else ( || {
233
+ log:: warn!(
234
+ "gva=0x{:#X} causes subtract with underflow: \" gpa - BASE_ADDRESS={:#X}-{:#X}\" " ,
235
+ gva, gpa, SandboxMemoryLayout :: BASE_ADDRESS ) ;
236
+ HyperlightError :: TranslateGuestAddress ( gva)
237
+ } ) ?;
224
238
225
239
dbg_mem_access_fn
226
240
. try_lock ( )
You can’t perform that action at this time.
0 commit comments