Skip to content

Commit ce10fc0

Browse files
iii-iborkmann
authored andcommitted
s390/bpf: Fix clobbering the caller's backchain in the trampoline
One of the first things that s390x kernel functions do is storing the the caller's frame address (backchain) on stack. This makes unwinding possible. The backchain is always stored at frame offset 152, which is inside the 160-byte stack area, that the functions allocate for their callees. The callees must preserve the backchain; the remaining 152 bytes they may use as they please. Currently the trampoline uses all 160 bytes, clobbering the backchain. This causes kernel panics when using __builtin_return_address() in functions called by the trampoline. Fix by reducing the usage of the caller-reserved stack area by 8 bytes in the trampoline. Fixes: 528eb2c ("s390/bpf: Implement arch_prepare_bpf_trampoline()") Reported-by: Song Liu <[email protected]> Signed-off-by: Ilya Leoshkevich <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 57ddeb8 commit ce10fc0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

arch/s390/net/bpf_jit_comp.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,8 +2260,12 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
22602260
tjit->run_ctx_off = alloc_stack(tjit,
22612261
sizeof(struct bpf_tramp_run_ctx));
22622262
tjit->tccnt_off = alloc_stack(tjit, sizeof(u64));
2263-
/* The caller has already reserved STACK_FRAME_OVERHEAD bytes. */
2264-
tjit->stack_size -= STACK_FRAME_OVERHEAD;
2263+
/*
2264+
* In accordance with the s390x ABI, the caller has allocated
2265+
* STACK_FRAME_OVERHEAD bytes for us. 8 of them contain the caller's
2266+
* backchain, and the rest we can use.
2267+
*/
2268+
tjit->stack_size -= STACK_FRAME_OVERHEAD - sizeof(u64);
22652269
tjit->orig_stack_args_off = tjit->stack_size + STACK_FRAME_OVERHEAD;
22662270

22672271
/* aghi %r15,-stack_size */

0 commit comments

Comments
 (0)