fix(shim-sev): do an early exit in `stack_trace()`
... if rbp is zero or not a valid virtual address.
This safe one level of indention.
@@ -176,14 +176,22 @@ unsafe fn stack_trace() {
//Maximum 64 frames
for _frame in 0..64 {
+ if rbp == 0
+ || active_table
+ .translate_addr(VirtAddr::new(rbp as _))
+ .is_none()
+ {
+ break;
+ }
+
if let Some(rip_rbp) = rbp.checked_add(size_of::<usize>() as _) {
if active_table
- .translate_addr(VirtAddr::new(rbp as _))
- .is_some()
- && active_table
.translate_addr(VirtAddr::new(rip_rbp as _))
- .is_some()
+ .is_none()
{
+ break;
+ }
+
let rip = *(rip_rbp as *const usize);
if let Some(rip) = rip.checked_sub(1) {
if rip == 0 {
@@ -205,10 +213,6 @@ unsafe fn stack_trace() {
// RIP zero
break;
}
- } else {
- // RBP NOT MAPPED
- break;
- }
} else {
// RBP OVERFLOW
break;
