]>
Commit | Line | Data |
---|---|---|
ffc1c2fe SL |
1 | From cf3ba17a91a62832ebb995d45bc66ac6ea0ef9c3 Mon Sep 17 00:00:00 2001 |
2 | From: Sasha Levin <sashal@kernel.org> | |
3 | Date: Thu, 21 Mar 2024 09:18:09 +0100 | |
4 | Subject: arm64: bpf: fix 32bit unconditional bswap | |
5 | ||
6 | From: Artem Savkov <asavkov@redhat.com> | |
7 | ||
8 | [ Upstream commit a51cd6bf8e10793103c5870ff9e4db295a843604 ] | |
9 | ||
10 | In case when is64 == 1 in emit(A64_REV32(is64, dst, dst), ctx) the | |
11 | generated insn reverses byte order for both high and low 32-bit words, | |
12 | resuling in an incorrect swap as indicated by the jit test: | |
13 | ||
14 | [ 9757.262607] test_bpf: #312 BSWAP 16: 0x0123456789abcdef -> 0xefcd jited:1 8 PASS | |
15 | [ 9757.264435] test_bpf: #313 BSWAP 32: 0x0123456789abcdef -> 0xefcdab89 jited:1 ret 1460850314 != -271733879 (0x5712ce8a != 0xefcdab89)FAIL (1 times) | |
16 | [ 9757.266260] test_bpf: #314 BSWAP 64: 0x0123456789abcdef -> 0x67452301 jited:1 8 PASS | |
17 | [ 9757.268000] test_bpf: #315 BSWAP 64: 0x0123456789abcdef >> 32 -> 0xefcdab89 jited:1 8 PASS | |
18 | [ 9757.269686] test_bpf: #316 BSWAP 16: 0xfedcba9876543210 -> 0x1032 jited:1 8 PASS | |
19 | [ 9757.271380] test_bpf: #317 BSWAP 32: 0xfedcba9876543210 -> 0x10325476 jited:1 ret -1460850316 != 271733878 (0xa8ed3174 != 0x10325476)FAIL (1 times) | |
20 | [ 9757.273022] test_bpf: #318 BSWAP 64: 0xfedcba9876543210 -> 0x98badcfe jited:1 7 PASS | |
21 | [ 9757.274721] test_bpf: #319 BSWAP 64: 0xfedcba9876543210 >> 32 -> 0x10325476 jited:1 9 PASS | |
22 | ||
23 | Fix this by forcing 32bit variant of rev32. | |
24 | ||
25 | Fixes: 1104247f3f979 ("bpf, arm64: Support unconditional bswap") | |
26 | Signed-off-by: Artem Savkov <asavkov@redhat.com> | |
27 | Tested-by: Puranjay Mohan <puranjay12@gmail.com> | |
28 | Acked-by: Puranjay Mohan <puranjay12@gmail.com> | |
29 | Acked-by: Xu Kuohai <xukuohai@huawei.com> | |
30 | Message-ID: <20240321081809.158803-1-asavkov@redhat.com> | |
31 | Signed-off-by: Alexei Starovoitov <ast@kernel.org> | |
32 | Signed-off-by: Sasha Levin <sashal@kernel.org> | |
33 | --- | |
34 | arch/arm64/net/bpf_jit_comp.c | 2 +- | |
35 | 1 file changed, 1 insertion(+), 1 deletion(-) | |
36 | ||
37 | diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c | |
38 | index 5fe4d8b3fdc89..29196dce9b91d 100644 | |
39 | --- a/arch/arm64/net/bpf_jit_comp.c | |
40 | +++ b/arch/arm64/net/bpf_jit_comp.c | |
41 | @@ -876,7 +876,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, | |
42 | emit(A64_UXTH(is64, dst, dst), ctx); | |
43 | break; | |
44 | case 32: | |
45 | - emit(A64_REV32(is64, dst, dst), ctx); | |
46 | + emit(A64_REV32(0, dst, dst), ctx); | |
47 | /* upper 32 bits already cleared */ | |
48 | break; | |
49 | case 64: | |
50 | -- | |
51 | 2.43.0 | |
52 |