Commit 4023b742 authored by Wentao Guan's avatar Wentao Guan Committed by Catalin Marinas
Browse files

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: d499e962 ("arm64/scs: Fix handling of advance_loc4")
Signed-off-by: default avatarWentao Guan <guanwentao@uniontech.com>
Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
parent 254f4963
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -196,7 +196,7 @@ static int scs_handle_fde_frame(const struct eh_frame *frame,
			loc += *opcode++ * code_alignment_factor;
			loc += (*opcode++ << 8) * code_alignment_factor;
			loc += (*opcode++ << 16) * code_alignment_factor;
			loc += (*opcode++ << 24) * code_alignment_factor;
			loc += ((u64)*opcode++ << 24) * code_alignment_factor;
			size -= 4;
			break;