From: Yonghong Song <yhs@fb.com>
To: <bpf@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>,
Dave Marchevsky <davemarchevsky@fb.com>
Subject: [PATCH bpf-next v5 03/17] libbpf: Fix an error in 64bit relocation value computation
Date: Mon, 6 Jun 2022 23:26:10 -0700 [thread overview]
Message-ID: <20220607062610.3717378-1-yhs@fb.com> (raw)
In-Reply-To: <20220607062554.3716237-1-yhs@fb.com>
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>
---
tools/lib/bpf/relo_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/lib/bpf/relo_core.c b/tools/lib/bpf/relo_core.c
index 0dce5644877b..073a54ed7432 100644
--- a/tools/lib/bpf/relo_core.c
+++ b/tools/lib/bpf/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 %llu -> %llu\n",
prog_name, relo_idx,
--
2.30.2
next prev parent reply other threads:[~2022-06-07 6:26 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-07 6:25 [PATCH bpf-next v5 00/17] bpf: Add 64bit enum value support Yonghong Song
2022-06-07 6:26 ` [PATCH bpf-next v5 01/17] bpf: Add btf enum64 support Yonghong Song
2022-06-07 6:26 ` [PATCH bpf-next v5 02/17] libbpf: Permit 64bit relocation value Yonghong Song
2022-06-07 6:26 ` Yonghong Song [this message]
2022-06-07 6:26 ` [PATCH bpf-next v5 04/17] libbpf: Refactor btf__add_enum() for future code sharing Yonghong Song
2022-06-07 6:26 ` [PATCH bpf-next v5 05/17] libbpf: Add enum64 parsing and new enum64 public API Yonghong Song
2022-06-07 6:26 ` [PATCH bpf-next v5 06/17] libbpf: Add enum64 deduplication support Yonghong Song
2022-06-07 6:26 ` [PATCH bpf-next v5 07/17] libbpf: Add enum64 support for btf_dump Yonghong Song
2022-06-07 6:26 ` [PATCH bpf-next v5 08/17] libbpf: Add enum64 sanitization Yonghong Song
2022-06-07 6:26 ` [PATCH bpf-next v5 09/17] libbpf: Add enum64 support for bpf linking Yonghong Song
2022-06-07 6:26 ` [PATCH bpf-next v5 10/17] libbpf: Add enum64 relocation support Yonghong Song
2022-06-07 6:26 ` [PATCH bpf-next v5 11/17] bpftool: Add btf enum64 support Yonghong Song
2022-06-07 6:26 ` [PATCH bpf-next v5 12/17] selftests/bpf: Fix selftests failure Yonghong Song
2022-06-07 6:27 ` [PATCH bpf-next v5 13/17] selftests/bpf: Test new enum kflag and enum64 API functions Yonghong Song
2022-06-07 6:27 ` [PATCH bpf-next v5 14/17] selftests/bpf: Add BTF_KIND_ENUM64 unit tests Yonghong Song
2022-06-07 6:27 ` [PATCH bpf-next v5 15/17] selftests/bpf: Test BTF_KIND_ENUM64 for deduplication Yonghong Song
2022-06-07 6:27 ` [PATCH bpf-next v5 16/17] selftests/bpf: Add a test for enum64 value relocations Yonghong Song
2022-06-07 6:27 ` [PATCH bpf-next v5 17/17] docs/bpf: Update documentation for BTF_KIND_ENUM64 support Yonghong Song
2022-06-07 17:40 ` [PATCH bpf-next v5 00/17] bpf: Add 64bit enum value support patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220607062610.3717378-1-yhs@fb.com \
--to=yhs@fb.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davemarchevsky@fb.com \
--cc=kernel-team@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox