console-low: Fix off-by-one stack corruption in entInt
PATCH 1/3 console-low: Fix off-by-one stack corruption in entInt
From: Iain Nicol <[email protected]>
entInt stores nineteen registers, not eighteen.
The corruption would sometimes manifest as a memory fault. The STACK_FRAME macro saves the internal PS register to 0($sp). The same location would later be overwritten by entInt storing $at. Later, the wrong PS register value would be restored. This would sometimes cause a switch from kernel to user mode, which can cause memory permission checks to fail.
--- console-low.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
console-low.S +1 -1
@@ -23,7 +23,7 @@ .text .cfi_sections .debug_frame -#define SAVE_ALL_SIZE (18*8) +#define SAVE_ALL_SIZE ((18+1)*8) .globl entInt .type entInt, @function
Signature · 1 line
2.54.0
PATCH 2/3 console-low: Fix $8/$19 stack slot collision in entInt
$8 and $19 were both stored to 9*8($sp), so $19 overwrote $8's saved value and the interrupted context got $19's value back in $8.
Store $8 at 8*8($sp) instead, matching its .cfi_rel_offset.
--- console-low.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
console-low.S +2 -2
@@ -46,7 +46,7 @@ entInt: stq $5, 5*8($sp) stq $6, 6*8($sp) stq $7, 7*8($sp) - stq $8, 9*8($sp) + stq $8, 8*8($sp) stq $19, 9*8($sp) stq $20, 10*8($sp) stq $21, 11*8($sp)
@@ -87,7 +87,7 @@ entInt: ldq $5, 5*8($sp) ldq $6, 6*8($sp) ldq $7, 7*8($sp) - ldq $8, 9*8($sp) + ldq $8, 8*8($sp) ldq $19, 9*8($sp) ldq $20, 10*8($sp) ldq $21, 11*8($sp)
Signature · 1 line
2.54.0
Re: [PATCH qemu-palcode 2/3] console-low: Fix $8/$19 stack slot collision in entInt
Quoted 9 lines · Matt Turner
$8 and $19 were both stored to 9*8($sp), so $19 overwrote $8's saved value and the interrupted context got $19's value back in $8.
Store $8 at 8*8($sp) instead, matching its .cfi_rel_offset.
Signed-off-by Matt Turner <[email protected]>--- console-low.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
PATCH 3/3 console-low: Keep $sp 16-byte aligned in entInt
In reply to Matt TurnerThe PAL stack frame is 48 bytes, and entInt then allocates 19*8 = 152 bytes to save registers, leaving $sp 8 mod 16 at the call to do_entInt. The Alpha calling convention requires 16-byte stack alignment at calls.
Pad the save area to 20*8 bytes.
--- console-low.S | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
console-low.S +2 -1
@@ -23,7 +23,8 @@ .text .cfi_sections .debug_frame -#define SAVE_ALL_SIZE ((18+1)*8) +/* 19 saved registers plus one pad slot to keep $sp 16-byte aligned. */ +#define SAVE_ALL_SIZE (20*8) .globl entInt .type entInt, @function
Signature · 1 line
2.54.0
Hi Richard,
Would you mind applying these three patches?
Thanks,
Matt