aarch64_insn_gen_adr() stores the ADRP page offset in an s32 before the range check. For a target about 16TB or more away, the upper bits of the page offset are dropped. The offset can then wrap into range, and the encoder returns an ADRP to the wrong page instead of AARCH64_BREAK_FAULT. Keep the offset in an s64 and shift the ADRP page offset as signed, like label_imm_common() does for the branches. This also covers ADR, so its separate check for a 4GB wrap goes away. The only ADRP user is the module PLTs, which stay within 4GB, so no caller is affected. Offsets within range encode as before. Signed-off-by: Daniel Borkmann Link: https://sashiko.dev/#/patchset/cover.1794165614.git.daniel@iogearbox.net?part=8 --- arch/arm64/lib/insn.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/arm64/lib/insn.c b/arch/arm64/lib/insn.c index 540888474a71..9e4917e68061 100644 --- a/arch/arm64/lib/insn.c +++ b/arch/arm64/lib/insn.c @@ -1444,19 +1444,16 @@ u32 aarch64_insn_gen_adr(unsigned long pc, unsigned long addr, enum aarch64_insn_adr_type type) { u32 insn; - s32 offset; + s64 offset; switch (type) { case AARCH64_INSN_ADR_TYPE_ADR: insn = aarch64_insn_get_adr_value(); - /* The s32 offset would truncate a difference beyond 4GB */ - if ((long)(addr - pc) != (s32)(addr - pc)) - return AARCH64_BREAK_FAULT; - offset = addr - pc; + offset = (s64)(addr - pc); break; case AARCH64_INSN_ADR_TYPE_ADRP: insn = aarch64_insn_get_adrp_value(); - offset = (addr - ALIGN_DOWN(pc, SZ_4K)) >> 12; + offset = (s64)(addr - ALIGN_DOWN(pc, SZ_4K)) >> 12; break; default: pr_err("%s: unknown adr encoding %d\n", __func__, type); -- 2.43.0