Check alignment of fp in unwind_frame

A misaligned frame pointer is certainly not a valid frame pointer and
with strict alignment enabled (as on CHERI) can cause panics when it is
loaded from later in the code.

This is a recommit of 40e0fa10f5 with
is_aligned() corrected to __is_aligned().

Reviewed By:	jhb
Differential Revision: https://reviews.freebsd.org/D34646
This commit is contained in:
Dapeng Gao 2022-11-16 18:29:28 +00:00 committed by Brooks Davis
parent 07853c6c9d
commit 61b146ba43
2 changed files with 4 additions and 2 deletions

View file

@ -41,7 +41,8 @@ unwind_frame(struct thread *td, struct unwind_state *frame)
fp = frame->fp;
if (!kstack_contains(td, fp, sizeof(uintptr_t) * 2))
if (!__is_aligned(fp, sizeof(fp)) ||
!kstack_contains(td, fp, sizeof(fp) * 2))
return (false);
/* FP to previous frame (X29) */

View file

@ -47,7 +47,8 @@ unwind_frame(struct thread *td, struct unwind_state *frame)
fp = frame->fp;
if (!kstack_contains(td, fp - sizeof(fp) * 2, sizeof(fp) * 2))
if (!__is_aligned(fp, sizeof(fp)) ||
!kstack_contains(td, fp - sizeof(fp) * 2, sizeof(fp) * 2))
return (false);
frame->sp = fp;