Skip to content

Commit 4023b74

Browse files
opsiffctmarinas
authored andcommitted
arm64/scs: Fix potential sign extension issue of advance_loc4
The expression (*opcode++ << 24) and exp * code_alignment_factor may overflow signed int and becomes negative. Fix this by casting each byte to u64 before shifting. Also fix the misaligned break statement while we are here. Example of the result can be seen here: Link: https://godbolt.org/z/zhY8d3595 It maybe not a real problem, but could be a issue in future. Fixes: d499e96 ("arm64/scs: Fix handling of advance_loc4") Signed-off-by: Wentao Guan <guanwentao@uniontech.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 254f496 commit 4023b74

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

arch/arm64/kernel/pi/patch-scs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ static int scs_handle_fde_frame(const struct eh_frame *frame,
196196
loc += *opcode++ * code_alignment_factor;
197197
loc += (*opcode++ << 8) * code_alignment_factor;
198198
loc += (*opcode++ << 16) * code_alignment_factor;
199-
loc += (*opcode++ << 24) * code_alignment_factor;
199+
loc += ((u64)*opcode++ << 24) * code_alignment_factor;
200200
size -= 4;
201-
break;
201+
break;
202202

203203
case DW_CFA_def_cfa:
204204
case DW_CFA_offset_extended:

0 commit comments

Comments
 (0)