summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-08-20 23:36:45 -0400
committerIan Moffett <ian@osmora.org>2025-08-20 23:36:45 -0400
commitffe51b4d28f4de048b7be442f7fa8b3527b3e609 (patch)
treef12be427f4e75166b4ceb8fb3c1b00d6785388cd
parent7ed5ce81ccd6f7a546ea504d998419452b18fc20 (diff)
kernel/amd64: Do not run off callstack in trace
Previously, if RBP becomes NULL (indicating that the END of the callstack has been reached), we still had a chance of dereferencing a NULL pointer when attempting to grab the next value for 'rip'. This commit checks if RBP is NULL before we get the next instruction pointer value. Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/arch/amd64/amd64/machdep.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c
index 76c1a5f..1a07cb5 100644
--- a/sys/arch/amd64/amd64/machdep.c
+++ b/sys/arch/amd64/amd64/machdep.c
@@ -404,7 +404,7 @@ cpu_shootdown_tlb(vaddr_t va)
void
md_backtrace(void)
{
- uintptr_t *rbp;
+ uintptr_t *rbp = NULL;
uintptr_t rip, tmp;
off_t off;
const char *name;
@@ -417,6 +417,11 @@ md_backtrace(void)
break;
}
+ /* End of callstack */
+ if (rbp == NULL) {
+ break;
+ }
+
rip = rbp[1];
rbp = (uintptr_t *)rbp[0];
@@ -434,7 +439,7 @@ md_backtrace(void)
* This is not a valid value, get out
* of this loop!!
*/
- if (rbp == NULL || rip == 0) {
+ if (rip == 0) {
break;
}