Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: d499e9627d70 ("arm64/scs: Fix handling of advance_loc4")
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>

authored by

Wentao Guan and committed by
Catalin Marinas
4023b742 254f4963

+2 -2
+2 -2
arch/arm64/kernel/pi/patch-scs.c
··· 196 196 loc += *opcode++ * code_alignment_factor; 197 197 loc += (*opcode++ << 8) * code_alignment_factor; 198 198 loc += (*opcode++ << 16) * code_alignment_factor; 199 - loc += (*opcode++ << 24) * code_alignment_factor; 199 + loc += ((u64)*opcode++ << 24) * code_alignment_factor; 200 200 size -= 4; 201 - break; 201 + break; 202 202 203 203 case DW_CFA_def_cfa: 204 204 case DW_CFA_offset_extended: