Signed-off-by: superCharge-xsy <xiesongyang@huawei.com> (cherry picked from commit 767848cdce2c8335a84af7d2a2cabe4ceeb7b2de)
48 lines
1.8 KiB
Diff
48 lines
1.8 KiB
Diff
From 0167a883554df812013ae1778724943ed0c8a069 Mon Sep 17 00:00:00 2001
|
|
From: Yonghong Song <yhs@fb.com>
|
|
Date: Mon, 6 Jun 2022 23:26:10 -0700
|
|
Subject: [PATCH] libbpf: Fix an error in 64bit relocation value computation
|
|
|
|
Currently, the 64bit relocation value in the instruction
|
|
is computed as follows:
|
|
__u64 imm = insn[0].imm + ((__u64)insn[1].imm << 32)
|
|
|
|
Suppose insn[0].imm = -1 (0xffffffff) and insn[1].imm = 1.
|
|
With the above computation, insn[0].imm will first sign-extend
|
|
to 64bit -1 (0xffffffffFFFFFFFF) and then add 0x1FFFFFFFF,
|
|
producing incorrect value 0xFFFFFFFF. The correct value
|
|
should be 0x1FFFFFFFF.
|
|
|
|
Changing insn[0].imm to __u32 first will prevent 64bit sign
|
|
extension and fix the issue. Merging high and low 32bit values
|
|
also changed from '+' to '|' to be consistent with other
|
|
similar occurences in kernel and libbpf.
|
|
|
|
Acked-by: Andrii Nakryiko <andrii@kernel.org>
|
|
Acked-by: Dave Marchevsky <davemarchevsky@fb.com>
|
|
Signed-off-by: Yonghong Song <yhs@fb.com>
|
|
Link: https://lore.kernel.org/r/20220607062610.3717378-1-yhs@fb.com
|
|
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
|
|
Conflict:NA
|
|
Reference:https://github.com/libbpf/libbpf/commit/0167a883554df812013ae1778724943ed0c8a069
|
|
---
|
|
src/relo_core.c | 2 +-
|
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
|
diff --git a/src/relo_core.c b/src/relo_core.c
|
|
index ba4453d..a9216b6 100644
|
|
--- a/src/relo_core.c
|
|
+++ b/src/relo_core.c
|
|
@@ -1027,7 +1027,7 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
|
|
return -EINVAL;
|
|
}
|
|
|
|
- imm = insn[0].imm + ((__u64)insn[1].imm << 32);
|
|
+ imm = (__u32)insn[0].imm | ((__u64)insn[1].imm << 32);
|
|
if (res->validate && imm != orig_val) {
|
|
pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDIMM64) value: got %llu, exp %u -> %u\n",
|
|
prog_name, relo_idx,
|
|
--
|
|
2.33.0
|
|
|