Skip to content

bpf, arm64: sign return address for jited code #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

kernel-patches-bot
Copy link

Pull request for series with
subject: bpf, arm64: sign return address for jited code
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572

@kernel-patches-bot
Copy link
Author

Master branch: 6091197
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 63cc8e2
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 63cc8e2
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 08063b4
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 9492450
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: a8fee96
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 46e9244
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: ef07860
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 7ada378
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: ec80906
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: f709869
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: d0f325c
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: d8dc09a
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: d56c9fe
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: f97b8b9
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 9695f4e
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: e52b8f5
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 7f0059b
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 7f0059b
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 2af7e56
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 169e777
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: d717e4c
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 2975dbd
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

Sign return address for jited code when the kernel is built with pointer
authentication enabled.

1. Sign lr with paciasp instruction before lr is pushed to stack. Since
   paciasp acts like landing pads for function entry, no need to insert
   bti instruction before paciasp.

2. Authenticate lr with autiasp instruction after lr is poped from stack.

Signed-off-by: Xu Kuohai <[email protected]>
@kernel-patches-bot
Copy link
Author

Master branch: 38608ee
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
version: 1

Pull request is NOT updated. Failed to apply https://patchwork.kernel.org/project/netdevbpf/list/?series=624572
error message:

Cmd('git') failed due to: exit code(128)
  cmdline: git am -3
  stdout: 'Applying: bpf, arm64: sign return address for jited code
Using index info to reconstruct a base tree...
M	arch/arm64/net/bpf_jit.h
M	arch/arm64/net/bpf_jit_comp.c
Falling back to patching base and 3-way merge...
Auto-merging arch/arm64/net/bpf_jit_comp.c
CONFLICT (content): Merge conflict in arch/arm64/net/bpf_jit_comp.c
Auto-merging arch/arm64/net/bpf_jit.h
Patch failed at 0001 bpf, arm64: sign return address for jited code
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".'
  stderr: 'error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch'

conflict:

diff --cc arch/arm64/net/bpf_jit_comp.c
index 093fa9ea1083,5dcf45e5944e..000000000000
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@@ -194,52 -191,11 +194,57 @@@ static bool is_addsub_imm(u32 imm
  	return !(imm & ~0xfff) || !(imm & ~0xfff000);
  }
  
 +/*
 + * There are 3 types of AArch64 LDR/STR (immediate) instruction:
 + * Post-index, Pre-index, Unsigned offset.
 + *
 + * For BPF ldr/str, the "unsigned offset" type is sufficient.
 + *
 + * "Unsigned offset" type LDR(immediate) format:
 + *
 + *    3                   2                   1                   0
 + *  1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 + * |x x|1 1 1 0 0 1 0 1|         imm12         |    Rn   |    Rt   |
 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 + * scale
 + *
 + * "Unsigned offset" type STR(immediate) format:
 + *    3                   2                   1                   0
 + *  1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 + * |x x|1 1 1 0 0 1 0 0|         imm12         |    Rn   |    Rt   |
 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 + * scale
 + *
 + * The offset is calculated from imm12 and scale in the following way:
 + *
 + * offset = (u64)imm12 << scale
 + */
 +static bool is_lsi_offset(int offset, int scale)
 +{
 +	if (offset < 0)
 +		return false;
 +
 +	if (offset > (0xFFF << scale))
 +		return false;
 +
 +	if (offset & ((1 << scale) - 1))
 +		return false;
 +
 +	return true;
 +}
 +
  /* Tail call offset to jump into */
++<<<<<<< HEAD
 +#if IS_ENABLED(CONFIG_ARM64_BTI_KERNEL)
 +#define PROLOGUE_OFFSET 9
++=======
+ #if IS_ENABLED(CONFIG_ARM64_BTI_KERNEL) || IS_ENABLED(CONFIG_ARM64_PTR_AUTH_KERNEL)
+ #define PROLOGUE_OFFSET 8
++>>>>>>> bpf, arm64: sign return address for jited code
  #else
 -#define PROLOGUE_OFFSET 7
 +#define PROLOGUE_OFFSET 8
  #endif
  
  static int build_prologue(struct jit_ctx *ctx, bool ebpf_from_cbpf)

@kernel-patches-bot
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=624572 irrelevant now for [{'archived': False, 'project': 399, 'delegate': 121173}]

@kernel-patches-bot kernel-patches-bot deleted the series/624572=>bpf-next branch April 3, 2022 18:01
kernel-patches-bot pushed a commit that referenced this pull request Apr 20, 2022
Pu Lehui says:

====================

patch 1 fix a minor issue where usdt_cookie is cast to 32 bits.
patch 2 add support riscv libbpf USDT argument parsing logic,
both RV32 and RV64 tests have been passed as like follow:

# ./test_progs -t usdt
#169 usdt:OK
Summary: 1/4 PASSED, 0 SKIPPED, 0 FAILED
====================

Signed-off-by: Andrii Nakryiko <[email protected]>
kernel-patches-daemon-bpf-rc bot pushed a commit that referenced this pull request Mar 5, 2024
Recent additions in BPF like cpu v4 instructions, test_bpf module
exhibits the following failures:

	test_bpf: #82 ALU_MOVSX | BPF_B jited:1 ret 2 != 1 (0x2 != 0x1)FAIL (1 times)
	test_bpf: #83 ALU_MOVSX | BPF_H jited:1 ret 2 != 1 (0x2 != 0x1)FAIL (1 times)
	test_bpf: #84 ALU64_MOVSX | BPF_B jited:1 ret 2 != 1 (0x2 != 0x1)FAIL (1 times)
	test_bpf: #85 ALU64_MOVSX | BPF_H jited:1 ret 2 != 1 (0x2 != 0x1)FAIL (1 times)
	test_bpf: #86 ALU64_MOVSX | BPF_W jited:1 ret 2 != 1 (0x2 != 0x1)FAIL (1 times)

	test_bpf: #165 ALU_SDIV_X: -6 / 2 = -3 jited:1 ret 2147483645 != -3 (0x7ffffffd != 0xfffffffd)FAIL (1 times)
	test_bpf: #166 ALU_SDIV_K: -6 / 2 = -3 jited:1 ret 2147483645 != -3 (0x7ffffffd != 0xfffffffd)FAIL (1 times)

	test_bpf: #169 ALU_SMOD_X: -7 % 2 = -1 jited:1 ret 1 != -1 (0x1 != 0xffffffff)FAIL (1 times)
	test_bpf: #170 ALU_SMOD_K: -7 % 2 = -1 jited:1 ret 1 != -1 (0x1 != 0xffffffff)FAIL (1 times)

	test_bpf: #172 ALU64_SMOD_K: -7 % 2 = -1 jited:1 ret 1 != -1 (0x1 != 0xffffffff)FAIL (1 times)

	test_bpf: #313 BSWAP 16: 0x0123456789abcdef -> 0xefcd
	eBPF filter opcode 00d7 (@2) unsupported
	jited:0 301 PASS
	test_bpf: #314 BSWAP 32: 0x0123456789abcdef -> 0xefcdab89
	eBPF filter opcode 00d7 (@2) unsupported
	jited:0 555 PASS
	test_bpf: #315 BSWAP 64: 0x0123456789abcdef -> 0x67452301
	eBPF filter opcode 00d7 (@2) unsupported
	jited:0 268 PASS
	test_bpf: #316 BSWAP 64: 0x0123456789abcdef >> 32 -> 0xefcdab89
	eBPF filter opcode 00d7 (@2) unsupported
	jited:0 269 PASS
	test_bpf: #317 BSWAP 16: 0xfedcba9876543210 -> 0x1032
	eBPF filter opcode 00d7 (@2) unsupported
	jited:0 460 PASS
	test_bpf: #318 BSWAP 32: 0xfedcba9876543210 -> 0x10325476
	eBPF filter opcode 00d7 (@2) unsupported
	jited:0 320 PASS
	test_bpf: #319 BSWAP 64: 0xfedcba9876543210 -> 0x98badcfe
	eBPF filter opcode 00d7 (@2) unsupported
	jited:0 222 PASS
	test_bpf: #320 BSWAP 64: 0xfedcba9876543210 >> 32 -> 0x10325476
	eBPF filter opcode 00d7 (@2) unsupported
	jited:0 273 PASS

	test_bpf: #344 BPF_LDX_MEMSX | BPF_B
	eBPF filter opcode 0091 (@5) unsupported
	jited:0 432 PASS
	test_bpf: #345 BPF_LDX_MEMSX | BPF_H
	eBPF filter opcode 0089 (@5) unsupported
	jited:0 381 PASS
	test_bpf: #346 BPF_LDX_MEMSX | BPF_W
	eBPF filter opcode 0081 (@5) unsupported
	jited:0 505 PASS

	test_bpf: #490 JMP32_JA: Unconditional jump: if (true) return 1
	eBPF filter opcode 0006 (@1) unsupported
	jited:0 261 PASS

	test_bpf: Summary: 1040 PASSED, 10 FAILED, [924/1038 JIT'ed]

Fix them by adding missing processing.

Fixes: daabb2b ("bpf/tests: add tests for cpuv4 instructions")
Signed-off-by: Christophe Leroy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant